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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:52:27+00:00 2026-06-07T05:52:27+00:00

In a program I am writing, I would like to develop a hashing algorithm

  • 0

In a program I am writing, I would like to develop a hashing algorithm which can map either a RGB color, string, or both to a unique and relatively small index.

The goal here is to reduce as many collisions as possible, with the guarantee that no two colors being passed through the algorithm will be similar (perceptually; e.g. red, blue, orange).

With my limited knowledge, the array seems the optimal choice for a direct-access data structure, but I do not want to create an incredibly large array. Given that I have to allocate memory in C++ for the array, I am having trouble developing such an algorithm.

Any tips are appreciated!

  • 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-07T05:52:28+00:00Added an answer on June 7, 2026 at 5:52 am

    You could use std::map to access the Subject by its color or label. No need to develop own hashing algorithms for that, all you have to do is to create comparison operator, which should be easy on this case, assuming you use 32bit integer for the RGB color, and a std::string for the label.

    Edit: Actually you dont need to make anything else than the map (no custom operators), as simple as:

    typedef map<int, MyClass*, greater<int> > IntClassMap;
    typedef map<std::string, MyClass*, greater<std::string> > StrClassMap;
    IntClassMap inttable;
    StrClassMap strtable;
    
    void adding_the_data(){
        inttable[0x11223344] = myclasspointer1;
        inttable[0x11223345] = myclasspointer2;
        inttable[0x11223346] = myclasspointer3;
    
        strtable["test string1"] = myclasspointer1;
        strtable["test string2"] = myclasspointer2;
        strtable["test string3"] = myclasspointer3;
    }
    
    void accessing_example(){
        strtable["test string1"]->something;
    }
    

    std::map is very fast, I don’t think you need (or find) any faster solution than that.

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

Sidebar

Related Questions

I'm currently writing a program in which I would like to access the variable
For the python program I am writing I would like to give the opportunity
I'm currently writing a program in Python, and I would like to determine the
I'm writing a blackjack program and would like to be able to write the
I'm writing a physics simulating program, and found after() useful. I once would like
I am writing a program for WP7 in C# where I would like to
I am currently trying to make a Writing program. I would like the functionality
I am writing a program in C#.NET I would like to gather the total
I'm currently writing a program in Java that I would like to use to
I would like to distribute a program I'm halfway done writing but I'm having

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.