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. Data structure searched
Forum Updated to NodeBB v4.3 + New Features

Data structure searched

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 622 Views 1 Watching
  • 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.
  • S Offline
    S Offline
    schoettner
    wrote on last edited by
    #1

    Hi everyone,

    I currently have a problem with a data structure I could use some advice with, since I can come up with anything good.
    There are 4 hash tables with the same keys but different values. It also would be possible to put them together in a new container. The 4 different values for each key should be ordered (asc or desc doesn't matter) and I want the average of the 2nd and 3rd.
    The idea I have is to iterate through one table to get the keys, go to each tables and get the values, add them to a list, qSort() the list with the 4 values and save the result in a new hashtable with the key.
    I guess that would work but does not perform very well. Any idea?

    Thanks

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What are your hash tables currently ? Do you want to replace them ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #3

        In light of current cache and CPU architectures you could consider something simple like this:
        @
        struct Data {
        SomeType key;
        std::array<SomeOtherType,4> values;
        };
        std::vector<Data> mySortedData;
        @
        ...with some access functions that would ensure sorted insertion and something like binary search for look up.

        This all depends of course on the size, type and access patterns of your data.
        Stuff like cache locality and branch prediction make many algorithmic complexity assumptions void these days. Profiling and benchmarking seem to be the mantra of today.

        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