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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:29:28+00:00 2026-05-20T07:29:28+00:00

Right now I have a vector std::vector<char> myVector(4) containing any combination of a set

  • 0

Right now I have a vector std::vector<char> myVector(4) containing any combination of a set of char lets say {@,#,O,*,%,$,!} may be more or less but not many more than that, might not always be 4 members either, but will be constant for any instance one instance.

now I stuck trying to create a data structure that can use an indefinite number of those combination as an index, to another vector.

in pseudo-code I am trying to accomplish:

SomeDataStructure['*']['#']['@']['O'] = someData

(someData is going to be a small class, but that shouldn’t matter)

This is an operation critical piece that needs to run quickly, and will be run very often.

some approached i’ve tried to reason with were:
a 4 dimensional array, but I can access those without numeric indices. Maybe some form of enumeration could solve this. Edit: would maps be a way to do this?


edit:

I resolved this using a map:

std::map<std::vector<char>, someData> myMap;
  • 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-20T07:29:28+00:00Added an answer on May 20, 2026 at 7:29 am

    Since the number of possible characters is limited to 8, you can use an enumeration instead. You’d therefore only need 3-bits to represent each “character”. You can pack several of these 3-bit “characters” into a short integer using bitfields. The resulting packed integer becomes the index into your vector<SomeData>.

    The space occupied by this vector would be space_of_SomeData * 2^(3*number_of_spaces). If, for example, number_of_spaces is 4, this results in 4096*space_of_SomeData. This might result in some wasted memory space, but lookups and insertions should be very fast.

    Here’s some sample code:

    #include <vector>
    
    enum CharSet
    {
        ampersand,
        pound,
        letterOh,
        percent,
        dollar,
        exclamation
    };
    
    struct CompositeIndex
    {
        union
        {
            struct // Bitfield
            {
                unsigned c0 : 3; // 3 bits
                unsigned c1 : 3; // 3 bits
                unsigned c2 : 3; // 3 bits
                unsigned c3 : 3; // 3 bits
            } chars;
    
            unsigned int index;
        };
    };
    
    unsigned int lookup(CharSet c0, CharSet c1, CharSet c2, CharSet c3)
    {
        CompositeIndex ci;
        ci.chars.c0 = c0;
        ci.chars.c1 = c1;
        ci.chars.c2 = c2;
        ci.chars.c3 = c3;
        return ci.index;
    }
    
    typedef int SomeClass;
    
    int main(int argc, char* argv[])
    {
        std::vector<SomeClass> vec(100);
        vec[lookup(ampersand, percent, dollar, pound)] = 42;
    }
    

    If you must absolutely work with char characters, you can easily create a 256-element lookup table that quickly converts ‘char’ characters into CharSet values.


    As already discussed by others, you can use a std::map<std::string, SomeData> or even (the possibly faster) std::map<char[4], SomeData, Comparitor>. If the approximate frequency distribution of different character sequences is known, try inserting the most frequent patterns first in the map. Depending on the internal implementation of the map, this may speed up lookups for the most frequent patterns (they are near the top of the underlying binary search tree).

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

Sidebar

Related Questions

Simple question; right now I have something like this: typedef void(*MyFunctionPointer)(int); typedef std::vector <
Right now I have an array of std::strings, and have a function in my
I have typedef std::queue<MyObject*> InputQueue; std::vector<InputQueue> inp_queue; Now what I want to do is
Right now I have a database (about 2-3 GB) in PostgreSQL, which serves as
Right now I have an SSIS package that runs every morning and gives me
Right now I have the following in my .vimrc : au BufWritePost *.c,*.cpp,*.h !ctags
Right now I have a few new applications being developed against an Oracle Database,
Right now I have a JSP page that allows to sort some items, when
Right now I have a table called Campaigns that has many Hits, if I
I'm working on a C# program, and right now I have one Form and

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.