hash_table_hash Function

private function hash_table_hash(me, key) result(hash_value)

DJB hash algorithm for a string.

See also

  • J. Shahbazian, Fortran hashing algorithm, July 6, 2013 Fortran Dev

Type Bound

json_hash_table

Arguments

Type IntentOptional Attributes Name
class(json_hash_table), intent(in) :: me
character(kind=CK, len=*), intent(in) :: key

Return Value integer(kind=IK)


Called by

proc~~hash_table_hash~~CalledByGraph proc~hash_table_hash json_hash_table%hash_table_hash proc~hash_table_get json_hash_table%hash_table_get proc~hash_table_get->proc~hash_table_hash proc~hash_table_insert json_hash_table%hash_table_insert proc~hash_table_insert->proc~hash_table_hash proc~hash_table_resize json_hash_table%hash_table_resize proc~hash_table_insert->proc~hash_table_resize proc~hash_table_create_from_value json_hash_table%hash_table_create_from_value proc~hash_table_create_from_value->proc~hash_table_insert proc~hash_table_resize->proc~hash_table_insert proc~json_file_get_object json_file%json_file_get_object proc~json_file_get_object->proc~hash_table_get none~get json_file%get none~get->proc~json_file_get_object proc~json_file_get_alloc_string_vec json_file%json_file_get_alloc_string_vec none~get->proc~json_file_get_alloc_string_vec proc~json_file_get_integer json_file%json_file_get_integer none~get->proc~json_file_get_integer proc~json_file_get_integer_vec json_file%json_file_get_integer_vec none~get->proc~json_file_get_integer_vec proc~json_file_get_logical json_file%json_file_get_logical none~get->proc~json_file_get_logical proc~json_file_get_logical_vec json_file%json_file_get_logical_vec none~get->proc~json_file_get_logical_vec proc~json_file_get_real json_file%json_file_get_real none~get->proc~json_file_get_real proc~json_file_get_real32 json_file%json_file_get_real32 none~get->proc~json_file_get_real32 proc~json_file_get_real32_vec json_file%json_file_get_real32_vec none~get->proc~json_file_get_real32_vec proc~json_file_get_real_vec json_file%json_file_get_real_vec none~get->proc~json_file_get_real_vec proc~json_file_get_string json_file%json_file_get_string none~get->proc~json_file_get_string proc~json_file_get_string_vec json_file%json_file_get_string_vec none~get->proc~json_file_get_string_vec proc~wrap_json_file_get_alloc_string_vec json_file%wrap_json_file_get_alloc_string_vec none~get->proc~wrap_json_file_get_alloc_string_vec proc~wrap_json_file_get_integer json_file%wrap_json_file_get_integer none~get->proc~wrap_json_file_get_integer proc~wrap_json_file_get_integer_vec json_file%wrap_json_file_get_integer_vec none~get->proc~wrap_json_file_get_integer_vec proc~wrap_json_file_get_logical json_file%wrap_json_file_get_logical none~get->proc~wrap_json_file_get_logical proc~wrap_json_file_get_logical_vec json_file%wrap_json_file_get_logical_vec none~get->proc~wrap_json_file_get_logical_vec proc~wrap_json_file_get_object json_file%wrap_json_file_get_object none~get->proc~wrap_json_file_get_object proc~wrap_json_file_get_real json_file%wrap_json_file_get_real none~get->proc~wrap_json_file_get_real proc~wrap_json_file_get_real32 json_file%wrap_json_file_get_real32 none~get->proc~wrap_json_file_get_real32 proc~wrap_json_file_get_real32_vec json_file%wrap_json_file_get_real32_vec none~get->proc~wrap_json_file_get_real32_vec proc~wrap_json_file_get_real_vec json_file%wrap_json_file_get_real_vec none~get->proc~wrap_json_file_get_real_vec proc~wrap_json_file_get_string json_file%wrap_json_file_get_string none~get->proc~wrap_json_file_get_string proc~wrap_json_file_get_string_vec json_file%wrap_json_file_get_string_vec none~get->proc~wrap_json_file_get_string_vec proc~initialize_hash json_file%initialize_hash proc~initialize_hash->proc~hash_table_create_from_value proc~initialize_hash->none~get proc~json_file_get_alloc_string_vec->none~get proc~json_file_get_integer->none~get proc~json_file_get_integer_vec->none~get proc~json_file_get_logical->none~get proc~json_file_get_logical_vec->none~get proc~json_file_get_real->none~get proc~json_file_get_real32->none~get proc~json_file_get_real32_vec->none~get proc~json_file_get_real_vec->none~get proc~json_file_get_string->none~get proc~json_file_get_string_vec->none~get proc~wrap_json_file_get_alloc_string_vec->none~get proc~wrap_json_file_get_integer->none~get proc~wrap_json_file_get_integer_vec->none~get proc~wrap_json_file_get_logical->none~get proc~wrap_json_file_get_logical_vec->none~get proc~wrap_json_file_get_object->none~get proc~wrap_json_file_get_real->none~get proc~wrap_json_file_get_real32->none~get proc~wrap_json_file_get_real32_vec->none~get proc~wrap_json_file_get_real_vec->none~get proc~wrap_json_file_get_string->none~get proc~wrap_json_file_get_string_vec->none~get

Source Code

    function hash_table_hash(me, key) result(hash_value)

    class(json_hash_table), intent(in) :: me
    character(kind=CK,len=*), intent(in) :: key
    integer(kind=IK) :: hash_value

    integer(IK) :: hash
    integer(IK) :: i !! counter

    hash = 5381_IK
    do i = 1, len(key)
        hash = ishft(hash, 5_IK) + hash + iachar(key(i:i), kind=IK)  ! hash * 33 + c
    end do

    ! Map to bucket index
    hash_value = int(modulo(hash, int(me%capacity, IK)), IK)

    end function hash_table_hash