Results 1 to 7 of 7

Thread: Suggest me a container

  1. #1
    Join Date
    Jan 2011
    Posts
    34
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Suggest me a container

    I have a list of structures which contains IP, port and transfer speed fields. List must be always sorted by speed (to take N-fastest clients) and have logarithmic search time by IP/port fields. Could you suggest me appropriate container for this?

  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: Suggest me a container

    ...std::map

  3. #3
    Join Date
    Jan 2011
    Posts
    34
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Suggest me a container

    std::map or QMap not a solution, as I understood they are always sorted and searched by THE SAME field, but I need to sort by one field and search by other. QMap can be searched by value, but it will be slow.

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

    Default Re: Suggest me a container

    Use two. Use pointers.

  5. #5
    Join Date
    Apr 2011
    Posts
    124
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Default Re: Suggest me a container

    1) Use SQL.
    2) As suggested, keep your objects separate and use pointers in two separate maps.
    3) Roll your own. It's not rocket science.

  6. #6
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Suggest me a container

    You may need to maintain 3 containers, to achieve the specified performance.

    1. sorted with speed (to take N-fastest clients), use qSort() to sort
    2. sorted with IP/Port, use qSort() to sort then use qBinaryFind() to search
    3. the master container with actual objects, the first two contain references to this container

    you need to implement the appropriate operators (like ==, >) too use the containers (stl / qt algorithms) to be able to sort, find etc.

  7. The following user says thank you to Santosh Reddy for this useful post:

    giantdragon (3rd June 2011)

  8. #7
    Join Date
    Sep 2011
    Posts
    2
    Qt products
    Qt3
    Platforms
    MacOS X

    Default Re: Suggest me a container

    The other option is to use Qhash

Similar Threads

  1. Do you suggest to develop a videoplayer and notetaker with QT ?
    By fenerista in forum Qt-based Software
    Replies: 4
    Last Post: 14th November 2009, 06:28
  2. Container plugins
    By Benne Gesserit in forum Qt Tools
    Replies: 4
    Last Post: 20th November 2008, 23:43
  3. Quick ? about qSort(Container & container)
    By JimDaniel in forum Qt Programming
    Replies: 2
    Last Post: 15th December 2007, 11:20
  4. Container Extensions
    By mariok in forum Qt Programming
    Replies: 1
    Last Post: 3rd July 2007, 11:06

Tags for this Thread

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.