I have a lot of lists, vectors, sets ... (what ever you prefer) of pointers called
RealAlgebraicNumberPtr to certain class. They are sorted.
I want to merge them and of course I want to do it fast and efficient.
¿Cual es la mejor opción?
std::merge ? O tal vez
std::set? I can provide both an < and == ordering.
preguntado el 08 de noviembre de 11 a las 11:11
Como se mencionó,
std::merge esta bien
Only for std::list, you can profit from the optimization that
std::list::merge función miembro implements: it splices the list nodes from the source into the target. That way, the source list will become empty, but it will avoid resource (re)allocation
you could in fact std::merge into a std::set to get unique values in one go. With generic merge, duplicate values are not filtered, but the result is sorted, so you could apply
std::unique to the result. If you expect a lot of duplicates, you might be quicker using a
std::merge is as efficient as it gets. Which underlying container you use depends on your requirements.
std::vector has the smallest memory-overhead of all standard containers, so if your data are large, you should stick with that.
std::vector, tiene que
resize the target-vector before merging to avoid reallocations (you should be able to calculate the required size up-front), instead of using an