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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:29:03+00:00 2026-05-12T23:29:03+00:00

I have a pair I know the value of the pair.first cannot be more

  • 0

I have a pair
I know the value of the pair.first cannot be more than 1000.
I also know that the pair.second , the string, is always 1 word. Never more than 1 word.
So, to construct the Hash value for the pair I am doing the following:

pair<int,string> p;
hash<char*> H;
hash_vale = H(p.second)*1000 + p.first;

I think this will give unique values as long as the hash value of strings is not too huge and that H(p.second) will give 1-1 mappings. Are these assumptions valid?

Thanks,

  • 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-12T23:29:03+00:00Added an answer on May 12, 2026 at 11:29 pm

    By definition, a hash can’t be one-to-one due to the pigeonhole principle. I.E., there are 2^32 possible hash values, but far more possible strings. So there must be two strings with the same hash value.

    Second of all, you are almost certainly causing overflow by multiplying your hash value by 1000, since a hash should use all 32 bits. You are much better off hashing the int and then mixing the hashes. Boost has a hash_combine function: a + 0x9e3779b9 + (b << 6) + (b >> 2);

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

Sidebar

Related Questions

I have a pair of shell programs that talk over a named pipe. The
I have a string of key->value pairs in the following colon-separated format: MIME-Version: 1.0
The question I have is more of mathematics! I have some pair of values
Say I have an entity that will have many attributes, some I know about
I have a function that takes a parameter(key) to retrieve it's value from a
I have a WCF application, written in VB.NET that takes a generic Dictionary(Of String,
I have a pair of static fields with a complicated one-time initialization. I want
If I have a pair of dates, and I want to generate a list
I have a public/private key pair set up so I can ssh to a
I have a situation where I want to map a pair of objects to

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.