From 3b23a8cc23a20d01f602e588fc1cf309cebd92fb Mon Sep 17 00:00:00 2001
From: Chris Lattner
If you intend to insert a lot of elements, then do a lot of queries, one -great approach is to use a vector (or other sequential container), and then use +
If you intend to insert a lot of elements, then do a lot of queries, a +great approach is to use a vector (or other sequential container) with std::sort+std::unique to remove duplicates. This approach works really well if -your usage pattern has these two distinct phases (insert then query), and, -coupled with a good choice of sequential container -can provide the several nice properties: the result data is contiguous in memory -(good for cache locality), has few allocations, is easy to address (iterators in -the final vector are just indices or pointers), and can be efficiently queried -with a standard binary search.
+your usage pattern has these two distinct phases (insert then query), and can be +coupled with a good choice of sequential container. + + ++This combination provides the several nice properties: the result data is +contiguous in memory (good for cache locality), has few allocations, is easy to +address (iterators in the final vector are just indices or pointers), and can be +efficiently queried with a standard binary or radix search.
std::set is a reasonable all-around set class, which is good at many things -but great at nothing. std::set use a allocates memory for every single element +but great at nothing. std::set allocates memory for each element inserted (thus it is very malloc intensive) and typically stores three pointers with every element (thus adding a large amount of per-element space overhead). It offers guaranteed log(n) performance, which is not particularly fast. -- cgit v1.2.3-18-g5258