hash_map_insert Subroutine

private subroutine hash_map_insert(this, key, value)

Insert key with value, or overwrite the value of an existing key.

A key that is not present is appended at the end of the iteration order. A key that is already present keeps its position in the iteration order and only its value changes.

Type Bound

hash_map_t

Arguments

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

Stored verbatim; trailing blanks are part of the key.

integer(kind=int64), intent(in) :: value

Calls

proc~~hash_map_insert~~CallsGraph proc~hash_map_insert hash_map_t%hash_map_insert proc~find_entry find_entry proc~hash_map_insert->proc~find_entry proc~grow_buckets grow_buckets proc~hash_map_insert->proc~grow_buckets proc~hash_map_init hash_map_t%hash_map_init proc~hash_map_insert->proc~hash_map_init proc~probe_free probe_free proc~hash_map_insert->proc~probe_free proc~reserve_entries reserve_entries proc~hash_map_insert->proc~reserve_entries proc~reserve_pool reserve_pool proc~hash_map_insert->proc~reserve_pool proc~home_bucket home_bucket proc~find_entry->proc~home_bucket proc~key_matches key_matches proc~find_entry->proc~key_matches proc~rebuild_buckets rebuild_buckets proc~grow_buckets->proc~rebuild_buckets proc~hash_map_destroy hash_map_t%hash_map_destroy proc~hash_map_init->proc~hash_map_destroy proc~probe_free->proc~home_bucket interface~fnv_1a_hash fnv_1a_hash proc~home_bucket->interface~fnv_1a_hash proc~rebuild_buckets->proc~probe_free proc~entry_key entry_key proc~rebuild_buckets->proc~entry_key

Variables

Type Visibility Attributes Name Initial
integer(kind=default_int), private :: entry
integer(kind=default_int), private :: i
integer(kind=default_int), private :: klen

Source Code

   subroutine hash_map_insert(this, key, value)
      !! Insert `key` with `value`, or overwrite the value of an existing key.
      !!
      !! A key that is not present is appended at the end of the iteration
      !! order. A key that is already present keeps its position in the
      !! iteration order and only its value changes.
      class(hash_map_t), intent(inout) :: this
      character(len=*), intent(in) :: key
         !! Stored verbatim; trailing blanks are part of the key.
      integer(int64), intent(in) :: value

      integer(default_int) :: entry, klen, i

      if (this%n_buckets == 0) call this%init()

      entry = find_entry(this, key)
      if (entry > 0) then
         this%entry_value(entry) = value
         return
      end if

      if ((this%n_entries + 1)*LOAD_DEN > this%n_buckets*LOAD_NUM) then
         call grow_buckets(this)
      end if

      klen = int(len(key), default_int)
      call reserve_entries(this, this%n_entries + 1)
      call reserve_pool(this, this%pool_used + klen)

      this%n_entries = this%n_entries + 1
      this%key_start(this%n_entries) = this%pool_used + 1
      this%key_size(this%n_entries) = klen
      this%entry_value(this%n_entries) = value
      do i = 1, klen
         this%key_pool(this%pool_used + i) = key(i:i)
      end do
      this%pool_used = this%pool_used + klen

      this%buckets(probe_free(this, key)) = this%n_entries
   end subroutine hash_map_insert