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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:48:27+00:00 2026-05-17T17:48:27+00:00

I am writing a generic hash map in C++ which uses chaining to deal

  • 0

I am writing a generic hash map in C++ which uses chaining to deal with collisions.

Say if I have a hash map with 11 buckets, and I insert 8 items. The hash function will distribute it as follows:

bucket[0] = empty
bucket[1] = 2 elements
bucket[2] = empty
bucket[3] = 1 element
bucket[4] = 1 element
bucket[5] = 3 elements
bucket[6] = empty
bucket[7] = 1 element
bucket[8] = empty
bucket[9] = empty
bucket[10] = empty

Calculating the spread over the buckets is 5/8 = 0.625.
But how do I calculate the spread taking the depth of the buckets into account?

I want to know this because:
Say if I added 20 elements, and every bucket has 1 element and the last bucket has 11 elements.

then the spread would be 1 if i calculate it the easy way, but this is obviously not correct! (the table resizes to avoid this of course, but I want to be able to show the spread) I want to use this information to be able to tune hash functions.

Thanks in advance!

  • 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-17T17:48:28+00:00Added an answer on May 17, 2026 at 5:48 pm

    If you’re only using this to tune the hash functions themselves, you could compute a genuine measure of statistical dispersion, such as the Gini coefficient. On the other hand, if you’re trying to make this a feature of the hash-map itself, I would recommend against it – computing a complicated benchmark as part of the ‘is resize necessary’ logic has its own performance costs; something naïve is probably better.

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

Sidebar

Related Questions

I am writing the a generic function for my website using jquery which would
I'm writing a Haskell library which uses Data.Vector 's. I successfully wrote library function,
I'm writing a Generic for LINQ to SQL CUD. I 'Generic Insert Public Shared
I am writing a generic function that will be reused in multiple places in
I'm writing a semi-generic form plugin using jQuery in order to speed up the
I'm having some trouble with a generic method I'm writing. It has the following
I was thinking about writing generic functions for basic Math operations such as Min,
I was writing a generic class to read RSS feed from various source and
I'm writing a generic class where I need to use Interlocked. T test1, test2;
I'm writing a Generic class as follows. public class Foo<T> : where T :

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.