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 9169765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:55:26+00:00 2026-06-17T15:55:26+00:00

I need to implement a key-value data structure that search for a unique key

  • 0

I need to implement a key-value data structure that search for a unique key in O(lgn) or O(1) AND get max value in O(1). I am thinking about

boost::bimap< unordered_set_of<key> ,multiset_of<value> >

Note that there is no duplicated key in my key-value data sets. However, two keys may have the same value. Therefore I used multiset to store values.

I need to insert/remove/update key-value pair frequently

How does it sounds ?

  • 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-06-17T15:55:27+00:00Added an answer on June 17, 2026 at 3:55 pm

    It depends on what you want to do. So it is clear that you want to use it for some get-the-maximum-values-in-an-iteration construction.

    Question 1: Do you access the elements by their keys as well?

    • If yes, I can think of two solutions for you:

      1. use boost::bimap – easy, tested solution with logarithmic runtimes.

      2. create a custom container that contains an std::map (or for even faster by key access std::unordered_map) and a heap implementation (e.g. std::priority_queue<std::map<key, value>::iterator> + custom comparator) as well, keeps them in sync, etc. This is the hard way, but maybe faster. Most operations on both will be O(logn) (insert, get&pop max, get by key, remove) but the constant sometimes do matter. Although is you use std::unordered_map the access by key operation will be O(1).

        You may want to write tests for the new container as well and optimize it for the operation you use the most.

    • If no, you really just access using elements using the maximum value

      Question 2: do you insert/remove/update elements randomly or you first put in all elements in one round and then remove them one by one?

      • for random insert/remove/updates use std::priority_queue<std::pair<value, key>>

      • if you put in the elements first, and then remove them one-by-one, use and std::vector<std::pair<value, key>> and std::sort() it before the first remove operation. Do not actually remove the elements, just iterate on them.

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

Sidebar

Related Questions

I need to implement an efficient excel-like app. I'm looking for a data structure
I am trying to implement a Binary Search Tree data structure in C, and
I'm trying to implement a system where I'll have key-value structure pairs. They will
I have a private key and exponent, i need to implement RSA encryption of
What is the best Data Structure(DS)/Class I can use to implement Caesar's Cipher ?
I'm having a bit of a hard time. Essentially I need a data structure
I need a fast, reliable and memory-efficient key--value database for Linux. My keys are
I am implementing a data structure using Ruby and the BinData gem. I need
I need to implement caching in Asp.net web application My need to store data
We are storing our data in an internal key-value store in few different data

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.