
7 Sep
2004
7 Sep
'04
9:32 p.m.
Rob Stewart wrote:
From: Stefan Slapeta <stefan@slapeta.com>
I'm looking for an associative container which is optimized for one-time insertion and avoids much of the overhead of std::map therefore. IIRC Andrei once published something like this: a vector of pairs that was sorted once and accessed by binary search.
std::vector + std::sort + std::binary_search?
(You'd populate the vector with your data, run std::sort on it, and then just use std::binary_search from that point forward.)
Other search algorithms which might prove more efficient for your data type, of course.
FWIW, if you decide to go with the above, be sure to profile it against a std::map first. You may be surprised. Not to mention hash_map, if you have one.