This is not a full answer, just some points.
As for the size of a hash, when a new hash with one
element is created, it has 8 hash buckets initially.
I don't know how it is grown, but you can check it
by experimenting: evaluate a hash in scalar
context, and you'll get a string containing eg "3/8" if it has
8 hash buckets of which 3 is not empty.
As for the actual implementation, I can't say anything,
but you can try to read perl's source, esp. hv.c.
For the bonus question, the C++ standard library
implements associative arrays (they call it map)
as tree structures, specifically red-black trees.
Other implementations then gcc's library can use other kind
of trees, but they can't use a hash table as
the keys can be anything, and all the functions
get about the keys is a comparision function.
Ruby uses a hash table.
Some lisps have balanced trees too.
Gcc has functions for balanced trees too.
Question: does awk use hash-tables or trees or it depends on version.
Only slightly related to your question is that the linux kernel itself uses red-black trees for some
memory-management functions; it might use hashes too somewhere.
Reiserfs has a balanced-tree structure (where the key itself
is the hash-key of the filename).
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||