C++ STL Map vs Vector speed

后端 未结 12 1052
日久生厌
日久生厌 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:35

    std::map's operator[] takes O(log(n)) time. This means that it is quite efficient, but you still should avoid doing the lookups over and over again. Instead of storing an index, perhaps you can store a reference to the value, or an iterator to the container? This avoids having to do lookup entirely.

提交回复
热议问题