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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:13:57+00:00 2026-06-12T01:13:57+00:00

What ways do you know to evaluate the efficiency of a hash function besides

  • 0

What ways do you know to evaluate the efficiency of a hash function besides generating a large set of values and see the distribution of values?
By efficiency I mean that the keys generated by your hash function distribute evenly. Is there a way to prove this without actually testing for actual values?

  • 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-12T01:13:58+00:00Added an answer on June 12, 2026 at 1:13 am

    A hash function is only even in the context of the data being hashed

    Consider two data sets:

    Set 1

    1, 3, 6, 2, 7, 9, 5, 8, 4
    

    Set 2

    65355, 96424664, 86463624, 133, 643564,  24232, 88677, 865747, 2224
    

    A good hashing function for one set (ie mod 10 for set 1) gives no collisions and could be seen as the perfect hash for that data set

    However apply it to the second set and there are collisions everywhere

    Hash = (x * 37) mod 256
    

    Is much better for the second set but may not suit the first set quite so well… Especially when partitioning the hash for eg a small number of buckets.

    What you can do is evaluate a hash against random data that you “expect” your function to have to handle… But that is making assumptions…

    Premature optimisation is looking for the perfect hash function before you have enough real data to base your assessment on.

    You should get enough data well before the cost of rehashing becomes prohibitive to change your hash function

    Update

    Lets suppose we are looking for a hash function that generates an 8 bit hash of the input data. Lets further suppose that the hash function is supposed to take byte-streams of varying length.

    If we assume that the bytes in the byte-streams are uniformly distributed, we can make some assessment of different hash functions.

    int hash = 0;
    for (byte b in datastream) hash = hash xor b;
    

    This function will produce uniformly distributed hash values for the specified data set, and would therefore be a good hash function in this context. If you don’t see why this is, then you might have other problems.

    int hash = 37;
    for (byte b in datastream hash = (31 * hash + b) mod 256;
    

    This function will produce uniformly distributed hash values for the specified data set, and would therefore be a good hash function in this context.

    Now lets change the data set from being variable length strings of random numbers in the range 0 to 255 to being variable length strings comprising English sentences encoded as US-ASCII.

    The XOR is then a poor hash because the input data never has the 8th bit set and as a result only generates hashes in the range 0-127, also there is a higher likelyhood of some “hot” values because of the letter frequency in english words and the cancelling affect of the XOR.

    The pair of primes remains reasonably good as a hash function because it uses the full output range and the prime initial offset coupled with a different prime multiplier tends to spread the values out. But it is still weak for collisions due to how English language is structured… Something that only testing with real data can show.

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

Sidebar

Related Questions

I know that technically all three ways below are valid, but is there any
There are two ways that I know that you can fetch results in Rails
There are at least two ways that I know of to write a Symbian
Does anyone know ways of partially or fully automating driver test installation? I am
Want to know ways to store OBJECTS of a Class in some persistent storage.
I know two ways to check parameters of the method and throw exceptions when
I know of three ways to get a full language name of a CultureInfo
I know there are ways to get the number of digits after a decimal
I know plenty of ways to calculate the offset or position of an element
I know there are two ways, [self.navigationController pushViewController:siteViewController animated:YES]; [self presentModalViewController:anotherViewController animated:YES]; However, those

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.