Why does Google sparsehash open-source library has two implementations: a dense hashtable and a sparse one?
What is the main implementation idea behind sparse hash table?
12k views Asked by Denis Gorodetskiy At
2
Why does Google sparsehash open-source library has two implementations: a dense hashtable and a sparse one?
The dense hashtable is your ordinary textbook hashtable implementation.
The sparse hashtable stores only the elements that have actually been set, divided over a number of arrays. To quote from the comments in the implementation of sparse tables:
To know which elements of the arrays are set, a sparse table includes a bitmap:
so that each element incurs an overhead of only 1 bit (in the limit).