in reply to using values and keys functions
To understand the answers, you need to know how a hash works internally. Internally a hash has a set of buckets. There is a function (aka a hash function) that decides what bucket each key should go into. Ideally the assignment of keys to buckets will look random, so if you have enough buckets for your keys, then no bucket has very many keys. But in fact it is deterministic. That means that inserting/retrieving/deleting are always fast, because you only have to work with the handful of keys in a bucket. (Technical note, Perl changes the number of buckets if the hash gets too many keys, thereby keeping the number of keys/bucket down. This operation is known as a "hash split" and is expensive. But it is also rare, and the cost of this operation averages out to a constant per insert. Perl does not try to reclaim memory if a hash shrinks after having grown.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: using values and keys functions
by monarch (Priest) on Jun 09, 2005 at 07:25 UTC | |
by BrowserUk (Patriarch) on Jun 09, 2005 at 14:09 UTC | |
by tilly (Archbishop) on Jun 09, 2005 at 19:01 UTC |