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

Re: Repobrowser - Numeric order filename sorting

From: Stefan Küng <tortoisesvn_at_gmail.com>
Date: 2006-04-12 16:31:29 CEST

Gerasimov, Ivan wrote:
> Hello, Hans-Emil!
>
>> I would say that the problem lies in trying to sort the likes of:
>> v1.3.2
>> v101.3.2
>> or
>> v-1.1.0
>> v-1.11.5
>> v-1.11.12
>
> Yes, you are right. Though, in the case you mentioned, the sorting will
> be done properly, since ‘.’ < ‘0’.
>
> The problem will arise, if some separator that is “greater” than a digit
> is used, like:
>
> 10v
> 1v
>
> To handle such cases properly, the routine has to remember the whole
> numbers that are at the places, where the strings are different.
>
> So, here is the improved version of the sample routine, which solves the
> problem, mentioned above.
>
> I also tried to make it locale-aware. Additionally, I eliminated the
> need to convert literal number to integer. This way, huge numbers that
> will not fit into int can be compared. All the comparisons are done with
> the CompareString() function from WinAPI.

First, thanks for the compare function.
I've already used your first function in TSVN to have it sort the items
in the repobrowser (try a nightly build and enable the "sort
numerically" checkbox in the settings 'dialog 2' page).

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.

Now, your new function doesn't work. It first looked like it did, then I
tried the Subversion tags folder. Here the sorting failed. First I had
no clue why, but then I noticed that your new function checks
specifically for '0' - why is that?
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';

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

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()).

Stefan

-- 
        ___
   oo  // \\      "De Chelonian Mobile"
  (_,\/ \_/ \     TortoiseSVN
    \ \_/_\_/>    The coolest Interface to (Sub)Version Control
    /_/   \_\     http://tortoisesvn.tigris.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tortoisesvn.tigris.org
For additional commands, e-mail: dev-help@tortoisesvn.tigris.org
Received on Wed Apr 12 16:31:50 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.