std::unordered_map insert with hint

后端 未结 2 883
攒了一身酷
攒了一身酷 2020-12-10 23:46

std::map has an insert method that takes a \"hint\" iterator that will reduce the insertion time from log(n) to constant time if the hint is correc

相关标签:
2条回答
  • 2020-12-11 00:08

    It is an interface compatibility issue. Basically, the design is done considering the interface of std::map.

    In other words, for std::unordered_map it does not differ a hint is provided or not.

    Additional Information from the comments here:

    The interface compatibility is very important because being able to quickly/easily switch between map and unordered_map provides the valuable flexibility of painlessly transition since performance is often the deciding factor in choosing one over the other.

    0 讨论(0)
  • 2020-12-11 00:28

    The hint allows the unordered map implementation to do a value compare first to see if the hint works. This avoids having to do the hash function which can be more costly than a compare operation.

    0 讨论(0)
提交回复
热议问题