Answer the question
In order to leave comments, you need to log in
How are real hashes arranged?
I studied hashes here, made a small implementation. But now it became interesting to me - how it is done in the normal way, in stl for example.
I actually have a hash - std::list<T> *_hash
, that is, an array of collisions.
It turns out that either we must know in advance the maximum number that the hash function can return and create an array of this length. But it's not memory efficient and I doubt it's used.
So my question is, what is the right way to do this?
Neither binary trees nor lists are suitable - the meaning of a hash, as I understand it, is reading, searching, deleting in the average case in O (n)
Answer the question
In order to leave comments, you need to log in
Just like a vector. Initially, the maximum size is considered small, and each time it is filled, it increases by N times. To get the position in the array, not the hash function itself is taken, but the remainder of dividing it by the maximum size. As the size of the array increases, all elements are re-allocated.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question