Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 459027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:43:54+00:00 2026-05-12T22:43:54+00:00

I am looking for a special template class, hopefully either a QT template or

  • 0

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-().

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T22:43:54+00:00Added an answer on May 12, 2026 at 10:43 pm

    The data structure you’re looking for is a heap. The stdlib has std::make_help, push_heap, and pop_heap. There is also std::priority_queue. (I’m not sure why you’d avoid these, unless there’s some other requirement you haven’t told us about.)

    A tree such as a map will also work, but it will sort every item. If you need, for example, only the ‘best’ three out of 1,000,000, then sorting all of them would be wasteful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for a java class to parse all HTML special characters. I guess
I'm looking for a performant, reasonably robust RNG using no special hardware. It can
Looking for C# class which wraps calls to do the following: read and write
This is from some code I'm looking at... I think it's some sort of
I'm looking to encode special characters(ex: Japanese chars) along with ' . encodeURIComponent() encodes
I am looking für a css-way to set td-attributes in tables with an special
I'm looking for a set of CSS/JS code that would let me create special
Looking for feedback on : http://code.google.com/p/google-perftools/wiki/GooglePerformanceTools
Looking for an example that: Launches an EXE Waits for the EXE to finish.
Looking at what's running and nothing jumps out. Thanks!

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.