3 ms·
Lua uses "chained scatter" (linked list, but links point to other entries in the same table, to maintain locality): https://github.com/lua/lua/blob/master/ltabl
by haberman 5y ago
Lua uses "chained scatter" (linked list, but links point to other entries in the same table, to maintain locality): https://github.com/lua/lua/blob/master/ltable.c https://github.com/lua/lua/blob/master/ltable.c
This is a good visual depiction of chained scatter: https://book.huihoo.com/data-structures-and-algorithms-with-object-oriented-design-patterns-in-c++/html/page230.html https://book.huihoo.com/data-structures-and-algorithms-with-...
Inspired by Lua, I did the same for upb (https://github.com/protocolbuffers/upb https://github.com/protocolbuffers/upb). I recently benchmarked upb's table vs SwissTable for a string-keyed table and found upb was faster in both insert and lookup (in insert upb is beating SwissTable by 2x).
It's true that the links do create more memory overhead though.
- xxs 5y agoTo improve locality it has to be on the same cache line, effectively linear probing