Add a node pointer to the hash table.
If a node with the same key is already in the hash table, it is removed and the new one will replace it.
If the table is homogeneous the key/content types are verified against the typeguard members: if those typeguards have not been initialized by an invocation of initialize they are initialized by the types here passed.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(hash_table), | intent(inout) | :: | self | The hash table. |
||
class(*), | intent(in) | :: | key | The key. |
||
class(*), | intent(in), | pointer | :: | content | The content. |
subroutine add_pointer(self, key, content)
!---------------------------------------------------------------------------------------------------------------------------------
!< Add a node pointer to the hash table.
!<
!< @note If a node with the same key is already in the hash table, it is removed and the new one will replace it.
!<
!< @note If the table is **homogeneous** the key/content types are verified against the typeguard members: if those typeguards
!< have not been initialized by an invocation of [[hash_table:initialize]] they are initialized by the types here passed.
!---------------------------------------------------------------------------------------------------------------------------------
class(hash_table), intent(inout) :: self !< The hash table.
class(*), intent(in) :: key !< The key.
class(*), pointer, intent(in) :: content !< The content.
integer(I4P) :: b !< Bucket index.
integer(I4P) :: i !< Image index.
integer(I4P) :: bucket_length !< Length (nodes number) of the bucket where the node is placed.
!---------------------------------------------------------------------------------------------------------------------------------
!---------------------------------------------------------------------------------------------------------------------------------
if (.not.is_key_allowed(key)) error stop 'error: key type not supported'
if (.not.self%is_initialized_) call self%initialize ! initialize the table with default options
call self%check_type(key=key, content=content)
call self%get_bucket_image_indexes(key=key, bucket=b, image=i)
if (b>0.and.i==self%me) then
bucket_length = len(self%bucket(b))
call self%bucket(b)%add_pointer(key=key, content=content)
self%nodes_number_ = self%nodes_number_ + (len(self%bucket(b)) - bucket_length)
self%ids_(1:2, b) = self%bucket(b)%ids()
endif
!---------------------------------------------------------------------------------------------------------------------------------
endsubroutine add_pointer