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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:08:44+00:00 2026-06-11T19:08:44+00:00

Let’s say I’m using a map that uses three strings as a key. Here’s

  • 0

Let’s say I’m using a map that uses three strings as a key. Here’s a quick example struct:

struct ExampleMapKey
{
 std::string key0;
 std::string key1;
 std::string key2;

 bool operator<(const ExampleMapKey& other) const
 {
  if (key0 < other.key0) return true;
  else if (key0 > other.key0) return false;

  if (key1 < other.key1) return true;
  else if (key1 > other.key1) return false;

  return key2 < other.key2;
 }
}

Now, this works fine until I decide I want to use lower_bound and upper_bound. If I want to find the range of values formed by any key0, any key1 starting with “ab”, and any key2 starting with “cd”, using those 2 functions with ExampleMapKey("", "ab", "cd") and ExampleMapKey("", "ac", "ce") respectively will have me iterating through keys that don’t fulfill my requirements. Or will I miss keys that do? Either way, it’s wrong.

It seems what I need is a data structure that explicitly indexes by each key, and will also allow me to perform potentially complicated lower_bound and upper_bound iterations. Is there such a thing? I’m not necessarily using strings, nor am I limited to only 3 keys, so it needs to be STL-style or similarly generic.

  • 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-11T19:08:45+00:00Added an answer on June 11, 2026 at 7:08 pm
    1. Boost Multi-index Containers Library can be of help.

      Update: After rereading your question, I think you may have to do what is taught in db classes; you would have to use one of the indices to create a temporary result, and prune that result, based on your second constraint (alternatively, you can run each constraint on each index, joining the results). Boost Multi-index Containers will only allow lookup on one index at a time AFAIK.

    2. For the particular type of query that you asked, you might be able to come up with a very specialized data structure that can help, by adding indices on partitions of indices. That is for example, you take the 2nd index, split it in half, rewrite a 3rd index for the first half, and for the 2nd half. Then you split each half and repeat. This way, you can select a section of the 2nd index, and then subsequently select a part of the 3rd index that is within (approximately) that part of the 2nd index. But I don’t know of any library that does this.

    3. Another approach might be some sort of multi-dimensional data structure, though I am not familiar with using such a structure with non-numeric keys. For example, imagine your keys were integers, you could use a 3D kd-tree or other spatial index, and query for a cubic range. For example: (using libssrckdtree, seems it might work with strings too):

    Codes for (3):

    #include <ssrc/spatial/kd_tree.h>
    
    #include <cstdlib>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <cassert>
    
    #include <string>
    
    typedef std::array<std::string, 3> Point;
    
    typedef ssrc::spatial::kd_tree<Point, Point> Tree;
    
    int main()
    {
      Tree tree;
    
      Point point = {{"any1","aa1","cc1"}};
      tree[point] = point;
    
      point = {{"any2","ab1","cc1"}};
      tree[point] = point;
    
      point = {{"any3","ab1","cd1"}};
      tree[point] = point;
      point = {{"any4","ab1","cd2"}};
      tree[point] = point;
      point = {{"any5","ab1","cd3"}};
      tree[point] = point;
    
    
      point = {{"any22","ac1","cc1"}};
      tree[point] = point;
    
      point = {{"any33","ac1","cd1"}};
      tree[point] = point;
      point = {{"any44","ac1","cd2"}};
      tree[point] = point;
      point = {{"any55","ac1","cd3"}};
      tree[point] = point;
    
    
      point = {{"any6","aa1","cd2"}};
      tree[point] = point;
      point = {{"any7","aa1","cd3"}};
      tree[point] = point;
    
      Point lower{ { "any0", "ab", "cd" } }, upper{ { "any9", "ac", "cd2" } };
    
      for(Tree::const_iterator it = tree.begin(lower, upper), end = tree.end();
          it != end; ++it)
      {
        Point point = it->first;
        Point value = it->second;
        std::cout << point[0] << ", " << point[1] << ", " << point[2] << std::endl;
      }
    
    
      return 0;
    }
    

    Output:

    any3, ab1, cd1
    any4, ab1, cd2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let me explain best with an example. Say you have node class that can
Let me try to explain by example. Say website is hosted at example.com (NOT
Let's say that I have a SQLite database that I create in a separate
Let's say I have two text files that I need to extract data out
Let say I want to create an iOS app that download music files from
Let's say I have multiple requirements for a password. The first is that the
Let's say that I have a date in R and it's formatted as follows.
Let say I've this URL: http://example.com/image-title/987654/ I want to insert download to the part
Let's say you have a method that expects a numerical value as an argument.
Let's say I have a bunch of links that share a click event: <a

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.