Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Sort by first part of line

From: rotenca:telvia:it at: 6-Sep-2002 14:48

Hi,
> >I think that he can parse the string building a sortable block and then
rejoin
> >the data in a string. > > Would you please give an example?
My idea is like Anton's one. Andrew came with an interesting idea, but how fast? If the whole line had a fixed lenght, we could use another method, more fast, here i presume lines are of different lengths. Here i assume that numbers strings are right aligned and of fixed lengths and separators are spaces (not tabs) to be a little more fast. REBOL [] probe r: 10000 ;10000 lines string: make string! 2000000 string: head insert/dup tail "" { 454 en tw 12395 en th 313 kai o 175 oi de asdf 313 eij thn 174 eij ton 124 kai ouk dffd fder 4123 kai thn 219 ek tou 160 kai en tty ttq qzfcv } r / 10 blk: make block! 2 * r ; 2 * number of lines in the string s2: has [num rest] [ clear blk parse/all string [ some [ copy num [any " " to " "] copy rest thru newline (insert insert tail blk num rest) ] ] to string! sort/skip blk 2 ] probe s2 --- Ciao Romano