N
N
Nikita Gusakov2014-01-24 23:02:05
C++ / C#
Nikita Gusakov, 2014-01-24 23:02:05

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

2 answer(s)
B
bak, 2014-01-24
@bak

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.

T
tsarevfs, 2014-01-24
@tsarevfs

A little more developed: http://neerc.ifmo.ru/wiki

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question