Hi,
I am looking for a special template class, hopefully either a QT template or a self-contained open source library. This template class is intended to act as a container for a set of objects. Each object in the set has an integer-valued weight function but the weight function itself is arbitrary. It could range uniformly from 10 to 100 or vary non-uniformly from 1000 to 10000 or be a constant value.
The template would keep a list of objects sorted by this weight (resolving ties arbitrarily). It would allow me to quickly retrieve the object having nth highest weight from the list, by order, not value (random access using an integer, like QList). The template also allow me to quickly add and remove arbitrary elements while keeping the list ordered by weight (like a QMap).
Just quickly finding objects within an order of magnitude would be enough for my purposes - IE, finding the 1st, the 10th, the 100th, the 1000th and so-forth elements in my ordered list would suffice.
I could implement a data structure like this myself (as an array of lists of increasing size or as a modified a binary tree having a count of n elements below each node). But it seems better to use a standard, commonly available, well documented template to solve the problem. I would prefer to avoid STL but if there's an STL solution, I would be interested.
Edit: I'm looking for, at the least, orders of magnitude - not just the first but the 1st, the 10th, the 100th ordered by weight on up to the end (the internal ordering of a heap data structure would be great but I don't see any functions that directly access this). I can see that STL provides a "random access iterator" but after paging through a fair amount of documentation, I still can't find if this iterator would give the nth value without needing to sort the list for each call - indeed, my vague impression is that it would. STL also provides an "nth element" function but it appears that this is relatively costly if you are calling it for each access to the list.
Edit2: Reason one can't simply use a QMap iterator and do it2 = it.begin()+1000; (from QT's documentation):
iterator iterator::operator+ ( int j ) const
Returns an iterator to the item at j positions forward from this iterator. (If j is negative, the iterator goes backward.)
This operation can be slow for large j values.
See also operator-().