Results 1 to 5 of 5

Thread: Fast QList search/access

  1. #1
    Join Date
    Jan 2011
    Posts
    9
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Fast QList search/access

    Hi all,

    i have a list of custom MyObject objects. MyObject has a property QPoint. I need a quick search in list to retrieve those MyObjects that match given QPoint (more precise - have the same x and y).

    What i was thinking is using QHash<QPoint, QList<MyObject*>> ... or perhaps other, faster way exist? (many MyObjects can have same QPoints)

    Currently data is not very large- arr ound 50 items, but could grow to ~200.

    Thanks!

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Fast QList search/access

    If there are only a few hundred points, you likely won't notice any difference between a simple linear search and a fast, log(n) algorithm like binary search. There just aren't enough comparisons to worry about.

    Code it simply first, then identify where you actually need performance improvements. It's hard to imagine this being such a place.

  3. #3
    Join Date
    Jan 2011
    Posts
    9
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: Fast QList search/access

    It will not be a single search. Rather a search every few second (user moves map, we do search). But ok, i'll try to code, and check Thanks!

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Fast QList search/access

    If it is so often, then you really may work on that. If so, consider to split QPoint into its x and y parameters. So you can possible avoid some look ups/comparisons: (to be improved!)
    Qt Code:
    1. QHash<int, QHash<int, MyObject*> > data;
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Fast QList search/access

    I would consider a structure that retains order in x and y separately. So that once you get hold of an interesting area, you get direct access to its neighbourhood. And of course using BSP (binary space partitioning) is also a great option once the amount of data increases.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Cast QList<Foo*> to QList<const Foo*>
    By vfernandez in forum Qt Programming
    Replies: 0
    Last Post: 4th October 2010, 16:04
  2. Replies: 4
    Last Post: 20th August 2010, 13:54
  3. [SOLVED]Use of Iterator to access a QList
    By graciano in forum Qt Programming
    Replies: 10
    Last Post: 22nd March 2010, 16:25
  4. segfault while trying to access QList
    By Raven24 in forum General Programming
    Replies: 1
    Last Post: 3rd March 2010, 06:53
  5. BEst way to search QList for item
    By steg90 in forum Qt Programming
    Replies: 11
    Last Post: 18th July 2007, 09:41

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.