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. Key-based container with custom sort order?

Key-based container with custom sort order?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 1.1k 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.
  • A Offline
    A Offline
    Asperamanca
    wrote on last edited by
    #1

    I am looking for a container with fast key-based lookup (like QHash, QMap), but where I can choose in which order items are inserted (like QList). I think that none of the Qt or std containers can provide that, but I hope you can prove me wrong.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      t3685
      wrote on last edited by
      #2

      The fast lookup is achieved by optimizing the order of the items, so what you're asking is not possible with standard containers.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Asperamanca
        wrote on last edited by
        #3

        Technically, such a container would require two separate tables internally. I just hoped such a construct already existed.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tilsitt
          wrote on last edited by
          #4

          Hi,

          containers like the map are based on the comparison operators: if you encapsulates you keys inside a class with operators based on your sort algorithm, that would do the trick.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Asperamanca
            wrote on last edited by
            #5

            Unfortunately, not an option here. They keys I need for searching have their own sort order, nothing I can influence.

            1 Reply Last reply
            0
            • T Offline
              T Offline
              tilsitt
              wrote on last edited by
              #6

              What I meant is that you can influence by storing the keys in a structure in which you can define sort order (?)

              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