Louis:
> Your sort worked perfectly. Thanks also for the explanation.
> You might be interested to know that
> on my 450 Pentium 2 running w2k total time to sort
> 29,688 lines using your code was:
>
> 3:50:10
<snip>
> One question I'll ask now however: What exactly does hash do, and could
> hash be used to speed up sort?
I'm glad to hear it worked, even if it took three hours.
In my experience, you can speed things up with more memory. Take this example:
a: copy [1]
forever [
print [length? a now/precise]
append a a
]
I have a 1gig machine with 384meg of memory. This takes under 30 seconds to
error-out with "not enough memory". The same test on my now-dead 450Mhz
128meg machine was still running after several hours.
Your code may also be running slowly because I suspect 'parse is a big
overhead. You *might* be able to speed it up (given the nature of your data)
by extracting that sort key in another way.
For example (here I've adapted Gregg's code, and I've changed the order of
the tests, as equality is not likely on the test data I saw):
sort data func [a b /local aa bb] [
aa: first to-block a
bb: first to-block b
either aa < bb [-1][either aa = bb [0][1]]
]
But I don't guarantee this will be any faster -- tuning is an art, and you
need to practice and experiment.
You may also find, given the amount of data you have, things work better if
you preallocate blocks, so:
my-data: make block! [] 30'000 ;;; allocate space for 30,000 entries
append my-data read/lines %my-data-file.txt
A hash is a faster way of finding data in a series. It won't help the sort,
but it could help find records in the sorted series.
a-series: [ "aa" "hh" "nn" "jj" "uu"]
a-hash: make hash! a-series
For most practical purposes, a-series and a-hash behave the same. You can,
for example, find items like this:
find a-series "jj"
find a-hash "jj"
The hash is likely to be much faster for a series of over a certain size -- I
don't know what that size is, but I tend to use hash for anything over 100 or
so entries.
Sunanda.
--
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the
subject, without the quotes.