home_bucket Function

private 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.

Arguments

Type IntentOptional Attributes Name
class(hash_map_t), intent(in) :: this
character(len=*), intent(in) :: key

Return Value integer(kind=default_int)


Calls

proc~~home_bucket~~CallsGraph proc~home_bucket home_bucket interface~fnv_1a_hash fnv_1a_hash proc~home_bucket->interface~fnv_1a_hash

Called by

proc~~home_bucket~~CalledByGraph proc~home_bucket home_bucket proc~find_entry find_entry proc~find_entry->proc~home_bucket proc~probe_free probe_free proc~probe_free->proc~home_bucket proc~hash_map_get hash_map_t%hash_map_get proc~hash_map_get->proc~find_entry proc~hash_map_has_key hash_map_t%hash_map_has_key proc~hash_map_has_key->proc~find_entry proc~hash_map_insert hash_map_t%hash_map_insert proc~hash_map_insert->proc~find_entry proc~hash_map_insert->proc~probe_free proc~grow_buckets grow_buckets proc~hash_map_insert->proc~grow_buckets proc~hash_map_remove hash_map_t%hash_map_remove proc~hash_map_remove->proc~find_entry proc~rebuild_buckets rebuild_buckets proc~hash_map_remove->proc~rebuild_buckets proc~rebuild_buckets->proc~probe_free proc~grow_buckets->proc~rebuild_buckets

Variables

Type Visibility Attributes Name Initial
integer(kind=int32), private :: code

Source 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