Natural Order Sorting

English support forum

Moderators: Hacker, petermad, Stefan2, white

User avatar
pdavit
Power Member
Power Member
Posts: 1529
Joined: 2003-02-05, 21:41 UTC
Location: Kavala -> Greece -> Europe -> Earth -> Solar System -> Milky Way -> Space
Contact:

Post by *pdavit »

So in other words if we cannot have the very best solution we eliminate the solution that is a step better than the current one!

Sorry but I don’t follow this idea. I believe that perfection can only be achieved with slow positive improvements and not in one go. Surely, NS hasn’t solved all problems but why should we withdraw an improvement just because it doesn’t reach perfection?
"My only reason for still using M$ Window$ as an OS is the existence of Total Commander!"
Christian Ghisler Rules!!!
VadiMGP
Power Member
Power Member
Posts: 672
Joined: 2003-04-05, 12:11 UTC
Location: Israel

Post by *VadiMGP »

pdavit wrote:Surely, NS hasn’t solved all problems but why should we withdraw an improvement just because it doesn’t reach perfection?
I think there is no common answer for this question. It is question about efforts against profit. Word "natural" is confusing. For example you are missing hammer. Do you support idea about inventing a new hammer matching for specific nail size only?
I support idea of "alternative sorting". But how make it flexible? May be "sort plugin"? It is possible let to user write comparision function and export from dll. TC in his turn can load such dll for alternative sorting. So i can implement my "natural" sorting you - your etc...
User avatar
pdavit
Power Member
Power Member
Posts: 1529
Joined: 2003-02-05, 21:41 UTC
Location: Kavala -> Greece -> Europe -> Earth -> Solar System -> Milky Way -> Space
Contact:

Post by *pdavit »

So it’s an issue of labeling the sorting method now and not its contents?! ;) :D
Last edited by pdavit on 2003-05-15, 16:17 UTC, edited 1 time in total.
"My only reason for still using M$ Window$ as an OS is the existence of Total Commander!"
Christian Ghisler Rules!!!
jb
Senior Member
Senior Member
Posts: 412
Joined: 2003-02-09, 22:56 UTC
Location: Switzerland

Post by *jb »

VadiMGP wrote:It's means user have to write some rule/sort criteria/comparision function, and thereby write "natural sorting algoritm". So instead of make job for user we found a new job for user! :wink:

Of course, I don't want to start a long discussion, i just want to clarify my opinion - "efforts to implement this feature doesn't match to profit".
VadiMGP wrote:I support idea of "alternative sorting". But how make it flexible? May be "sort plugin"? It is possible let to user write comparision function and export from dll. TC in his turn can load such dll for alternative sorting. So i can implement my "natural" sorting you - your etc...
Seems you have changed your mind! :o
VadiMGP
Power Member
Power Member
Posts: 672
Joined: 2003-04-05, 12:11 UTC
Location: Israel

Post by *VadiMGP »

jb wrote:I tried to tell you that the "natural sorting algorithm" can probably be localized because you complained that the current algorithm is not appropriate for your region.
jb wrote:Seems you have changed your mind!
No, i didn't. I repeat: it's doesn't make sense to spend time for some specific algorithm (somebody will call it "natural", somebody will call it "pervertion" :)) with unpdedictable requirements for "localization". Much more valuable is ability to everyone to add his sorting algorithm. Do you see difference?
Beside of this you scared me with unemployment. :wink:
chasbas
Junior Member
Junior Member
Posts: 52
Joined: 2003-02-06, 16:01 UTC
Location: New Jersey

Post by *chasbas »

Making a generalized alternative sort, whether it is called natural or perverted, will require dealing with the few cases I posed as well as a lot more. The utility of such a complex scheme is doubtful, and is far more likely to lead to problems than solutions. For example, a file unexpectedly gets sorted into the middle of a group and gets copied somewhere it shouldn't. Or even worse, a file *doesn't* get sorted into the middle of a group and *doesn't* get copied where it should be. These downsides are daunting, especially when all you really have to do is select the 9 files that don't have leading zeroes and rename them with Ctrl+T!

Making a custom sort algorithm is an intriguing idea for allowing sorts on other criteria (e.g., file attributes, or the name of the first C function call contained in the file). It would also allow for unique situations where you might want to sort ignoring all non-alphanumeric characters, or sort by a lookup table using the file name as a key. I would support this custom DLL sort concept, but I sure wouldn't put it high on my list of priorities.
User avatar
pdavit
Power Member
Power Member
Posts: 1529
Joined: 2003-02-05, 21:41 UTC
Location: Kavala -> Greece -> Europe -> Earth -> Solar System -> Milky Way -> Space
Contact:

Post by *pdavit »

Since it’s becoming a “common sense” that this is a complicated issue to implement for a “minor” adjustment maybe someone is willing to implement it in the form of a plug-in. In this way he/she can even include different types of sorting even for some special languages. What worries me though in the plug-in approach is the level of integration with TC and how well the shorting plug-in will interact with file managing actions.
"My only reason for still using M$ Window$ as an OS is the existence of Total Commander!"
Christian Ghisler Rules!!!
jb
Senior Member
Senior Member
Posts: 412
Joined: 2003-02-09, 22:56 UTC
Location: Switzerland

Post by *jb »

VadiMGP wrote:I repeat: it's doesn't make sense to spend time for some specific algorithm (somebody will call it "natural", somebody will call it "pervertion" :)) with unpdedictable requirements for "localization". Much more valuable is ability to everyone to add his sorting algorithm. Do you see difference?
No, not really.
Firstly I used the word "configurable" in my first post to you concerning this topic. So if the algorithm is configurable it is also localizable. You can consider a "locale" as a default configuration for a specific region.
Secondly the requirements are not that unpredictable as you think. For instance it is quite predictable what alphabet is used for numbers in a specific region. At least in the western world the default alphabet would be '0', '1', ..., '9'. Of course it gets more difficult when the numeric alphabet ("digits") and the non-numeric alphabet ("letters" etc.) overlap. Then also the context must be configurable.

BTW: I forgot to ask you something right at the start. How does a hebrew version of Windows handle strings? Are the strings stored in reverse order or just displayed in reverse order? In other words: Is the character at position 0 displayed as right-most character?
VadiMGP
Power Member
Power Member
Posts: 672
Joined: 2003-04-05, 12:11 UTC
Location: Israel

Post by *VadiMGP »

jb wrote:How does a hebrew version of Windows handle strings?
Very good question! And the answer is very simple: Windows doesn't know how Windows itself handle hebrew text!!!:evil: Belive me, i'm not kidding you! It is nightmare! The problem is the string content depend on "text layout". Text layout - is rule for cursor moving on screen during user input. So resulting string depend on "text layout" choosen in the current application. So nice! You can type exactly the same string in Notepad or Access but in the file you'll get the different strings. Of course, string itself doesn't contain any information about "text layout".
Using text information between different OS even more difficult. Sometime all text reversed, sometime only letters in words reversed, sometime letters in words reversed and words swapped.

Of course, life not so ugly. In many cases all application work with the same layout, but anyway, i know cases when companies reject to develop projects if customer requsted full (normal!!!) hebrew support.
Well, i can continue for hours... Let finish it.

PS. Last sample. I have a lot of e-mails in my Outlook inbox (it is Microsoft product, right? :wink: ) unreadable under no circumstances.
jb
Senior Member
Senior Member
Posts: 412
Joined: 2003-02-09, 22:56 UTC
Location: Switzerland

Post by *jb »

VadiMGP wrote:I have a lot of e-mails in my Outlook inbox (it is Microsoft product, right? :wink: ) unreadable under no circumstances.
What about an Open Source e-mail client such as the one that comes with the Mozilla browser? Do you think that Open Source cares more about non-western presentations in general?
VadiMGP
Power Member
Power Member
Posts: 672
Joined: 2003-04-05, 12:11 UTC
Location: Israel

Post by *VadiMGP »

jb wrote:Do you think that Open Source cares more about non-western presentations in general?
Based on my experience with Netscape(Mozilla), as a general rule - yes. Much more mails can be correctly shown in Netscape then Outlook. Although Mozilla have more problems with encoding from MS Exchange and Lotus.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 50486
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

Concerning the original question: If anyone can give me some pseudo-code or sample code for this sorting method, I will gladly add it as an option. Currently TC uses lexical sorting (by letters, not numbers), so simply use file01.txt instead of file1.txt to sort numbers correctly!
Author of Total Commander
https://www.ghisler.com
jb
Senior Member
Senior Member
Posts: 412
Joined: 2003-02-09, 22:56 UTC
Location: Switzerland

Post by *jb »

ghisler(Author) wrote:Concerning the original question: If anyone can give me some pseudo-code or sample code for this sorting method, I will gladly add it as an option. Currently TC uses lexical sorting (by letters, not numbers), so simply use file01.txt instead of file1.txt to sort numbers correctly!

Code: Select all

/*
   natstrsort.c by jb, 2003-05-17

   This program reads the command-line parameters and displays them sorted
   "normally" and "naturally". It is derived from a sample in the MSDN Library.

   EXAMPLE:
   >natstrsort.exe 1pic2.jpg 2pic5.jpg 5pic3.jpg  1z.pop z.pop  1.10 1.9  a10.txt a01.txt a20b.txt a1.txt a2c.txt a12.c a1b.txt a2.c a2.txt
   Normal sort  : 1.10 1.9 1pic2.jpg 1z.pop 2pic5.jpg 5pic3.jpg a01.txt a1.txt a10.txt a12.c a1b.txt a2.c a2.txt a20b.txt a2c.txt z.pop
   Natural sort : 1.9 1.10 1pic2.jpg 1z.pop 2pic5.jpg 5pic3.jpg a01.txt a1.txt a1b.txt a2.c a2.txt a2c.txt a10.txt a12.c a20b.txt z.pop

   Note: The data is gathered from http://www.ghisler.ch/board/viewtopic.php?t=934.
*/

#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#include "strnatcmp.h" /* from http://sourcefrog.net/projects/natsort/strnatcmp.h
                          Copyright (C) 2000 by Martin Pool */


/*
   The qsort() function of the Standard C libary requires a compare function that
   accepts two pointers to anything.
   The following compare functions assume that "anything" is a zero terminated
   string (char*), so pAnything1 is actually const char**.
*/

static int compare_strcmp(const void *pAnything1, const void *pAnything2)
{
  return strcmp( *(char **)pAnything1 , *(char **)pAnything2 );
}

static int compare_strnatcmp(const void *pAnything1, const void *pAnything2)
{
  return strnatcmp( *(char **)pAnything1 , *(char **)pAnything2 );
}


void main( int argc, char **argv )
{
  int i;

  /* Eliminate argv[0] from sort */
  argv++;
  argc--;

  {
    /* Sort remaining args by Quicksort algorithm using NORMAL string comparison */
    qsort( (void *)argv, (size_t)argc, sizeof( char * ), compare_strcmp );

    /* Output sorted list */
    printf( "%s", "Normal sort  : " );
    for( i=0; i<argc; ++i )
    {
      printf( "%s ", argv[i] );
    }
    printf( "\n" );
  }

  {
    /* Sort remaining args by Quicksort algorithm using NATURAL string comparison */
    qsort( (void *)argv, (size_t)argc, sizeof( char * ), compare_strnatcmp );

    /* Output sorted list */
    printf( "%s", "Natural sort : " );
    for( i=0; i<argc; ++i )
    {
      printf( "%s ", argv[i] );
    }
    printf( "\n" );
  }
}
User avatar
JackFoo
Senior Member
Senior Member
Posts: 373
Joined: 2003-02-05, 19:53 UTC
Location: ERROR

Post by *JackFoo »

Damn, couldn't hold myself: the above C code isn't helpful; I presume the compare_strnatcmp function is what Christian wants or even just a specification for the so called "natural" sort, what you have posted is just some "wrapping".

Cheers.
jb
Senior Member
Senior Member
Posts: 412
Joined: 2003-02-09, 22:56 UTC
Location: Switzerland

Post by *jb »

JackFoo wrote:I presume the compare_strnatcmp function is what Christian wants or even just a specification for the so called "natural" sort, what you have posted is just some "wrapping".
Actually compare_strnatcmp() wraps strnatcmp() which is available at http://sourcefrog.net/projects/natsort/strnatcmp.c. For a start also Christian could just integrate it (or wrap it as you say) instead of reimplement it.
Last edited by jb on 2003-05-18, 18:27 UTC, edited 1 time in total.
Post Reply