Common code used internally by dict_set() and change_capacity().
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(dict_i4tuple_callstat_type), | intent(inout) | :: | dict | |||
integer(kind=int_4), | intent(in), | dimension(2) | :: | key | ||
type(call_stat_type), | intent(in), | POINTER | :: | value | ||
integer(kind=int_8), | intent(in) | :: | hash |
RECURSIVE SUBROUTINE set_hashed_i4tuple_callstat (dict, key, value, hash) !! Common code used internally by dict_set() and change_capacity(). TYPE(dict_i4tuple_callstat_type), intent(inout) :: dict INTEGER(kind=int_4), dimension(2), intent(in) :: key TYPE(call_stat_type), POINTER, intent(in) :: value INTEGER(KIND=int_8), intent(in) :: hash TYPE(private_item_type_i4tuple_callstat), POINTER :: item, new_item INTEGER(KIND=int_8) :: idx idx = MOD(hash, INT(size(dict%buckets), KIND=int_8)) + 1 ! if already in dict just update its value item => dict%buckets(idx)%p do while (ASSOCIATED(item)) IF (item%hash == hash) THEN IF (ALL(item%key==key)) THEN item%value =>value return END IF END IF item => item%next end do ! check load-factor IF (4*dict%size > 3*size(dict%buckets)) THEN ! load-factor > 75% call change_capacity_i4tuple_callstat (dict, 2*size(dict%buckets)) !double capacity idx = MOD(hash, INT(size(dict%buckets), KIND=int_8)) + 1 END IF ! create a new item allocate (new_item) new_item%hash = hash new_item%key =key new_item%value =>value new_item%next => dict%buckets(idx)%p dict%buckets(idx)%p => new_item dict%size = dict%size + 1 END SUBROUTINE set_hashed_i4tuple_callstat