13 integer(I4B),
private,
allocatable :: values(:)
15 integer(I4B),
private :: capacity
17 procedure, pass(this) ::
init
20 procedure, pass(this) ::
pop
23 procedure, pass(this) ::
at
25 procedure, pass(this) ::
set
33 procedure,
private, pass(this) ::
expand
38 subroutine init(this, capacity)
40 integer(I4B),
intent(in),
optional :: capacity
42 if (
present(capacity))
then
43 this%capacity = capacity
48 allocate (this%values(this%capacity))
55 integer(I4B) :: newValue
57 if (this%size + 1 > this%capacity)
then
61 this%size = this%size + 1
62 this%values(this%size) = newvalue
68 integer(I4B) :: newValue
70 if (.not. this%contains(newvalue))
then
71 call this%push_back(newvalue)
79 if (this%size > 0)
then
80 this%size = this%size - 1
82 write (*, *)
'STLVecInt exception: cannot pop from an empty array'
90 integer(I4B),
dimension(:),
pointer :: array
95 call this%push_back(array(i))
102 integer(I4B),
dimension(:),
pointer :: array
106 do i = 1,
size(array)
107 if (.not. this%contains(array(i)))
then
108 call this%push_back(array(i))
114 function at(this, idx)
result(value)
116 integer(I4B),
intent(in) :: idx
117 integer(I4B) :: value
119 value = this%values(idx)
125 integer(I4B),
intent(in) :: idx
126 integer(I4B) :: value
128 if (idx > this%size)
then
129 write (*, *)
'STLVecInt exception: access out of bounds, index ', idx, &
130 ' exceeds actual size (', this%size,
')'
137 subroutine set(this, idx, value)
139 integer(I4B),
intent(in) :: idx
140 integer(I4B) :: value
142 this%values(idx) =
value
157 integer(I4B),
allocatable :: tempValues(:)
158 integer(I4B) :: i, newSize
160 if (this%size == this%capacity)
then
166 allocate (tempvalues(newsize))
168 tempvalues(i) = this%values(i)
173 call this%init(newsize)
177 call this%push_back(tempvalues(i))
185 if (
allocated(this%values))
then
186 deallocate (this%values)
190 write (*, *)
'STLVecInt exception: cannot delete an unallocated array'
200 integer(I4B) :: increment
203 increment = this%capacity / 2 + 1
205 this%capacity = this%capacity + increment
219 if (this%at(i) == val)
then
238 if (this%at(i) == val)
then
248 integer(I4B),
dimension(:),
allocatable :: values
250 values = this%values(1:this%size)
This module defines variable data types.
This module contains simulation methods.
subroutine, public ustop(stopmess, ioutlocal)
Stop the simulation.
subroutine push_back_unique(this, newValue)
subroutine set(this, idx, value)
subroutine push_back(this, newValue)
subroutine shrink_to_fit(this)
integer(i4b) function at_safe(this, idx)
integer(i4b) function, dimension(:), allocatable get_values(this)
logical(lgp) function contains(this, val)
integer(i4b) function at(this, idx)
subroutine add_array(this, array)
subroutine add_array_unique(this, array)
integer(i4b) function get_index(this, val)
Return index of first occurrence,.
integer(i4b), parameter defaultinitialcapacity