Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt way to set FIFO map ?

    General and Desktop
    3
    5
    2868
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • U
      umen242 last edited by

      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 .

      1 Reply Last reply Reply Quote 0
      • C
        Chris H last edited by

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

        1 Reply Last reply Reply Quote 0
        • U
          umen242 last edited by

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

          1 Reply Last reply Reply Quote 0
          • A
            andre last edited by

            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.

            1 Reply Last reply Reply Quote 0
            • U
              umen242 last edited by

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

              1 Reply Last reply Reply Quote 0
              • First post
                Last post