What is the best container suitable for the next task.

Fast movement of objects in any direction, the beginning / middle / end of the container on the principle of Z - indexing .

For example, the popup method opens so to speak, and this popup object should move to the end of the container for a while, after which it will have to be removed or simply moved 1 position down to overlap the content or display a message / warning / mistakes.

Such containers as map vector I think will not work at all, for one of the reasons, the vector or map will have to pull the entire collection to move or swap objects or move.

I looked at the list , but I think I also have my own pigs.

multi[set\map] looks good, but is not sure about its speed.

  • 3
    Try to start by writing this all on the basis of the usual vector. Well or on the basis of vector<unique_ptr<T>> . With high probability this is exactly what you need. And then test your performance. If your objects are small and the number of elements is less than a hundred, then the vector is likely to be the best solution - KoVadim
  • write all operations on the elements. While the usual tree is quite suitable. - pavel Nov.
  • Do you (in the example above) order the rendering of objects depending on the passage through the container in which they are stored (that is, the higher the index, the later the object will be drawn)? - isnullxbh
  • 3
    Mentioning set / map makes the question incomprehensible. What do you mean by "fast moving"? Fast reorganization of data in memory? Or a quick search for a new place to insert? - AnT
  • I did something similar through the stack + map. Map was a static repository of windows with the key = name. The stack was a hierarchy of open windows, the top of the stack is the current open window. As soon as you need to open a window, we add a pointer / link to this window onto the stack. As soon as the window closes, we simply remove the top element of the stack and display the new vertex (if there is one). - goldstar_labs

1 answer 1

How do you get the idea to create an array of pointers to objects, and if you want to move objects themselves - move pointers to them (much faster). Sorted, as needed, such an array of pointers to objects will be the necessary sequence of objects.