11 #include "../base/base_uses.f90"
30 LOGICAL,
PRIVATE,
PARAMETER :: debug_this_module = .true.
34 PUBLIC :: cp_sll_fm_type, cp_sll_fm_p_type
37 PUBLIC :: cp_create, cp_dealloc, cp_next
39 PUBLIC :: cp_get_first_el, cp_get_rest, cp_get_length, cp_get_element_at, cp_to_array
41 PUBLIC :: cp_set_element_at
43 PUBLIC :: cp_insert, cp_remove_first_el, cp_remove_el, cp_remove_all
70 INTERFACE cp_get_first_el
78 INTERFACE cp_get_length
82 INTERFACE cp_get_element_at
86 INTERFACE cp_set_element_at
93 INTERFACE cp_insert_at
97 INTERFACE cp_remove_el
102 INTERFACE cp_remove_first_el
106 INTERFACE cp_remove_all
110 INTERFACE cp_to_array
137 type(cp_fm_type),
pointer :: first_el => null()
138 TYPE(cp_sll_fm_type),
POINTER :: rest => null()
139 END TYPE cp_sll_fm_type
148 TYPE cp_sll_fm_p_type
149 TYPE(cp_sll_fm_type),
POINTER :: list => null()
150 END TYPE cp_sll_fm_p_type
167 TYPE(cp_sll_fm_type),
POINTER :: sll
168 type(cp_fm_type),
pointer,
OPTIONAL :: first_el
169 TYPE(cp_sll_fm_type),
POINTER,
OPTIONAL :: rest
171 IF (.NOT.
PRESENT(first_el))
THEN
173 IF (
PRESENT(rest)) sll => rest
176 sll%first_el =>first_el
178 IF (
PRESENT(rest)) sll%rest => rest
194 TYPE(cp_sll_fm_type),
POINTER :: sll
208 SUBROUTINE cp_sll_fm_dealloc_node(sll)
209 TYPE(cp_sll_fm_type),
POINTER :: sll
212 END SUBROUTINE cp_sll_fm_dealloc_node
225 TYPE(cp_sll_fm_type),
POINTER :: sll
226 type(cp_fm_type),
pointer :: res
244 TYPE(cp_sll_fm_type),
POINTER :: sll
245 INTEGER,
OPTIONAL :: iter
247 TYPE(cp_sll_fm_type),
POINTER :: res
251 IF (.NOT.
ASSOCIATED(sll))
THEN
254 IF (
PRESENT(iter))
THEN
257 IF (
ASSOCIATED(res%rest))
THEN
260 cpabort(
"tried to go past end")
265 IF (.NOT.
ASSOCIATED(res%rest))
EXIT
286 TYPE(cp_sll_fm_type),
pointer :: sll
289 TYPE(cp_sll_fm_type),
POINTER :: iterator
294 IF (
ASSOCIATED(iterator))
THEN
296 iterator => iterator%rest
315 type(cp_fm_type),
pointer :: res
316 TYPE(cp_sll_fm_type),
POINTER :: sll
317 INTEGER,
INTENT(in) :: index
319 TYPE(cp_sll_fm_type),
POINTER :: pos
321 IF (index == -1)
THEN
326 cpassert(
ASSOCIATED(pos))
344 type(cp_fm_type),
pointer :: value
345 TYPE(cp_sll_fm_type),
POINTER :: sll
346 INTEGER,
INTENT(in) :: index
348 TYPE(cp_sll_fm_type),
POINTER :: pos
350 IF (index == -1)
THEN
355 cpassert(
ASSOCIATED(pos))
373 TYPE(cp_sll_fm_type),
POINTER :: iterator
374 type(cp_fm_type),
pointer,
OPTIONAL :: el_att
377 IF (
ASSOCIATED(iterator))
THEN
379 if (
present(el_att)) el_att =>iterator%first_el
380 iterator => iterator%rest
400 TYPE(cp_sll_fm_type),
POINTER :: sll
401 type(cp_fm_type),
pointer:: el
403 TYPE(cp_sll_fm_type),
POINTER :: newslot
422 TYPE(cp_sll_fm_type),
POINTER :: sll
424 TYPE(cp_sll_fm_type),
POINTER :: node_to_rm
427 IF (
ASSOCIATED(sll))
THEN
429 CALL cp_sll_fm_dealloc_node(node_to_rm)
431 cpabort(
"tried to remove first el of an empty list")
448 type(cp_fm_type),
pointer :: el
449 INTEGER,
INTENT(in) :: index
450 TYPE(cp_sll_fm_type),
POINTER :: sll
452 TYPE(cp_sll_fm_type),
POINTER :: pos
457 IF (index == -1)
THEN
462 cpassert(
ASSOCIATED(pos))
478 TYPE(cp_sll_fm_type),
POINTER :: sll
479 INTEGER,
INTENT(in)::index
481 TYPE(cp_sll_fm_type),
POINTER :: pos
486 IF (index == -1)
THEN
491 cpassert(
ASSOCIATED(pos))
506 TYPE(cp_sll_fm_type),
POINTER :: sll
508 TYPE(cp_sll_fm_type),
POINTER :: next_node, actual_node
512 IF (.NOT.
ASSOCIATED(actual_node))
EXIT
513 next_node => actual_node%rest
514 CALL cp_sll_fm_dealloc_node(actual_node)
515 actual_node => next_node
530 TYPE(cp_sll_fm_type),
POINTER :: sll
531 type(cp_fm_p_type),
DIMENSION(:),
POINTER :: res
535 TYPE(cp_sll_fm_type),
POINTER :: iter
541 res(i) %matrix=>iter%first_el
543 cpassert(ok .OR. i == len)
represent a full matrix distributed on many processors
integer function, public cp_sll_fm_get_length(sll)
returns the length of the list
subroutine, public cp_sll_fm_insert_el(sll, el)
insert an element at the beginning of the list
subroutine, public cp_sll_fm_rm_el_at(sll, index)
removes the element at the given index
subroutine, public cp_sll_fm_rm_all_el(sll)
removes all the elements from the list
subroutine, public cp_sll_fm_create(sll, first_el, rest)
allocates and initializes a single linked list
type(cp_sll_fm_type) function, pointer, public cp_sll_fm_get_rest(sll, iter)
returns the rest of the list
logical function, public cp_sll_fm_next(iterator, el_att)
returns true if the actual element is valid (i.e. iterator ont at end) moves the iterator to the next...
subroutine, public cp_sll_fm_insert_el_at(sll, el, index)
inserts the element at the given index
type(cp_fm_p_type) function, dimension(:), pointer, public cp_sll_fm_to_array(sll)
returns a newly allocated array with the same contents as the linked list
type(cp_fm_type) function, pointer, public cp_sll_fm_get_first_el(sll)
returns the first element stored in the list
subroutine, public cp_sll_fm_dealloc(sll)
deallocates the singly linked list starting at sll. Does not work if loops are present!
type(cp_fm_type) function, pointer, public cp_sll_fm_get_el_at(sll, index)
returns the element at the given index
subroutine, public cp_sll_fm_set_el_at(sll, index, value)
sets the element at the given index
subroutine, public cp_sll_fm_rm_first_el(sll)
remove the first element of the linked list