What is the relationship between hash table and hash value?

Hash value

The hash value is an int number. The value range is from 2.1 billion to 2.1 billion, out of a total of 4.2 billion. We can see the hash value as an identification (signature code) of the object

In Object, there is a method called hashCode, which can obtain the hash value of the object.
The hash value of the hashCode in the Object is calculated based on the address value.

If you want to define the hash value calculation rules yourself, you can override the hashCode method.

Note: The hash value is an identifier of the object, but not a unique identifier. The hash value is allowed to be repeated.

The hash value can be merged using the remainder.

For example, if the hash value is divided into 3 types, the hash value can be the remainder of 3.

Hash value %3 -> 0 1 2

The result of the merge is a hash table

Hash table

The hash table is an array, and each element in the array is a linked list

In JDK8 and later, if the length of the linked list exceeds 8, then the linked list will automatically become a red-black tree.

Bucket: Each element of the array in the hash table is a bucket.

Hash conflict: If two objects appear in the same bucket, it means a hash conflict has occurred.

Load factor: It is a percentage, the default is 0.75.When the usage ratio of the bucket of the hash table exceeds the load factor, it will be re-hashing.

Re-hashing: Re-categorize and expand the hash table.

Guess you like

Origin blog.csdn.net/numbbe/article/details/109322036