What is buckets or bucket?

I look at the picture about the hash table and see this word: buckets. Tell us what it is and for what purpose?

enter a description of the image here

Author: default locale, 2019-06-03

1 answers

Bucket (English bucket - bucket) is a set of hash table elements with matching / close hash function values.

The hash function can take a large range of values. Due to technical limitations (for example, if you need to save memory), the internal hash table array may contain fewer elements. Then elements with similar hash values will fall into the same cell.

The situation when two elements added to the hash table match the hash value is called a collision. In this case, both elements fall into the same cell (bucket / bucket) of the hash table. A large number of collisions causes the hash table to slow down.

See Hash table/Wikipedia Conflict Resolution

Picture

The picture illustrates a specific collision resolution algorithm - open addressing.

All elements of the hash table are distributed in 255 cells (the number is given for example, the number of cells can be arbitrary). "John Smith "and" Sandra Dee " have the same hash. Both values are placed side by side in the hash table. When using this collision resolution algorithm, this affects the next "Ted Baker" item, which moves to the next bucket in order despite having a unique hash.

It should be noted that the HashMap class in Java currently uses a different type of collision resolution, in which each bucket is a search tree, although this is an implementation detail, not a specified in JavaDoc. The number of buckets in HashMap can be set using capacity and grows as needed.

 8
Author: default locale, 2019-06-03 11:03:55