[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: A C++ port of Lua table implementation
- From: Dibyendu Majumdar <mobile@...>
- Date: Sun, 14 Aug 2016 17:13:28 +0100
Hi
I created a simple C++ hash table implementation that is derived from
the Lua table implementation.
https://github.com/dibyendumajumdar/try-catch-finally/blob/master/hash/hashtable.h
It is defined as a C++ template in header only file. Not STL compatible though.
The Lua implementation requires that keys and values have a 'nil'
value. In the C++ version this is achieved by using a special value of
the key or value as nil. For example, for an 'int' value, we can
denote the nil by INT_MIN. For strings we can use an empty string. In
any case the user must decide what value to use as nil.
An illustration of how the table is used is here:
https://github.com/dibyendumajumdar/try-catch-finally/blob/master/hash/hashtable_t.cpp
I guess the main advantage of this implementation is that data is
stored in an array. This may make it cache friendly - although I have
not yet done any benchmarks. Before benchmarking one would need to
optimize the construction/destruction of objects when rehashing for
example - as the code right now reflects the way it is done in C which
may not be most optimum.
Regards
Dibyendu