1. 7.6.2.3 sort_user

Is it true, this function sorts all the fields in one direction? Have you looked at sorttok() and sortntok() in strtok v2.2? Either allows you to sort each field in any direction:

string = {"Red,Skelton,45,London,England", 
          "Lucy,Ball,56,Barre,North Dakota", 
          "Fred,Astaire,45,Alberta,Canada", 
          "Pierre,du Pont,56,Paris,France"} 
 
string = sorttok(string,{3,-2},',') 
 
string = {"Red,Skelton,45,London,England", 
          "Fred,Astaire,45,Alberta,Canada", 
          "Pierre,du Pont,56,Paris,France", 
          "Lucy,Ball,56,Barre,North Dakota"} 

You see, it did a ascending sort on (fictitious) age field (field3, positive), then sorted the last name field (field2, negative) in decending order.

sortntok() is the same, but returns the sorted line numbers of string, not the lines themselves.

useless

new topic     » topic index » view message » categorize

2. Re: 7.6.2.3 sort_user

useless said...

Is it true, this function sorts all the fields in one direction?

The documentation is a bit misleading. The custom_sort orders the result determined by the value returned by the user-defined comparision routine. The order argument can be used to reverse the sense of the user defined routine's value.

In other words, when the user defined routine returns a negative value, the order=DESCENDING parameter causes the sort to behave as if the routine had returned a postive value.

I've updated the documentation to make this more clearer.

useless said...

Have you looked at sorttok() and sortntok() in strtok v2.2? Either allows you to sort each field in any direction:

string = {"Red,Skelton,45,London,England", 
          "Lucy,Ball,56,Barre,North Dakota", 
          "Fred,Astaire,45,Alberta,Canada", 
          "Pierre,du Pont,56,Paris,France"} 
 
string = sorttok(string,{3,-2},',') 
 
string = {"Red,Skelton,45,London,England", 
          "Fred,Astaire,45,Alberta,Canada", 
          "Pierre,du Pont,56,Paris,France", 
          "Lucy,Ball,56,Barre,North Dakota"} 

You see, it did a ascending sort on (fictitious) age field (field3, positive), then sorted the last name field (field2, negative) in decending order.

sortntok() is the same, but returns the sorted line numbers of string, not the lines themselves.

These are nice routines. We already have a sort_columns() routine but it works on sequences that represent records - each element is a field. In your case, the sequences are text with comma-delimited fields.

I'll have a go at adding your ideas into the library ... maybe this weekend.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu