lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I created a simple C++ hash table implementation that is derived from
the Lua table implementation.

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:

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.