set_amap_t Subroutine

public subroutine set_amap_t(this, kv, vv)

Arguments

Type IntentOptional Attributes Name
class(amap_t), intent(inout) :: this
character(len=*), intent(in) :: kv
real(kind=8), intent(in) :: vv

Contents

Source Code


Variables

Type Visibility Attributes Name Initial
integer, public :: idx
type(key_t), public :: k
type(pair_t), public, allocatable :: tmp_pairs(:)
type(value_t), public :: v

Source Code

    subroutine set_amap_t(this,kv,vv)
        class(amap_t), intent(inout) :: this
        character(len=*), intent(in) :: kv
        real(8), intent(in)          :: vv
        type(pair_t), allocatable :: tmp_pairs(:)
        type(key_t)               :: k
        type(value_t)             :: v
        integer                   :: idx
        
        k = kv
        v = vv
        if (.not. allocated(this%pairs)) then
            allocate(this%pairs(this%extent))
        end if    
        
        idx = this%find(k)
        if (idx > 0) then
            this%pairs(idx) = pair_t(k,v)
            return
        end if
        
        if (this%high_water == size(this%pairs)) then
            allocate(tmp_pairs(size(this%pairs)+this%extent))
            tmp_pairs(1:this%high_water) = this%pairs
            call move_alloc(tmp_pairs, this%pairs)
        end if
        this%high_water = this%high_water + 1
        this%pairs(this%high_water) = pair_t(k,v)
        
    end subroutine set_amap_t