[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

RE: Re: Repobrowser - Numeric order filename sorting

From: Gerasimov, Ivan <Ivan.Gerasimov_at_transas.com>
Date: 2006-04-12 19:31:30 CEST

Hello, Stefan!

> But I had to modify the function. You see, compare functions don't just
> return true/false, they have to return a tri-state value. Most compare
> functions therefore return -1 for 'less than', 0 for 'equal' and 1 for
> 'greater than'. The reason is that sort functions need it that way to
> work faster.

Yes, I see that. I've been testing the sample function with STL's sort, that's why I made it return Boolean.

> Now, your new function doesn't work. It first looked like it did, then I
> tried the Subversion tags folder. Here the sorting failed.

That's surprising! I've tried to test as heavily as I could, before I posted it.

> First I had
> no clue why, but then I noticed that your new function checks
> specifically for '0' - why is that?

It only checks for _leading_ zeros. To make sort order more stable, I decided to place string with same numeric value but with less leading zeros earlier. The number with leading zeros looks bigger after all :-)

> Also, you don't really parse the numbers anymore. In the first function,
> you 'parsed' the numbers into real integers like this:
> y_num = 10 * y_num + *str2_tmp - '0';

Yes, I've mentioned that in my letter:

IG>> Additionally, I eliminated the need to convert literal number to
IG>> integer. This way, huge numbers that will not fit into int can be
IG>> compared. All the comparisons are done with the CompareString()
IG>> function from WinAPI.

> There's nothing like this anymore in your new function.

The idea is that having two strings, which consist only of numbers, we can compare them without converting to ints:
- if their lengths are different and the longer one have no leading zeros, then it is the greater one;
- if lengths are different and the longer one has leading zero, we cut the zero off and repeat previous step;
- if lengths are same (no matter, are there leading zeroes or not), then usual alpha-compare will work;
- if it turns out that strings are (numerically) same, then the one with less leading zeros is counted as been smaller.

> Maybe you can just start over from where I put your first function
> (modified):
> http://tortoisesvn.tigris.org/svn/tortoisesvn/trunk/src/TortoiseProc/Utils.cpp
> (at the end, the static method CUtils::CompareNumerical()).

I've already checked it out and started rebuilding it. As soon as I make it work, I'll post a patch.

Sorry for being a bit slow, have to do lots of other work at the same time :-(

Sincerely yours,
Ivan Gerasimov

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tortoisesvn.tigris.org
For additional commands, e-mail: dev-help@tortoisesvn.tigris.org
Received on Wed Apr 12 19:31:53 2006

This is an archived mail posted to the TortoiseSVN Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.