Re: Question about hashtables implementation
| From: | Sherif Ramadan | Date: | Sun, 02 Sep 2012 19:45:13 +0000 |
| Subject: | Re: Question about hashtables implementation | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-62681@lists.php.net to get a copy of this message | ||
>
> OK, thanks for the information. It explains why I didn't find anything in
> the HashTable structure (unlike iterator pointer or the next free key).
>
Yes, because the hashtable is an ordered map. The only way to
logically prepend to it is to rework the whole thing. That's generally
how you prepend to a stack as well. You'll probably find that in most
C implementations of a stack or a linked list the only way to prepend
is to rebuild the entire stack or list.
That's why the existing implementation is just doing the equivalent of
what I demonstrated in PHP code (it creates a new hashtable).
Line 2053 of ext/standard/array.c
HashTable *new_hash; /* New hashtable for the stack */
>
> You're right; I hadn't noticed that.
> Side effect: add values at the beginning of an array could be very
> time-consuming, according to its size.
>
It's generally more costly to do so, yes.
>
>
> Thanks again for this link. I have the book of Sara (huge piece of work,
> btw), and I found some good documentation. But more information wouldn't
> hurt! :-)
>
Cheers :)