Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt way to set FIFO map ?
QtWS25 Last Chance

Qt way to set FIFO map ?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.2k Views
  • 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 Offline
    U Offline
    umen242
    wrote on last edited by
    #1

    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
    0
    • C Offline
      C Offline
      Chris H
      wrote on last edited by
      #2

      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
      0
      • U Offline
        U Offline
        umen242
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          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
          0
          • U Offline
            U Offline
            umen242
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved