in reply to Hash and Array
If your question is, and I'm way out on a limb here trying to interpret your question:
Can you correctly describe a hash as being implemented an array of pointers internally
then the answer is a qualified "Yes and No":)
In essence, a hash consists of a (c-style) array of pointers, with each pointer leading to a structure that contains two further pointers. One pointing to the key for element, and the other to value. When an element is accessed, the characters that make up the key are munged (Tech. term:) mathematically by some algorithm to yield an index into the array. The pointer in this location leads to the structure and thence the value (and a copy of the key).
If the array where infinite in size, and the munging (hashing) algorithm were perfect, that would enough, but in the real world infinite arrays don't exist and hashing algorithms are imperfect except for special cases of highly tailored algorithms for specific, limited key sets., so the has to be extra logic, flags and pointers to deal with collisions.
See Gisle Aas' PerlGuts Illustrated for the most accessible description of perls internals I've encountered (you'll need to scroll down a ways or search for "RITER, EITER" to find the description of Perls hashes. It also includes a really excellent picture of their layout HV.PNG.
My apologies in advance if I misinterpreted your question, but a mention of PerlGuts Illustrated and Gisle's generosity in making it available is worth it anyway.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Hash and Array
by donno20 (Sexton) on Apr 28, 2003 at 03:44 UTC | |
by BrowserUk (Patriarch) on Apr 28, 2003 at 05:13 UTC |