Qt way to set FIFO map ?
-
Hello
is there any way in Qt to define FIFO map , that elements that inserted to the structure could be "get" by key
and also support some-kind of pop() method that will give me the first element that entered into the structure.
i know there is QQueue that suport FIFO , but what is the best way to implement map init rather then "search with loop inside it " way . -
The problem is that a map is typically implemented using a tree data structure, to ensure that access time is logarithmic in the number of elements. But (most) trees don't keep track of the order the elements were inserted in. I think your best bet is going to be to manually track the order of insertions using an separate, parallel, data structure. e.g. every time you insert into the map, also push an iterator to that element onto a queue. You could write a simple data structure that was a thin wrapper around these two structures and that behaved the way you want, but I doubt that there is anything predefined in Qt (or anywhere else for that matter... the STL doesn't have a structure that does that: it maintains a distinction between "Sequences" and "Associative Containers").