4 ms·
It looks like recently, there has been a convergence of hashtable implementations across a number of programming languages. Details differ, but the general stru
by nikic 10y ago
It looks like recently, there has been a convergence of hashtable implementations across a number of programming languages. Details differ, but the general structure is now to use two arrays, one for storing the data in insertion order (thus maintaining order without a doubly linked list), and another array serving as a hash, which contains indexes into the data array. This general idea works both with chaining and open addressing. In the last couple of years PHP (first HHVM then Zend), then Python (first PyPy then CPython), then Ruby (MRI) have switched to using this layout. Interestingly, Python has previously not made guarantees about order of hashtable elements, so this layout is advantageous even if maintaining insertion order is not a hard design constraint.
- euyyn 10y agoHow do they remove elements from the first array? Suck it and do O(N), or is it storing (value, deleted?) pairs?
- brianwawok 10y agoLook at the index as given by the hash?
- euyyn 10y agoOh, so as you iterate the array, look up the value in the hash and if it's not there skip it? The downside is you end up accumulating dead values.
- pmontra 10y agoIt also helps with cache locality.