Meaning of hash buckets

In the documentation of “as_hashmap_init”, 'buckets" refer to “The number of hash buckets to allocate”. My understanding is that number of ‘buckets’ refer to the number of key-value pairs I want in the hash-map. Just wanted to confirm if my understanding is correct.

Actually, in my program I used lesser number of buckets in as_hashmap_init as compared to the number of times I used ‘as_hashmap_set’ and my program still runs fine. That’s why the confusion.

Thanks.

buckets is the number of slots indexed by the each entry’s hashcode. buckets is the not the number of key-value pairs.

as_hashmap allocates buckets once during as_hashmap_init() and bucket size remains fixed. When a new entry collides with an existing bucket, the entry is added to that bucket’s collision list. The collision list does not have a capacity and grows indefinitely.

as_hashmap is useful getting maps in and out of the server, but I don’t recommend using it beyond that.

Can you elaborate what you mean by ‘number of slots indexed by each entry’s hashcode’? By “Each entry’s hashcode” you mean the hash of map’s key right? But what are the slots? Partitions(but I’m not able to make any sense)?

I want to understand this so that I can use as_hashmap properly in my code.

Thanks


So can I say that more the number of buckets, faster will be the the operations?

Yes, hash of map’s key. The slots are the buckets. Each bucket contains a collision list.

1 Like

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.