C++ STL Map vs Vector speed

后端 未结 12 1054
日久生厌
日久生厌 2020-12-16 11:56

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

12条回答
  •  既然无缘
    2020-12-16 12:20

    For looking up values, by a string key, map data type is the appropriate one, as mentioned by other users.

    STL map implementations usually are implemented with self-balancing trees, like the red black tree data structure, and their operations take O(logn) time.

    My advice is to wrap the table manipulation code in functions,
    like table_has(name), table_put(name) and table_get(name).

    That way you can change the inner symbol table representation easily if you experience
    slow run time performance, plus you can embed in those routines cache functionality later.

提交回复
热议问题