In the interpreter for my experimental programming language I have a symbol table. Each symbol consists of a name and a value (the value can be e.g.: of type string, int, fu
You effectively have a number of alternatives.
Libraries exist:
vector
of pairs, faster than a map for small or frozen sets because of cache locality.Critics
O(log N)
, but the items may be scattered throughout the memory, thus not playing well with caching strategies.O(N)
performance on find
, is it acceptable ?unordered_map
? They provide O(1)
lookup and retrieval (though the constant may be high) and are certainly suited to this task. If you have a look at Wikipedia's article on Hash Tables you'll realize that there are many strategies available and you can certainly pick one that will suit your particular usage pattern.