Bucket a key hashes to before probing.
fnv_1a_hash returns a fixed-width int32 hash code; that width is
an algorithmic property of FNV-1a and is intentionally not
default_int. The code is widened to int64 and masked with
n_buckets - 1, which is valid because the bucket count is always a
power of two, and which discards the sign bits along with the high
bits.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(hash_map_t), | intent(in) | :: | this | |||
| character(len=*), | intent(in) | :: | key |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer(kind=int32), | private | :: | code |
function home_bucket(this, key) result(bucket) !! Bucket a key hashes to before probing. !! !! `fnv_1a_hash` returns a fixed-width `int32` hash code; that width is !! an algorithmic property of FNV-1a and is intentionally *not* !! `default_int`. The code is widened to `int64` and masked with !! `n_buckets - 1`, which is valid because the bucket count is always a !! power of two, and which discards the sign bits along with the high !! bits. class(hash_map_t), intent(in) :: this character(len=*), intent(in) :: key integer(default_int) :: bucket integer(int32) :: code code = fnv_1a_hash(key) bucket = int(iand(int(code, int64), int(this%n_buckets - 1, int64)), default_int) + 1 end function home_bucket