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

  • Home
  • SEARCH
  • 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 6247427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:52:09+00:00 2026-05-24T12:52:09+00:00

I’m looking for a C++ implementation of a data structure ( or a combination

  • 0

I’m looking for a C++ implementation of a data structure ( or a combination of data structures ) that meet the following criteria:

  • items are accessed in the same way as in std::vector
  • provides random access iterator ( along with iterator comparison <,> )
  • average item access(:lookup) time is at worst of O(log(n)) complexity
  • items are iterated over in the same order as they were added to the container
  • given an iterator, i can find out the ordinal position of the item pointed to in the container, at worst of O(log(n)) complexity
  • provides item insertion and removal at specific position of at worst O(log(n)) complexity
  • removal/insertion of items does not invalidate previously obtained iterators

Thank you in advance for any suggestions

Dalibor

(Edit) Answers:

The answer I selected describes a data structure that meet all these requirements. However, boost::multi_index, as suggested by Maxim Yegorushkin, provides features very close to those above.

(Edit) Some of the requirements were not correctly specified. They are modified according to correction(:original)

(Edit) I’ve found an implementation of the data structure described in the accepted answer. So far, it works as expected. It’s called counter tree

(Edit) Consider using the AVL-Array suggested by sp2danny

  • 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-24T12:52:10+00:00Added an answer on May 24, 2026 at 12:52 pm

    Let’s go through these…

    • average item lookup time is at worst of O(log(n)) complexity
    • removal/insertion of items does not invalidate previously obtained iterators
    • provides item insertion and removal of at worst O(log(n)) complexity

    That pretty much screams “tree”.

    • provides random access iterator ( along with iterator comparison <,> )
    • given an iterator, i can find out the ordinal position of the item pointed to in the container, at worst of O(log(n)) complexity
    • items are iterated over in the same order as they were added to the container

    I’m assuming that the index you’re providing your random-access iterator is by order of insertion, so [0] would be the oldest element in the container, [1] would be the next oldest, etc. This means that, on deletion, for the iterators to be valid, the iterator internally cannot store the index, since it could change without notice. So just using a map with the key being the insertion order isn’t going to work.

    Given that, each node of your tree needs to keep track of how many elements are in each subtree, in addition to its usual members. This will allow random-access with O(log(N)) time. I don’t know of a ready-to-go set of code, but subclassing std::rb_tree and std::rb_node would be my starting point.

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

Sidebar

Related Questions

I'm looking for suggestions for debugging... If you view this site in Firefox or
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.