[REBOL] Another hash! question
From: m:s:licholai:ieee at: 28-Jan-2002 19:43
In the past several weeks there have been several discussions about
the hash! datatype and I hate to start another one, but as I was
playing with speeding up some scripts and timing results I found
some aspects of hash! behavior I cannot explain.
It seems that when repeatedly (over 1000 times) using find on sparse
hash! block then changing the next item I get incorrect behavior or
system lock ups. When using a regular block! the code runs fine,
but replacing the block! with a hash! causes problems. Here is
code I have been using to try to determine the source problem
(try making sum-data a hash! instead of a block!):
stats: func [ data ][
; sum-data: make hash! 100
sum-data: copy []
forskip data 2 [
id: first data
this-time: second data
either (datum: find/skip sum-data id 3) [
total-nr: 1 + second datum
total-spent: this-time + third datum
change datum: next datum :total-nr
change next datum :total-spent
][
append sum-data :id
append sum-data 1
append sum-data this-time
]
]
sps: " "
print ["id count sum"]
forskip sum-data 3 [
print [first sum-data sps second sum-data sps third sum-data]
]
]
I ran the above code with this test harness:
REBOL []
print "prep data"
random/seed now/time/precise
test-blk: copy []
t-blk: ["t1" "t2" "t3" "t8" "t876" "u76"]
loop 1000 [
id: first random t-blk
append append test-blk id random 100
]
print "process"
stats test-blk
Does anyone have any suggestions? Is the problem in writing to the
hash! such a large number of times? Recognizing that inserting values
into a hash is not efficient, but is there another other choice for a
fast associative data structure?
Puzzled,
Matt