Re: STL container question
On Oct 1, 3:40 pm, Jeff Schwab <j...@schwabcenter.com> wrote:
Boltar wrote:
I need to store a number of integer values which I will then
search on later to see if they exist in my container. Can
someone tell me which container would be quickest for
finding these values? I can't use a plain C array (unless I
make it 2^32 in size!) since I don't know the max integer
value.
Sorted vector. See Effective STL, Item 23.
For the record, you wouldn't 2^32 integers, just 2^32 bits =
500 MiB. It's actually not that much RAM, depending on your
target system, and would let you check for integers with O(1)
complexity (rather than O(log N)).
Some systems won't allow you to allocate that much as a local
variable, so you might as well use std::vector. If the
reallocations are an issue, one call up front to capacity should
solve that.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34