[REBOL] Re:Associative Array
From: kgd03011:nifty:ne:jp at: 14-Sep-2000 23:30
>Has any one made an associative arrary in Rebol? Something like:
> a/Associate Key Value
> TheValue: a/find Key
> It would be nice to show this to people used to using associative
>arrays, that Rebol can do so as well.
Hi Andrew,
Here's my latest attempt.
make-hash: func [][
make object! [
pos: none
keys: make hash! 1000
values: make block! 1000
set: func [key value][
either pos: find keys key
[poke values index? pos value]
[append keys key append values value]
]
get: func [key][
either pos: find keys key [pick values index? pos][none]
]
]
]
>> a: make-hash
>> a/set "brown" "chairo"
== ["chairo"]
>> a/set "green" "midori"
== ["chairo" "midori"]
>> a/set "brown" "kogechairo"
== ["kogechairo" "midori"]
>> a/get "brown"
== "kogechairo"
>> a/get "midori"
== none
Still, all the experimenting I've done indicates Rebol can't do
large associative arrays (more than a couple thousand keys)
nearly as efficiently as Perl.
Eric