Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hash table/map implementation without dynamic allocations

Does anyone know of a C/C++ hash table/map implementation that does not dynamically allocate memory? I'm working on an embedded system that has no standard library & no heap (unless I want to write/port one).

like image 695
Philippe Chaintreuil Avatar asked Apr 05 '13 20:04

Philippe Chaintreuil


People also ask

How can dynamic allocation be avoided?

If you really want to prevent your C++ programs from using dynamic memory allocation, you should replace all four variants of operator new with versions that cause link errors. Four variants of operator delete (one corresponding to each replaceable variant of operator new ) are also replaceable.

How are hash tables implemented?

Any Hash Table implementation has the following three components: A good Hash function to map keys to values. A Hash Table Data Structure that supports insert, search and delete operations. A Data Structure to account for collision of keys.

How is HashMap implemented in CPP?

i.e. if the range of key values is very small, then most of the hash table is not used and chains get longer. Below is the Hash Map implementation in C++. HashMap class contains the hash table, which is a double pointer to HashNode class and default table size in constant is used to construct this hash table.

How can I make a hash table faster?

The trick is to use Robin Hood hashing with an upper limit on the number of probes. If an element has to be more than X positions away from its ideal position, you grow the table and hope that with a bigger table every element can be close to where it wants to be.


1 Answers

The terms you're looking for are "Open addressing" or "closed hashing". See http://en.wikibooks.org/wiki/Data_Structures/Hash_Tables#Open_addressing and http://en.wikipedia.org/wiki/Open_addressing

Don't know a specific implementation, though. Sorry.

like image 147
Sebastian Avatar answered Nov 15 '22 22:11

Sebastian