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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:07:42+00:00 2026-05-31T02:07:42+00:00

I have an array of fingerprints in hash buckets. I would like to insert

  • 0

I have an array of fingerprints in hash buckets. I would like to insert into the bucket and search on it with out going from entry 0 to entry n.

What i want to do is, when i add entries into the buckets i use the fingerprint as an input to calculate a hash which i can use to determine which bucket to add into. This was not difficult, but when i try to hash the fingerprint using the same algorithm to identify into which slot in the bucket to add the fingerprint i see that it makes a lot of collisions.

Here is the code i used to hash the fingerprints into the buckets. I tried to use the same code with more characters but it still gives me higher collision.

he.fingerprint is 33 characters wide

number of buckets is 1024

number of entries per bucket is 2048

    char hph[32];
int bk,en;
unsigned long h = 0, g,i=0;
int j=0;
strncpy(hph,(const char*)(he).fing_print,32);

while ( j<32 ) 
{
    h  =h + hph[j]++;
     g = h & 0xFFf00000;
    h ^= g >> 24;
    h &= ~g;
    j++;
}
bk=h%buckets;
en=h%entries_per_bk;
  • 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-31T02:07:43+00:00Added an answer on May 31, 2026 at 2:07 am

    There are some superfluous things in your hashing function.

    char hph[32];
    int bk,en;
    unsigned long h = 0, g,i=0;
    int j=0;
    strncpy(hph,(const char*)(he).fing_print,32);
    
    while ( j<32 ) 
    {
        h = h + hph[j]++;
    

    This is, effectively, h += hph[j];. The character at index j is incremented, but since it is never used again, that doesn’t influence the hash at all. Perhaps you mean to preincrement it? But that wouldn’t change much.

        g = h & 0xFFf00000;
    

    The fingerprint (or at least the part of it you use) is 32 characters long at most. Each of those characters is less than 256, so the total sum is less than 32*256 = 8192 = 0x2000, hence h & 0xFFF00000 is 0. Thus the following two lines do exactly nothing to h.

        h ^= g >> 24;
        h &= ~g;
        j++;
    }
    bk=h%buckets;
    en=h%entries_per_bk;
    

    So effectively, your hash is the sum of the first 32 characters of the fingerprint. That doesn’t spread your hashes well, similar strings generate similar hashes. You would obtain a better hash by multiplying the hash so far by a largish prime,

    h = 0;
    for(j = 0; j < 32; ++j)
        h = prime*h + hph[j];
    

    so that small differences at any index (except the last, but you could multiply once more to spread those too) can create large differences of the hash.

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

Sidebar

Related Questions

I have array like this: $path = array ( [0] => site\projects\terrace_and_balcony\mexico.jpg [1] =>
I have array result like this: Array ( [0] => stdClass Object ( [id_global_info]
An array is defined of assumed elements like I have array like String[] strArray
I have array like below, Array ( [14289] => Array ( [0] => Karthikeyan
I have array that element is hash a = [{:history_date=>15/07/10}, {:open_price=>7.90}] I want to
I have array data as shown below, I want to store 'sale' value into
so I have array like ParamsArray {a,b,a,a,...b} (so i have 2 kinds of parameters
I have array object in jquery. array=[]; array{Id:user.Id,Date:user.Date}; Now am going to pass this
i have array like below which is sorted by array_count_values function, Array ( [Session
I have array of words and I want to get a hash, where keys

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.