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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:58:07+00:00 2026-06-05T03:58:07+00:00

I need a c++ memory dictionary container, that get a key, and return a

  • 0

I need a c++ memory dictionary container, that get a key, and return a value any way.
That is, if the key doesn’t exist in the ‘keys list’, it will find the most similar key, and give the value.

Any suggestions?

EDIT:

Thank for the comments.

More details:
For Simplicity, let’s start with numeric key. If the key is within 200 distance from the key, get it.

  • 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-05T03:58:09+00:00Added an answer on June 5, 2026 at 3:58 am

    You need to use something called locality-sensitive hashing, and you’ll need to write a little bit of code on top of it (just a tiny bit, I promise. One extra word).

    First, you need to use std::map and not std::unordered_map or any other hash table – it has to be a tree or other ordered data structure.

    Your key would be the locality-sensitive hash, which has the behavior of hashing similar inputs to close outputs. So the hash of AAA and the hash of AAB would be closer together than the hash of AAA and CCC. The value would be whatever you want it to be.

    To retrieve the “nearest match”, you just need to use the std::map::lower_bound (or std::map::upper_bound) to get the nearest value to any given input from the map.

    So your code would look like this

    std::map<unsigned int, some_struct> mymap;
    for(;;;)
    {
       mymap[locale_sensitive_hash(some_struct(some random value))] = some_struct(some random value)
    }
    
    //Now find the object we have that is nearest to some_struct(AAA)
    unsigned int this_hash = locale_sensitive_hash(some_struct(AAA));
    some_struct nearest_object = mymap.lower_bound(this_hash);
    

    Done and done.

    Some Notes:

    This is assuming a non-numberic key. Numbers are already “locale-sensitive hashes” of themselves, i.e. if H(n) is n, the difference between H(n) and H(n') is directly proportional to the difference between inputs n and n'. In that case, lower_bound is the only thing you need, and you don’t need the extra hashing step.

    You can extend this method very easily to do things like specify a maximum distance between objects. This will depend on the locale sensitive hash you’re using and how it signifies the distance between two hashes for two given inputs, but generally just compare H(n) and H(n') before returning the nearest_struct (with nearest_struct being n').

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

Sidebar

Related Questions

I need something like a temporary in-memory key-value store. I know there are solutions
That's pretty much it. I need to allocate memory and pass it to a
I need a cache that responds to memory pressure like the one build-into ASP.NET.
If I have a list(or array, dictionary....) in python that could exceed the available
We need to keep some in-memory data structure to keep english word dictionary in
I have a Dictionary containing 10 keys, each with a list containing up to
I need a memory efficient int-int dict in Python that would support the following
I have a strong use case for pre-allocating all the memory I need upfront
I am writing a script, where I need to set memory limit to something
I need to pass a memory stream to the WCF server , how do

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.