In article <11**********************@s13g2000cwa.googlegroups .com>,
qj*********@yahoo.com says...
I have a program that reads sorted data from a database and inserts it
element by element into a set.
If the data is sorted is there a faster way to insert ? Meaning is
there a way to tell the std::set to check the end of the tree before
doing the insert as a fast check on where the key is going to end up ?
Yes, you can use the version of insert that allows you to pass a
"hint" about where the insertion is likely to take place.
Given that you're starting with sorted data, you might consider
putting it into a vector, and using a binary search. You can then
supplement that (if necessary) with a set to hold newly-inserted
data. Since it uses contiguous memory, searching a vector is nearly
always substantially faster than searching a set. The shortcoming, of
course, is insertions (and deletions, if you insist on really
deleting data instead of just marking a location as empty).
Combining the two makes it fairly easy to get most of the good points
of each: you get faster searching because most data is in the vector,
but also fast inserts because you insert new data into the set.
--
Later,
Jerry.
The universe is a figment of its own imagination.