Howdy Brett:
Hash's are good for scripts which have a bunch of block data in
memory that they want to do many searches on. For instance, if you
had something like this:
associations: [
jeffrey giraffe
snoopy dog
garfield cat
... and on and on
]
with say more than a few hundred of such pairs and you was
doing a bunch of things like:
select associations 'garfield
then you'd want to HASH your block, and your script would then
be a lot faster.
h-assoc: make hash! associations
You'd still do select on the new hash:
select h-assoc 'snoopy
..the selection with a block ends up being a linear search for
'snoopy, but with the hash it's a constant time search. Creating the
hash takes some amount of time for large block data, so it's only
worth it if the hash will be sticking around in memory for some time
(ie. not as useful for things like CGI.) Of course, you can insert
and remove items into a hash! in the same way you work with blocks.
-jeff
> >From the user guide:
> "Hash is a storage method that makes finding data in large files
> faster. The hash datatype is useful for converting data into a
> binary table format that is readily searchable. " Cool.
> and: "Hash values are identical in operation to block values. See
> blocks values for detail on the format of block values. " Excellent.
> Umm.., but the examples there seem counter-intuitive to me
> (probably because I have way too much experience in relation
> databases).
> So can someone show me how and when hash! is most optimally used
> please?
> Brett