[REBOL] Re: Sort by first part of line
From: joel:neely:fedex at: 8-Sep-2002 7:35
Note to self: be more complete!
I should have pointed out that the modified algorithm below splits
the group number from the remainder of the line; therefore, some
post-processing might be needed to re-attach the three-digit prefix
to the data (unless, of course, the subsequent processing could use
the bucket index for that purpose). So the time comparison may not
be comletely fair.
-jn-
Joel Neely wrote:
> Reminding myself to take a clue from the first point, we can use
> the implicit looping of PARSE, and the fact that the prefixes are
> only three digits long to come up with something like this:
>
> 8<--------
>
> t0: now/time/precise
> buffer: copy/deep array/initial 999 [[]]
>
> digit: charset "0123456789"
> parse/all read f [
> some [
> some " "
> copy nr some digit
> copy data [thru "^/" | to end] (
> append pick buffer to-integer nr data
> )
> ]
> ]
>
> t1: now/time/precise
> print to-decimal t1 - t0
>
> 8<--------
>
> which, by my tests, actually runs a bit (~7%) faster than my
> first version (which extended the buffer within the inner loop
> whenever needed)...
>
--
; Joel Neely joeldotneelyatfedexdotcom
REBOL [] do [ do func [s] [ foreach [a b] s [prin b] ] sort/skip
do function [s] [t] [ t: "" foreach [a b] s [repend t [b a]] t ] {
| e s m!zauafBpcvekexEohthjJakwLrngohOqrlryRnsctdtiub} 2 ]