2 ms·
If your elements are in the millions than a tree might be better, depending on what you do. If you traverse the whole thing often then vector is best, but at a
by bluGill 4y ago
If your elements are in the millions than a tree might be better, depending on what you do. If you traverse the whole thing often then vector is best, but at a million a tree will do a search for element faster despite the cache misses.
I don't know where the line is, but in general you are probably not close to that line so default go vector. However as your point is, sometimes you are over that line.
- sally_glance 4y agoAnd if you really need it you can even do both tree and vector simultaneously - just make sure both consist of pointers only so you avoid update/sync issues.
- bluGill 4y agoYou can, but probably shouldn't. The pointers means a cache miss when you follow it. Putting everything in the vector is the point, otherwise the map is potentially faster