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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:33:31+00:00 2026-05-31T18:33:31+00:00

I have to create a hash function based on 3 shorts. What is the

  • 0

I have to create a hash function based on 3 shorts. What is the best way to go about doing this?

Edit
I have an object called Point. It is composed of three shorts (x, y, z). In order to use this object within a QSet, I have to fill in the body of the following function

uint qHash(const Point &point) {
    // return something here that is a unique combination of x, y, z so that
    // it is very quick to calculate and has minimal (if any) hash collisions
}
  • 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-31T18:33:33+00:00Added an answer on May 31, 2026 at 6:33 pm

    That depends a great deal on what you need from the hash function.

    Is speed critical?

    Is a near-perfect hash distribution critical?

    How large must your hash key be? 32-bits? 64-bits? Larger?

    Without knowledge of any other specifics, you may want to consider something along these lines:

    uint hash = (31 * 31 * 31 * (uint)short1) ^ (31 * 31 * (uint)short2) ^ (31 * short3);
    

    That will be fast and should have a reasonable distribution of bits, even if the input values for the shorts are not well distributed

    UPDATE:

    Modified code sample to type uint. My variant should work well if input is in the range 0 to 512.

    If you’re interested in understanding why I multiply each input by a power of 31, see

    Why does Java's hashCode() in String use 31 as a multiplier?

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

Sidebar

Related Questions

I've read this book section about git branches. I have create a branch called
I have some questions about Perl's map function. Specifically: How does %hash = map
I have create name range on sheet A so I need to use this
This is what I currently have: CREATE OR REPLACE TRIGGER MYTRIGGER AFTER INSERT ON
I have to create a dialog based application, instead of old CFormView type of
I have to create a lookup table for C function names (as keys) to
I have the following code which works great:- $('.ajax a').click(function() { getpageajax(this.href); return false;
Say I have some known values, against which I want to create a hash
I have an class definition with a __hash__ function that uses the object properties
I have a template class that I have made called hash . My template

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.