subroutineindex_setpure
pure subroutine index_set(table, name, value)
Give name the value value in table.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| table | type(name_index_t) | inout | the table | |
| name | character(len=*) | in | the name | |
| value | integer | in | its value |
Calls
Source
Show the code
pure subroutine index_set(table, name, value)
type(name_index_t), intent(inout) :: table !! the table
character(len=*), intent(in) :: name !! the name
integer, intent(in) :: value !! its value
type(string_t), allocatable :: keys(:)
integer, allocatable :: values(:)
integer :: at, entry, k
if (.not. allocated(table%slots)) then
allocate (table%slots(64), table%keys(32), table%values(32))
table%slots = 0
end if
at = name_hash(name, size(table%slots))
do
entry = table%slots(at)
if (entry == 0) exit
if (len(table%keys(entry)%s) == len(name)) then
if (table%keys(entry)%s == name) then
table%values(entry) = value
return
end if
end if
at = merge(at + 1, 1, at < size(table%slots))
end do
if (table%n == size(table%keys)) then
allocate (keys(2*table%n), values(2*table%n))
do k = 1, table%n
call move_alloc(table%keys(k)%s, keys(k)%s)
end do
values(1:table%n) = table%values(1:table%n)
call move_alloc(keys, table%keys)
call move_alloc(values, table%values)
deallocate (table%slots)
allocate (table%slots(4*table%n))
table%slots = 0
do k = 1, table%n
at = name_hash(table%keys(k)%s, size(table%slots))
do while (table%slots(at) /= 0)
at = merge(at + 1, 1, at < size(table%slots))
end do
table%slots(at) = k
end do
at = name_hash(name, size(table%slots))
do while (table%slots(at) /= 0)
at = merge(at + 1, 1, at < size(table%slots))
end do
end if
table%n = table%n + 1
table%keys(table%n)%s = name
table%values(table%n) = value
table%slots(at) = table%n
end subroutine index_set