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").

  • Thanks for your replay , basically i need something like php Associative arrays

  • I agree with Chris H, though I would not use iterators. The problem with those is, that they may be invalidated by modifications in the container. Instead, I would just push the keys of the associative container into a QQueue.

  • Thanks Andre , this is what i have implemented in the end

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.