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?
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?
...std::map
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.
Use two. Use pointers.
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.
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.
giantdragon (3rd June 2011)
The other option is to use Qhash
Bookmarks