Is there already some std::vector based set/map implementation?

前端 未结 6 1520
囚心锁ツ
囚心锁ツ 2021-02-08 07:43

For small sets or maps, it\'s usually much faster to just use a sorted vector, instead of the tree-based set/map - especially for something like 5-10 e

6条回答
  •  太阳男子
    2021-02-08 08:36

    If the set or map truly is small, the performance gained by micro-optimizing the data structure will have little to no noticeable effects. You'll save maybe one or two memory (read: cache) lookups when searching a tiny tree vs tiny vector, which in the big picture is insignificant.

    Having said that, you could give hash_map a try. Lookups by key are guaranteed to run in constant time.

提交回复
热议问题