18 INTEGER,
PARAMETER :: extvec_alloc_factor = 2, extvec_initial_alloc = 32
19 INTEGER,
PARAMETER :: set_modulus = 257
22 INTEGER,
DIMENSION(:),
ALLOCATABLE :: darr
23 INTEGER :: elements = 0, allocated = 0
26 PROCEDURE :: reset => extvec_reset
30 TYPE(extvec_type),
DIMENSION(0:set_modulus - 1) :: data = extvec_type()
31 INTEGER,
DIMENSION(:),
ALLOCATABLE :: sorted
32 INTEGER :: elements = 0
33 LOGICAL :: sorted_up_to_date = .false.
35 PROCEDURE :: insert => set_insert
36 PROCEDURE :: reset => set_reset
37 PROCEDURE :: find => set_find
38 PROCEDURE :: get => set_get
39 PROCEDURE :: getall => set_getall
40 PROCEDURE :: update_sorted => set_update_sorted
44 INTEGER,
DIMENSION(:),
POINTER :: data => null()
46 LOGICAL :: allocated = .false.
49 PROCEDURE :: alloc => intbuffer_alloc
50 PROCEDURE :: dealloc => intbuffer_dealloc
55 REAL(kind=
dp),
DIMENSION(:),
POINTER ::
data => null()
57 LOGICAL :: allocated = .false.
60 PROCEDURE :: alloc => buffer_alloc
61 PROCEDURE :: dealloc => buffer_dealloc
65 REAL(kind=
dp),
DIMENSION(:),
POINTER ::
target => null()
69 TYPE(
set_type),
DIMENSION(:),
ALLOCATABLE :: sets
80 CLASS(extvec_type),
INTENT(INOUT) :: this
81 INTEGER,
INTENT(IN) :: elem
82 INTEGER,
DIMENSION(:),
ALLOCATABLE :: tmp
84 IF (this%allocated .EQ. 0)
THEN
85 this%allocated = extvec_initial_alloc
86 ALLOCATE (this%darr(this%allocated))
88 IF (this%elements .EQ. this%allocated)
THEN
89 ALLOCATE (tmp(this%allocated))
91 DEALLOCATE (this%darr)
92 ALLOCATE (this%darr(this%allocated*extvec_alloc_factor))
93 this%darr(1:this%allocated) = tmp
95 this%allocated = this%allocated*extvec_alloc_factor
99 this%elements = this%elements + 1
100 this%darr(this%elements) = elem
107 PURE SUBROUTINE extvec_reset(this)
108 CLASS(extvec_type),
INTENT(INOUT) :: this
110 IF (
ALLOCATED(this%darr))
DEALLOCATE (this%darr)
113 END SUBROUTINE extvec_reset
120 PURE SUBROUTINE set_insert(this, elem)
121 CLASS(
set_type),
INTENT(INOUT) :: this
122 INTEGER,
INTENT(IN) :: elem
124 IF (.NOT. this%find(elem))
THEN
125 CALL this%data(
modulo(elem, set_modulus))%insert(elem)
126 this%sorted_up_to_date = .false.
127 this%elements = this%elements + 1
130 END SUBROUTINE set_insert
136 PURE SUBROUTINE set_reset(this)
137 CLASS(
set_type),
INTENT(INOUT) :: this
140 DO i = 0, set_modulus - 1
141 CALL this%data(i)%reset
143 IF (
ALLOCATED(this%sorted))
DEALLOCATE (this%sorted)
145 this%sorted_up_to_date = .false.
146 END SUBROUTINE set_reset
154 PURE FUNCTION set_find(this, elem)
RESULT(found)
156 INTEGER,
INTENT(IN) :: elem
163 DO i = 1, this%data(
idx)%elements
164 IF (this%data(
idx)%darr(i) .EQ. elem)
THEN
170 END FUNCTION set_find
178 FUNCTION set_get(this, idx)
RESULT(elem)
179 CLASS(
set_type),
INTENT(INOUT) :: this
180 INTEGER,
INTENT(IN) ::
idx
183 IF (.NOT. this%sorted_up_to_date)
CALL this%update_sorted
185 elem = this%sorted(
idx)
193 FUNCTION set_getall(this)
RESULT(darr)
194 CLASS(
set_type),
INTENT(INOUT) :: this
195 INTEGER,
DIMENSION(this%elements) :: darr
197 IF (.NOT. this%sorted_up_to_date)
CALL this%update_sorted
200 END FUNCTION set_getall
206 SUBROUTINE set_update_sorted(this)
207 CLASS(
set_type),
INTENT(INOUT) :: this
209 INTEGER,
DIMENSION(:),
ALLOCATABLE :: tmp
211 IF (
ALLOCATED(this%sorted))
DEALLOCATE (this%sorted)
212 ALLOCATE (this%sorted(this%elements))
215 DO i = 0, set_modulus - 1
216 IF (this%data(i)%elements .GT. 0)
THEN
217 this%sorted(
idx:
idx + this%data(i)%elements - 1) = this%data(i)%darr(1:this%data(i)%elements)
218 idx =
idx + this%data(i)%elements
222 ALLOCATE (tmp(this%elements))
223 CALL sort(this%sorted, this%elements, tmp)
226 this%sorted_up_to_date = .true.
227 END SUBROUTINE set_update_sorted
234 PURE SUBROUTINE buffer_alloc(this, elements)
236 INTEGER,
INTENT(IN) :: elements
238 ALLOCATE (this%data(elements))
239 this%allocated = .true.
241 END SUBROUTINE buffer_alloc
247 PURE SUBROUTINE buffer_dealloc(this)
250 IF (this%allocated)
DEALLOCATE (this%data)
251 this%allocated = .false.
253 END SUBROUTINE buffer_dealloc
260 PURE SUBROUTINE intbuffer_alloc(this, elements)
262 INTEGER,
INTENT(IN) :: elements
264 ALLOCATE (this%data(elements))
265 this%allocated = .true.
267 END SUBROUTINE intbuffer_alloc
273 PURE SUBROUTINE intbuffer_dealloc(this)
276 IF (this%allocated)
DEALLOCATE (this%data)
277 this%allocated = .false.
279 END SUBROUTINE intbuffer_dealloc
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
static GRID_HOST_DEVICE int idx(const orbital a)
Return coset index of given orbital angular momentum.
Defines the basic variable types.
integer, parameter, public dp
Interface to the message passing library MPI.
type(mp_request_type), parameter, public mp_request_null
pure subroutine extvec_insert(this, elem)
insert element into extendable vector
All kind of helpful little routines.