Re: Sorting Numbers

From: Robert A. Rosenberg (
Date: Mon Mar 13 2000 - 11:19:35 EST

At 04:24 AM 03/13/2000 -0800, Markus Kuhn wrote:


> Light bulb, 100 W
>should be sorted before
> Light bulb, 90 W


>I never understood, why this can't be handled properly within the
>international sorting ordering framework. Culturally correct sorting of
>numbers is most definitely a function that would be highly useful to
>have available. It is also most definitely a function that cannot be
>delegated simply to "higher processing levels", because these higher
>processing level have no way of encoding arbitrary length numbers in a
>way such that the sorting engine will treat them correctly.
>Imagine that I have a higher processing level that replaces written
>numbers such as "one", "two", "twothousand-one", "three" by 1, 2, 2001,
>3. If the resulting decimal numbers are not sorted correctly, the higher
>layer has to perform zero-padding to circumvent this. However, zero
>padding can only be performed efficiently if you know in advance an
>upper limit for the number of digits. If you insert strings that have
>undergone a sorting transform into a B-tree, then you can't just recode
>the entire B-tree, just because a user fancied to enter a number higher
>than the current zero prefixing scheme anticipated.
>So if your preprocessor transformed "one", "two", "twothousand-one",
>"three" into 000001, 000002, 002001, 000003 before inserting the
>sortable strings into a B-tree, then I can play the nasty user by
>entering "one billion" and your sorting scheme breaks down immediately.
>Therefore, numerical sorting is not only necessary to sort numbers
>directly. It is also an essential mechanism for flexible interfacing to
>higher-level sorting preprocessors.

There seems to be a conflict between Example 1 and Example 2. You have 90
sorting AFTER 100 in Example 1 yet say in Example 2 that you should sort 90
before 100 since 90 < 100. It seems to me that the error is in example 1
since you would want to list to be in ascending order of the wattage of the

This archive was generated by hypermail 2.1.2 : Tue Jul 10 2001 - 17:20:59 EDT