(git:0de0cc2)
cp_linked_list_input.F
Go to the documentation of this file.
1 !--------------------------------------------------------------------------------------------------!
2 ! CP2K: A general program to perform molecular dynamics simulations !
3 ! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
4 ! !
5 ! SPDX-License-Identifier: GPL-2.0-or-later !
6 !--------------------------------------------------------------------------------------------------!
7 
8 
10  USE kinds, only: dp, default_string_length
11  USE input_val_types, only: val_type, val_p_type
12 #include "../base/base_uses.f90"
13 
14 
15 ! **************************************************************************************************
16 !> \brief describes a generic linked list template.
17 !> Linked list are supposed to always use pointers to the nodes for
18 !> basically everything: a pointer to the node is a list, an element of
19 !> the list, an iterator between the elment of the list.
20 !> An empty list is represented by an unassociated pointer.
21 !> \par History
22 !> 1.2002 created
23 !> 4.2002 changed most of the methods, by making access to the list
24 !> always through pointers (identifying pointer, list and iterators)
25 !> 6.2004 removed %initialized from list elements
26 !> \author Fawzi Mohamed
27 ! **************************************************************************************************
28  IMPLICIT NONE
29  PRIVATE
30 
31  LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .true.
32 
33 
34 !API type
35  PUBLIC :: cp_sll_int_type, cp_sll_int_p_type
36  PUBLIC :: cp_sll_real_type, cp_sll_real_p_type
37  PUBLIC :: cp_sll_logical_type, cp_sll_logical_p_type
38  PUBLIC :: cp_sll_char_type, cp_sll_char_p_type
39  PUBLIC :: cp_sll_val_type, cp_sll_val_p_type
40 
41 !API common methods
42  PUBLIC :: cp_create, cp_dealloc, cp_next
43 !API special get
44  PUBLIC :: cp_get_first_el, cp_get_rest, cp_get_length, cp_get_element_at, cp_to_array
45 !API special set
46  PUBLIC :: cp_set_element_at
47 !API structure manipulation
48  PUBLIC :: cp_insert, cp_remove_first_el, cp_remove_el, cp_remove_all
49 
50  !API underlying routines
51 
97 
98 ! creation of an object (from a pointer)
99  INTERFACE cp_create
100  MODULE PROCEDURE cp_sll_int_create
101  MODULE PROCEDURE cp_sll_real_create
102  MODULE PROCEDURE cp_sll_logical_create
103  MODULE PROCEDURE cp_sll_char_create
104  MODULE PROCEDURE cp_sll_val_create
105  END INTERFACE
106 ! destruction of an object (from a pointer)
107  INTERFACE cp_dealloc
108  MODULE PROCEDURE cp_sll_int_dealloc
109  MODULE PROCEDURE cp_sll_real_dealloc
110  MODULE PROCEDURE cp_sll_logical_dealloc
111  MODULE PROCEDURE cp_sll_char_dealloc
112  MODULE PROCEDURE cp_sll_val_dealloc
113  END INTERFACE
114 ! iterates to the next element
115  INTERFACE cp_next
116  MODULE PROCEDURE cp_sll_int_next
117  MODULE PROCEDURE cp_sll_real_next
118  MODULE PROCEDURE cp_sll_logical_next
119  MODULE PROCEDURE cp_sll_char_next
120  MODULE PROCEDURE cp_sll_val_next
121  END INTERFACE
122 ! returns the first element
123  INTERFACE cp_get_first_el
124  MODULE PROCEDURE cp_sll_int_get_first_el
125  MODULE PROCEDURE cp_sll_real_get_first_el
126  MODULE PROCEDURE cp_sll_logical_get_first_el
127  MODULE PROCEDURE cp_sll_char_get_first_el
128  MODULE PROCEDURE cp_sll_val_get_first_el
129  END INTERFACE
130 ! returns the rest of the list
131  INTERFACE cp_get_rest
132  MODULE PROCEDURE cp_sll_int_get_rest
133  MODULE PROCEDURE cp_sll_real_get_rest
134  MODULE PROCEDURE cp_sll_logical_get_rest
135  MODULE PROCEDURE cp_sll_char_get_rest
136  MODULE PROCEDURE cp_sll_val_get_rest
137  END INTERFACE
138 ! returns the length of the list
139  INTERFACE cp_get_length
140  MODULE PROCEDURE cp_sll_int_get_length
141  MODULE PROCEDURE cp_sll_real_get_length
142  MODULE PROCEDURE cp_sll_logical_get_length
143  MODULE PROCEDURE cp_sll_char_get_length
144  MODULE PROCEDURE cp_sll_val_get_length
145  END INTERFACE
146 ! returns the element at the given position
147  INTERFACE cp_get_element_at
148  MODULE PROCEDURE cp_sll_int_get_el_at
149  MODULE PROCEDURE cp_sll_real_get_el_at
150  MODULE PROCEDURE cp_sll_logical_get_el_at
151  MODULE PROCEDURE cp_sll_char_get_el_at
152  MODULE PROCEDURE cp_sll_val_get_el_at
153  END INTERFACE
154 ! sets the element at the given position
155  INTERFACE cp_set_element_at
156  MODULE PROCEDURE cp_sll_int_set_el_at
157  MODULE PROCEDURE cp_sll_real_set_el_at
158  MODULE PROCEDURE cp_sll_logical_set_el_at
159  MODULE PROCEDURE cp_sll_char_set_el_at
160  MODULE PROCEDURE cp_sll_val_set_el_at
161  END INTERFACE
162 ! inserts one element call cp_insert(list,element,...)
163  INTERFACE cp_insert
164  MODULE PROCEDURE cp_sll_int_insert_el
165  MODULE PROCEDURE cp_sll_real_insert_el
166  MODULE PROCEDURE cp_sll_logical_insert_el
167  MODULE PROCEDURE cp_sll_char_insert_el
168  MODULE PROCEDURE cp_sll_val_insert_el
169  END INTERFACE
170  INTERFACE cp_insert_at
171  MODULE PROCEDURE cp_sll_int_insert_el_at
172  MODULE PROCEDURE cp_sll_real_insert_el_at
173  MODULE PROCEDURE cp_sll_logical_insert_el_at
174  MODULE PROCEDURE cp_sll_char_insert_el_at
175  MODULE PROCEDURE cp_sll_val_insert_el_at
176  END INTERFACE
177 ! removes an element
178  INTERFACE cp_remove_el
179  MODULE PROCEDURE cp_sll_int_rm_first_el, &
181  MODULE PROCEDURE cp_sll_real_rm_first_el, &
183  MODULE PROCEDURE cp_sll_logical_rm_first_el, &
185  MODULE PROCEDURE cp_sll_char_rm_first_el, &
187  MODULE PROCEDURE cp_sll_val_rm_first_el, &
189  END INTERFACE
190 ! removes the first el
191  INTERFACE cp_remove_first_el
192  MODULE PROCEDURE cp_sll_int_rm_first_el
193  MODULE PROCEDURE cp_sll_real_rm_first_el
194  MODULE PROCEDURE cp_sll_logical_rm_first_el
195  MODULE PROCEDURE cp_sll_char_rm_first_el
196  MODULE PROCEDURE cp_sll_val_rm_first_el
197  END INTERFACE
198 ! remove all the elements
199  INTERFACE cp_remove_all
200  MODULE PROCEDURE cp_sll_int_rm_all_el
201  MODULE PROCEDURE cp_sll_real_rm_all_el
202  MODULE PROCEDURE cp_sll_logical_rm_all_el
203  MODULE PROCEDURE cp_sll_char_rm_all_el
204  MODULE PROCEDURE cp_sll_val_rm_all_el
205  END INTERFACE
206 ! transorms the list in array
207  INTERFACE cp_to_array
208  module procedure cp_sll_int_to_array
209  module procedure cp_sll_real_to_array
210  module procedure cp_sll_logical_to_array
211  module procedure cp_sll_char_to_array
212  module procedure cp_sll_val_to_array
213  END INTERFACE
214 
215 ! **************************************************************************************************
216 !> \brief represent a single linked list that stores pointers to the elements
217 !> \param first_el the element that is stored in this node.
218 !> \param rest the rest of the list
219 !>
220 !> \param empty true if the list pointer is not associated, if it points to
221 !> to a not it is always false (as there is at least the
222 !> first_el in the list)
223 !> \param length the number of elements in the list
224 !> \note
225 !> List are alway accessed through pointers, so every node of the
226 !> linked list can be seen as a list, its first element
227 !> a pointer to the position before itself, in a very natural way:
228 !> all the insertions take place before the actual element, and
229 !> you still can insert an element at the end.
230 !> This way I could identify nodes, lists and pointers between the
231 !> elements of the list.
232 !> Indexing is 1 based.
233 !> \par History
234 !> none
235 !> \author Fawzi Mohamed
236 ! **************************************************************************************************
237  TYPE cp_sll_int_type
238  integer :: first_el = 0
239  TYPE(cp_sll_int_type), POINTER :: rest => null()
240  END TYPE cp_sll_int_type
241 ! **************************************************************************************************
242 !> \brief represent a single linked list that stores pointers to the elements
243 !> \param first_el the element that is stored in this node.
244 !> \param rest the rest of the list
245 !>
246 !> \param empty true if the list pointer is not associated, if it points to
247 !> to a not it is always false (as there is at least the
248 !> first_el in the list)
249 !> \param length the number of elements in the list
250 !> \note
251 !> List are alway accessed through pointers, so every node of the
252 !> linked list can be seen as a list, its first element
253 !> a pointer to the position before itself, in a very natural way:
254 !> all the insertions take place before the actual element, and
255 !> you still can insert an element at the end.
256 !> This way I could identify nodes, lists and pointers between the
257 !> elements of the list.
258 !> Indexing is 1 based.
259 !> \par History
260 !> none
261 !> \author Fawzi Mohamed
262 ! **************************************************************************************************
263  TYPE cp_sll_real_type
264  REAL(kind=dp) :: first_el = 0.0_dp
265  TYPE(cp_sll_real_type), POINTER :: rest => null()
266  END TYPE cp_sll_real_type
267 ! **************************************************************************************************
268 !> \brief represent a single linked list that stores pointers to the elements
269 !> \param first_el the element that is stored in this node.
270 !> \param rest the rest of the list
271 !>
272 !> \param empty true if the list pointer is not associated, if it points to
273 !> to a not it is always false (as there is at least the
274 !> first_el in the list)
275 !> \param length the number of elements in the list
276 !> \note
277 !> List are alway accessed through pointers, so every node of the
278 !> linked list can be seen as a list, its first element
279 !> a pointer to the position before itself, in a very natural way:
280 !> all the insertions take place before the actual element, and
281 !> you still can insert an element at the end.
282 !> This way I could identify nodes, lists and pointers between the
283 !> elements of the list.
284 !> Indexing is 1 based.
285 !> \par History
286 !> none
287 !> \author Fawzi Mohamed
288 ! **************************************************************************************************
289  TYPE cp_sll_logical_type
290  logical :: first_el = .false.
291  TYPE(cp_sll_logical_type), POINTER :: rest => null()
292  END TYPE cp_sll_logical_type
293 ! **************************************************************************************************
294 !> \brief represent a single linked list that stores pointers to the elements
295 !> \param first_el the element that is stored in this node.
296 !> \param rest the rest of the list
297 !>
298 !> \param empty true if the list pointer is not associated, if it points to
299 !> to a not it is always false (as there is at least the
300 !> first_el in the list)
301 !> \param length the number of elements in the list
302 !> \note
303 !> List are alway accessed through pointers, so every node of the
304 !> linked list can be seen as a list, its first element
305 !> a pointer to the position before itself, in a very natural way:
306 !> all the insertions take place before the actual element, and
307 !> you still can insert an element at the end.
308 !> This way I could identify nodes, lists and pointers between the
309 !> elements of the list.
310 !> Indexing is 1 based.
311 !> \par History
312 !> none
313 !> \author Fawzi Mohamed
314 ! **************************************************************************************************
315  TYPE cp_sll_char_type
316  character(len=default_string_length) :: first_el = ""
317  TYPE(cp_sll_char_type), POINTER :: rest => null()
318  END TYPE cp_sll_char_type
319 ! **************************************************************************************************
320 !> \brief represent a single linked list that stores pointers to the elements
321 !> \param first_el the element that is stored in this node.
322 !> \param rest the rest of the list
323 !>
324 !> \param empty true if the list pointer is not associated, if it points to
325 !> to a not it is always false (as there is at least the
326 !> first_el in the list)
327 !> \param length the number of elements in the list
328 !> \note
329 !> List are alway accessed through pointers, so every node of the
330 !> linked list can be seen as a list, its first element
331 !> a pointer to the position before itself, in a very natural way:
332 !> all the insertions take place before the actual element, and
333 !> you still can insert an element at the end.
334 !> This way I could identify nodes, lists and pointers between the
335 !> elements of the list.
336 !> Indexing is 1 based.
337 !> \par History
338 !> none
339 !> \author Fawzi Mohamed
340 ! **************************************************************************************************
341  TYPE cp_sll_val_type
342  type(val_type),pointer :: first_el => null()
343  TYPE(cp_sll_val_type), POINTER :: rest => null()
344  END TYPE cp_sll_val_type
345 
346 ! **************************************************************************************************
347 !> \brief pointer to a linked list (to make arrays of pointers)
348 !> \param list the pointer to the list
349 !> \par History
350 !> none
351 !> \author Fawzi Mohamed
352 ! **************************************************************************************************
353  TYPE cp_sll_int_p_type
354  TYPE(cp_sll_int_type), POINTER :: list => null()
355  END TYPE cp_sll_int_p_type
356 ! **************************************************************************************************
357 !> \brief pointer to a linked list (to make arrays of pointers)
358 !> \param list the pointer to the list
359 !> \par History
360 !> none
361 !> \author Fawzi Mohamed
362 ! **************************************************************************************************
363  TYPE cp_sll_real_p_type
364  TYPE(cp_sll_real_type), POINTER :: list => null()
365  END TYPE cp_sll_real_p_type
366 ! **************************************************************************************************
367 !> \brief pointer to a linked list (to make arrays of pointers)
368 !> \param list the pointer to the list
369 !> \par History
370 !> none
371 !> \author Fawzi Mohamed
372 ! **************************************************************************************************
373  TYPE cp_sll_logical_p_type
374  TYPE(cp_sll_logical_type), POINTER :: list => null()
375  END TYPE cp_sll_logical_p_type
376 ! **************************************************************************************************
377 !> \brief pointer to a linked list (to make arrays of pointers)
378 !> \param list the pointer to the list
379 !> \par History
380 !> none
381 !> \author Fawzi Mohamed
382 ! **************************************************************************************************
383  TYPE cp_sll_char_p_type
384  TYPE(cp_sll_char_type), POINTER :: list => null()
385  END TYPE cp_sll_char_p_type
386 ! **************************************************************************************************
387 !> \brief pointer to a linked list (to make arrays of pointers)
388 !> \param list the pointer to the list
389 !> \par History
390 !> none
391 !> \author Fawzi Mohamed
392 ! **************************************************************************************************
393  TYPE cp_sll_val_p_type
394  TYPE(cp_sll_val_type), POINTER :: list => null()
395  END TYPE cp_sll_val_p_type
396 
397  CONTAINS
398 
399 
400 ! =========== creation / destruction ========
401 
402 ! **************************************************************************************************
403 !> \brief allocates and initializes a single linked list
404 !> \param sll the single linked list to initialize
405 !> \param first_el the first element of this list
406 !> \param rest the following elements (if not given: empty)
407 !> \par History
408 !> none
409 !> \author Fawzi Mohamed
410 ! **************************************************************************************************
411  SUBROUTINE cp_sll_int_create(sll, first_el, rest)
412  TYPE(cp_sll_int_type), POINTER :: sll
413  integer, intent(in), OPTIONAL :: first_el
414  TYPE(cp_sll_int_type), POINTER, OPTIONAL :: rest
415 
416  IF (.NOT. PRESENT(first_el)) THEN
417  NULLIFY (sll)
418  IF (PRESENT(rest)) sll => rest
419  ELSE
420  ALLOCATE (sll)
421  sll%first_el =first_el
422  NULLIFY (sll%rest)
423  IF (PRESENT(rest)) sll%rest => rest
424  END IF
425  END SUBROUTINE cp_sll_int_create
426 ! **************************************************************************************************
427 !> \brief allocates and initializes a single linked list
428 !> \param sll the single linked list to initialize
429 !> \param first_el the first element of this list
430 !> \param rest the following elements (if not given: empty)
431 !> \par History
432 !> none
433 !> \author Fawzi Mohamed
434 ! **************************************************************************************************
435  SUBROUTINE cp_sll_real_create(sll, first_el, rest)
436  TYPE(cp_sll_real_type), POINTER :: sll
437  REAL(kind=dp), intent(in), OPTIONAL :: first_el
438  TYPE(cp_sll_real_type), POINTER, OPTIONAL :: rest
439 
440  IF (.NOT. PRESENT(first_el)) THEN
441  NULLIFY (sll)
442  IF (PRESENT(rest)) sll => rest
443  ELSE
444  ALLOCATE (sll)
445  sll%first_el =first_el
446  NULLIFY (sll%rest)
447  IF (PRESENT(rest)) sll%rest => rest
448  END IF
449  END SUBROUTINE cp_sll_real_create
450 ! **************************************************************************************************
451 !> \brief allocates and initializes a single linked list
452 !> \param sll the single linked list to initialize
453 !> \param first_el the first element of this list
454 !> \param rest the following elements (if not given: empty)
455 !> \par History
456 !> none
457 !> \author Fawzi Mohamed
458 ! **************************************************************************************************
459  SUBROUTINE cp_sll_logical_create(sll, first_el, rest)
460  TYPE(cp_sll_logical_type), POINTER :: sll
461  logical, intent(in), OPTIONAL :: first_el
462  TYPE(cp_sll_logical_type), POINTER, OPTIONAL :: rest
463 
464  IF (.NOT. PRESENT(first_el)) THEN
465  NULLIFY (sll)
466  IF (PRESENT(rest)) sll => rest
467  ELSE
468  ALLOCATE (sll)
469  sll%first_el =first_el
470  NULLIFY (sll%rest)
471  IF (PRESENT(rest)) sll%rest => rest
472  END IF
473  END SUBROUTINE cp_sll_logical_create
474 ! **************************************************************************************************
475 !> \brief allocates and initializes a single linked list
476 !> \param sll the single linked list to initialize
477 !> \param first_el the first element of this list
478 !> \param rest the following elements (if not given: empty)
479 !> \par History
480 !> none
481 !> \author Fawzi Mohamed
482 ! **************************************************************************************************
483  SUBROUTINE cp_sll_char_create(sll, first_el, rest)
484  TYPE(cp_sll_char_type), POINTER :: sll
485  character(len=default_string_length), intent(in), OPTIONAL :: first_el
486  TYPE(cp_sll_char_type), POINTER, OPTIONAL :: rest
487 
488  IF (.NOT. PRESENT(first_el)) THEN
489  NULLIFY (sll)
490  IF (PRESENT(rest)) sll => rest
491  ELSE
492  ALLOCATE (sll)
493  sll%first_el =first_el
494  NULLIFY (sll%rest)
495  IF (PRESENT(rest)) sll%rest => rest
496  END IF
497  END SUBROUTINE cp_sll_char_create
498 ! **************************************************************************************************
499 !> \brief allocates and initializes a single linked list
500 !> \param sll the single linked list to initialize
501 !> \param first_el the first element of this list
502 !> \param rest the following elements (if not given: empty)
503 !> \par History
504 !> none
505 !> \author Fawzi Mohamed
506 ! **************************************************************************************************
507  SUBROUTINE cp_sll_val_create(sll, first_el, rest)
508  TYPE(cp_sll_val_type), POINTER :: sll
509  type(val_type),pointer, intent(in), OPTIONAL :: first_el
510  TYPE(cp_sll_val_type), POINTER, OPTIONAL :: rest
511 
512  IF (.NOT. PRESENT(first_el)) THEN
513  NULLIFY (sll)
514  IF (PRESENT(rest)) sll => rest
515  ELSE
516  ALLOCATE (sll)
517  sll%first_el =>first_el
518  NULLIFY (sll%rest)
519  IF (PRESENT(rest)) sll%rest => rest
520  END IF
521  END SUBROUTINE cp_sll_val_create
522 
523 ! **************************************************************************************************
524 !> \brief deallocates the singly linked list starting at sll.
525 !> Does not work if loops are present!
526 !> \param sll the list to be deallocated
527 !> \par History
528 !> none
529 !> \author Fawzi Mohamed
530 !> \note
531 !> does not deallocate the elements that are stored in the list
532 !> check more?
533 ! **************************************************************************************************
534  SUBROUTINE cp_sll_int_dealloc(sll)
535  TYPE(cp_sll_int_type), POINTER :: sll
536 
537  CALL cp_sll_int_rm_all_el(sll)
538  END SUBROUTINE cp_sll_int_dealloc
539 ! **************************************************************************************************
540 !> \brief deallocates the singly linked list starting at sll.
541 !> Does not work if loops are present!
542 !> \param sll the list to be deallocated
543 !> \par History
544 !> none
545 !> \author Fawzi Mohamed
546 !> \note
547 !> does not deallocate the elements that are stored in the list
548 !> check more?
549 ! **************************************************************************************************
550  SUBROUTINE cp_sll_real_dealloc(sll)
551  TYPE(cp_sll_real_type), POINTER :: sll
552 
553  CALL cp_sll_real_rm_all_el(sll)
554  END SUBROUTINE cp_sll_real_dealloc
555 ! **************************************************************************************************
556 !> \brief deallocates the singly linked list starting at sll.
557 !> Does not work if loops are present!
558 !> \param sll the list to be deallocated
559 !> \par History
560 !> none
561 !> \author Fawzi Mohamed
562 !> \note
563 !> does not deallocate the elements that are stored in the list
564 !> check more?
565 ! **************************************************************************************************
566  SUBROUTINE cp_sll_logical_dealloc(sll)
567  TYPE(cp_sll_logical_type), POINTER :: sll
568 
569  CALL cp_sll_logical_rm_all_el(sll)
570  END SUBROUTINE cp_sll_logical_dealloc
571 ! **************************************************************************************************
572 !> \brief deallocates the singly linked list starting at sll.
573 !> Does not work if loops are present!
574 !> \param sll the list to be deallocated
575 !> \par History
576 !> none
577 !> \author Fawzi Mohamed
578 !> \note
579 !> does not deallocate the elements that are stored in the list
580 !> check more?
581 ! **************************************************************************************************
582  SUBROUTINE cp_sll_char_dealloc(sll)
583  TYPE(cp_sll_char_type), POINTER :: sll
584 
585  CALL cp_sll_char_rm_all_el(sll)
586  END SUBROUTINE cp_sll_char_dealloc
587 ! **************************************************************************************************
588 !> \brief deallocates the singly linked list starting at sll.
589 !> Does not work if loops are present!
590 !> \param sll the list to be deallocated
591 !> \par History
592 !> none
593 !> \author Fawzi Mohamed
594 !> \note
595 !> does not deallocate the elements that are stored in the list
596 !> check more?
597 ! **************************************************************************************************
598  SUBROUTINE cp_sll_val_dealloc(sll)
599  TYPE(cp_sll_val_type), POINTER :: sll
600 
601  CALL cp_sll_val_rm_all_el(sll)
602  END SUBROUTINE cp_sll_val_dealloc
603 
604 ! * low-level *
605 
606 ! **************************************************************************************************
607 !> \brief deallocates a node of a singly linked list (low level)
608 !> \param sll the node to be deallocated
609 !> \par History
610 !> none
611 !> \author Fawzi Mohamed
612 ! **************************************************************************************************
613  SUBROUTINE cp_sll_int_dealloc_node(sll)
614  TYPE(cp_sll_int_type), POINTER :: sll
615 
616  DEALLOCATE (sll)
617  END SUBROUTINE cp_sll_int_dealloc_node
618 ! **************************************************************************************************
619 !> \brief deallocates a node of a singly linked list (low level)
620 !> \param sll the node to be deallocated
621 !> \par History
622 !> none
623 !> \author Fawzi Mohamed
624 ! **************************************************************************************************
625  SUBROUTINE cp_sll_real_dealloc_node(sll)
626  TYPE(cp_sll_real_type), POINTER :: sll
627 
628  DEALLOCATE (sll)
629  END SUBROUTINE cp_sll_real_dealloc_node
630 ! **************************************************************************************************
631 !> \brief deallocates a node of a singly linked list (low level)
632 !> \param sll the node to be deallocated
633 !> \par History
634 !> none
635 !> \author Fawzi Mohamed
636 ! **************************************************************************************************
637  SUBROUTINE cp_sll_logical_dealloc_node(sll)
638  TYPE(cp_sll_logical_type), POINTER :: sll
639 
640  DEALLOCATE (sll)
641  END SUBROUTINE cp_sll_logical_dealloc_node
642 ! **************************************************************************************************
643 !> \brief deallocates a node of a singly linked list (low level)
644 !> \param sll the node to be deallocated
645 !> \par History
646 !> none
647 !> \author Fawzi Mohamed
648 ! **************************************************************************************************
649  SUBROUTINE cp_sll_char_dealloc_node(sll)
650  TYPE(cp_sll_char_type), POINTER :: sll
651 
652  DEALLOCATE (sll)
653  END SUBROUTINE cp_sll_char_dealloc_node
654 ! **************************************************************************************************
655 !> \brief deallocates a node of a singly linked list (low level)
656 !> \param sll the node to be deallocated
657 !> \par History
658 !> none
659 !> \author Fawzi Mohamed
660 ! **************************************************************************************************
661  SUBROUTINE cp_sll_val_dealloc_node(sll)
662  TYPE(cp_sll_val_type), POINTER :: sll
663 
664  DEALLOCATE (sll)
665  END SUBROUTINE cp_sll_val_dealloc_node
666 
667 ! ============= get/set ============
668 
669 ! **************************************************************************************************
670 !> \brief returns the first element stored in the list
671 !> \param sll the single linked list to get the element from
672 !> \return ...
673 !> \par History
674 !> none
675 !> \author Fawzi Mohamed
676 ! **************************************************************************************************
677  FUNCTION cp_sll_int_get_first_el(sll) RESULT(res)
678  TYPE(cp_sll_int_type), POINTER :: sll
679  integer :: res
680 
681  res =sll%first_el
682  END FUNCTION cp_sll_int_get_first_el
683 ! **************************************************************************************************
684 !> \brief returns the first element stored in the list
685 !> \param sll the single linked list to get the element from
686 !> \return ...
687 !> \par History
688 !> none
689 !> \author Fawzi Mohamed
690 ! **************************************************************************************************
691  FUNCTION cp_sll_real_get_first_el(sll) RESULT(res)
692  TYPE(cp_sll_real_type), POINTER :: sll
693  REAL(kind=dp) :: res
694 
695  res =sll%first_el
696  END FUNCTION cp_sll_real_get_first_el
697 ! **************************************************************************************************
698 !> \brief returns the first element stored in the list
699 !> \param sll the single linked list to get the element from
700 !> \return ...
701 !> \par History
702 !> none
703 !> \author Fawzi Mohamed
704 ! **************************************************************************************************
705  FUNCTION cp_sll_logical_get_first_el(sll) RESULT(res)
706  TYPE(cp_sll_logical_type), POINTER :: sll
707  logical :: res
708 
709  res =sll%first_el
710  END FUNCTION cp_sll_logical_get_first_el
711 ! **************************************************************************************************
712 !> \brief returns the first element stored in the list
713 !> \param sll the single linked list to get the element from
714 !> \return ...
715 !> \par History
716 !> none
717 !> \author Fawzi Mohamed
718 ! **************************************************************************************************
719  FUNCTION cp_sll_char_get_first_el(sll) RESULT(res)
720  TYPE(cp_sll_char_type), POINTER :: sll
721  character(len=default_string_length) :: res
722 
723  res =sll%first_el
724  END FUNCTION cp_sll_char_get_first_el
725 ! **************************************************************************************************
726 !> \brief returns the first element stored in the list
727 !> \param sll the single linked list to get the element from
728 !> \return ...
729 !> \par History
730 !> none
731 !> \author Fawzi Mohamed
732 ! **************************************************************************************************
733  FUNCTION cp_sll_val_get_first_el(sll) RESULT(res)
734  TYPE(cp_sll_val_type), POINTER :: sll
735  type(val_type),pointer :: res
736 
737  res =>sll%first_el
738  END FUNCTION cp_sll_val_get_first_el
739 
740 ! **************************************************************************************************
741 !> \brief returns the rest of the list
742 !> \param sll the single linked list to get the rest from
743 !> \param iter how many times the call to rest should be iterated,
744 !> defaults to 1; -1 means till end of the list.
745 !> \return ...
746 !> \par History
747 !> none
748 !> \author Fawzi Mohamed
749 !> \note
750 !> split the case iter=1 to make it more optimized?
751 ! **************************************************************************************************
752  FUNCTION cp_sll_int_get_rest(sll, iter) RESULT(res)
753  TYPE(cp_sll_int_type), POINTER :: sll
754  INTEGER, OPTIONAL :: iter
755 
756  TYPE(cp_sll_int_type), POINTER :: res
757 
758  INTEGER :: i
759 
760  IF (.NOT. ASSOCIATED(sll)) THEN
761  NULLIFY (res)
762  ELSE
763  IF (PRESENT(iter)) THEN
764  res => sll
765  DO i = 1, iter
766  IF (ASSOCIATED(res%rest)) THEN
767  res => res%rest
768  ELSE
769  cpabort("tried to go past end")
770  END IF
771  END DO
772  IF (iter == -1) THEN
773  DO
774  IF (.NOT. ASSOCIATED(res%rest)) EXIT
775  res => res%rest
776  END DO
777  END IF
778  ELSE
779  res => sll%rest ! make the common case fast...
780  END IF
781  END IF
782  END FUNCTION cp_sll_int_get_rest
783 ! **************************************************************************************************
784 !> \brief returns the rest of the list
785 !> \param sll the single linked list to get the rest from
786 !> \param iter how many times the call to rest should be iterated,
787 !> defaults to 1; -1 means till end of the list.
788 !> \return ...
789 !> \par History
790 !> none
791 !> \author Fawzi Mohamed
792 !> \note
793 !> split the case iter=1 to make it more optimized?
794 ! **************************************************************************************************
795  FUNCTION cp_sll_real_get_rest(sll, iter) RESULT(res)
796  TYPE(cp_sll_real_type), POINTER :: sll
797  INTEGER, OPTIONAL :: iter
798 
799  TYPE(cp_sll_real_type), POINTER :: res
800 
801  INTEGER :: i
802 
803  IF (.NOT. ASSOCIATED(sll)) THEN
804  NULLIFY (res)
805  ELSE
806  IF (PRESENT(iter)) THEN
807  res => sll
808  DO i = 1, iter
809  IF (ASSOCIATED(res%rest)) THEN
810  res => res%rest
811  ELSE
812  cpabort("tried to go past end")
813  END IF
814  END DO
815  IF (iter == -1) THEN
816  DO
817  IF (.NOT. ASSOCIATED(res%rest)) EXIT
818  res => res%rest
819  END DO
820  END IF
821  ELSE
822  res => sll%rest ! make the common case fast...
823  END IF
824  END IF
825  END FUNCTION cp_sll_real_get_rest
826 ! **************************************************************************************************
827 !> \brief returns the rest of the list
828 !> \param sll the single linked list to get the rest from
829 !> \param iter how many times the call to rest should be iterated,
830 !> defaults to 1; -1 means till end of the list.
831 !> \return ...
832 !> \par History
833 !> none
834 !> \author Fawzi Mohamed
835 !> \note
836 !> split the case iter=1 to make it more optimized?
837 ! **************************************************************************************************
838  FUNCTION cp_sll_logical_get_rest(sll, iter) RESULT(res)
839  TYPE(cp_sll_logical_type), POINTER :: sll
840  INTEGER, OPTIONAL :: iter
841 
842  TYPE(cp_sll_logical_type), POINTER :: res
843 
844  INTEGER :: i
845 
846  IF (.NOT. ASSOCIATED(sll)) THEN
847  NULLIFY (res)
848  ELSE
849  IF (PRESENT(iter)) THEN
850  res => sll
851  DO i = 1, iter
852  IF (ASSOCIATED(res%rest)) THEN
853  res => res%rest
854  ELSE
855  cpabort("tried to go past end")
856  END IF
857  END DO
858  IF (iter == -1) THEN
859  DO
860  IF (.NOT. ASSOCIATED(res%rest)) EXIT
861  res => res%rest
862  END DO
863  END IF
864  ELSE
865  res => sll%rest ! make the common case fast...
866  END IF
867  END IF
868  END FUNCTION cp_sll_logical_get_rest
869 ! **************************************************************************************************
870 !> \brief returns the rest of the list
871 !> \param sll the single linked list to get the rest from
872 !> \param iter how many times the call to rest should be iterated,
873 !> defaults to 1; -1 means till end of the list.
874 !> \return ...
875 !> \par History
876 !> none
877 !> \author Fawzi Mohamed
878 !> \note
879 !> split the case iter=1 to make it more optimized?
880 ! **************************************************************************************************
881  FUNCTION cp_sll_char_get_rest(sll, iter) RESULT(res)
882  TYPE(cp_sll_char_type), POINTER :: sll
883  INTEGER, OPTIONAL :: iter
884 
885  TYPE(cp_sll_char_type), POINTER :: res
886 
887  INTEGER :: i
888 
889  IF (.NOT. ASSOCIATED(sll)) THEN
890  NULLIFY (res)
891  ELSE
892  IF (PRESENT(iter)) THEN
893  res => sll
894  DO i = 1, iter
895  IF (ASSOCIATED(res%rest)) THEN
896  res => res%rest
897  ELSE
898  cpabort("tried to go past end")
899  END IF
900  END DO
901  IF (iter == -1) THEN
902  DO
903  IF (.NOT. ASSOCIATED(res%rest)) EXIT
904  res => res%rest
905  END DO
906  END IF
907  ELSE
908  res => sll%rest ! make the common case fast...
909  END IF
910  END IF
911  END FUNCTION cp_sll_char_get_rest
912 ! **************************************************************************************************
913 !> \brief returns the rest of the list
914 !> \param sll the single linked list to get the rest from
915 !> \param iter how many times the call to rest should be iterated,
916 !> defaults to 1; -1 means till end of the list.
917 !> \return ...
918 !> \par History
919 !> none
920 !> \author Fawzi Mohamed
921 !> \note
922 !> split the case iter=1 to make it more optimized?
923 ! **************************************************************************************************
924  FUNCTION cp_sll_val_get_rest(sll, iter) RESULT(res)
925  TYPE(cp_sll_val_type), POINTER :: sll
926  INTEGER, OPTIONAL :: iter
927 
928  TYPE(cp_sll_val_type), POINTER :: res
929 
930  INTEGER :: i
931 
932  IF (.NOT. ASSOCIATED(sll)) THEN
933  NULLIFY (res)
934  ELSE
935  IF (PRESENT(iter)) THEN
936  res => sll
937  DO i = 1, iter
938  IF (ASSOCIATED(res%rest)) THEN
939  res => res%rest
940  ELSE
941  cpabort("tried to go past end")
942  END IF
943  END DO
944  IF (iter == -1) THEN
945  DO
946  IF (.NOT. ASSOCIATED(res%rest)) EXIT
947  res => res%rest
948  END DO
949  END IF
950  ELSE
951  res => sll%rest ! make the common case fast...
952  END IF
953  END IF
954  END FUNCTION cp_sll_val_get_rest
955 
956 ! **************************************************************************************************
957 !> \brief returns the length of the list
958 !> \param sll the list you want to know the length of
959 !> \return ...
960 !> \par History
961 !> none
962 !> \author Fawzi Mohamed
963 !> \note
964 !> slow (O(n))
965 ! **************************************************************************************************
966  FUNCTION cp_sll_int_get_length(sll) RESULT(res)
967  TYPE(cp_sll_int_type), pointer :: sll
968  INTEGER ::res
969 
970  TYPE(cp_sll_int_type), POINTER :: iterator
971 
972  res = 0
973  iterator => sll
974  DO
975  IF (ASSOCIATED(iterator)) THEN
976  res = res + 1
977  iterator => iterator%rest
978  ELSE
979  EXIT
980  END IF
981  END DO
982  END FUNCTION cp_sll_int_get_length
983 ! **************************************************************************************************
984 !> \brief returns the length of the list
985 !> \param sll the list you want to know the length of
986 !> \return ...
987 !> \par History
988 !> none
989 !> \author Fawzi Mohamed
990 !> \note
991 !> slow (O(n))
992 ! **************************************************************************************************
993  FUNCTION cp_sll_real_get_length(sll) RESULT(res)
994  TYPE(cp_sll_real_type), pointer :: sll
995  INTEGER ::res
996 
997  TYPE(cp_sll_real_type), POINTER :: iterator
998 
999  res = 0
1000  iterator => sll
1001  DO
1002  IF (ASSOCIATED(iterator)) THEN
1003  res = res + 1
1004  iterator => iterator%rest
1005  ELSE
1006  EXIT
1007  END IF
1008  END DO
1009  END FUNCTION cp_sll_real_get_length
1010 ! **************************************************************************************************
1011 !> \brief returns the length of the list
1012 !> \param sll the list you want to know the length of
1013 !> \return ...
1014 !> \par History
1015 !> none
1016 !> \author Fawzi Mohamed
1017 !> \note
1018 !> slow (O(n))
1019 ! **************************************************************************************************
1020  FUNCTION cp_sll_logical_get_length(sll) RESULT(res)
1021  TYPE(cp_sll_logical_type), pointer :: sll
1022  INTEGER ::res
1023 
1024  TYPE(cp_sll_logical_type), POINTER :: iterator
1025 
1026  res = 0
1027  iterator => sll
1028  DO
1029  IF (ASSOCIATED(iterator)) THEN
1030  res = res + 1
1031  iterator => iterator%rest
1032  ELSE
1033  EXIT
1034  END IF
1035  END DO
1036  END FUNCTION cp_sll_logical_get_length
1037 ! **************************************************************************************************
1038 !> \brief returns the length of the list
1039 !> \param sll the list you want to know the length of
1040 !> \return ...
1041 !> \par History
1042 !> none
1043 !> \author Fawzi Mohamed
1044 !> \note
1045 !> slow (O(n))
1046 ! **************************************************************************************************
1047  FUNCTION cp_sll_char_get_length(sll) RESULT(res)
1048  TYPE(cp_sll_char_type), pointer :: sll
1049  INTEGER ::res
1050 
1051  TYPE(cp_sll_char_type), POINTER :: iterator
1052 
1053  res = 0
1054  iterator => sll
1055  DO
1056  IF (ASSOCIATED(iterator)) THEN
1057  res = res + 1
1058  iterator => iterator%rest
1059  ELSE
1060  EXIT
1061  END IF
1062  END DO
1063  END FUNCTION cp_sll_char_get_length
1064 ! **************************************************************************************************
1065 !> \brief returns the length of the list
1066 !> \param sll the list you want to know the length of
1067 !> \return ...
1068 !> \par History
1069 !> none
1070 !> \author Fawzi Mohamed
1071 !> \note
1072 !> slow (O(n))
1073 ! **************************************************************************************************
1074  FUNCTION cp_sll_val_get_length(sll) RESULT(res)
1075  TYPE(cp_sll_val_type), pointer :: sll
1076  INTEGER ::res
1077 
1078  TYPE(cp_sll_val_type), POINTER :: iterator
1079 
1080  res = 0
1081  iterator => sll
1082  DO
1083  IF (ASSOCIATED(iterator)) THEN
1084  res = res + 1
1085  iterator => iterator%rest
1086  ELSE
1087  EXIT
1088  END IF
1089  END DO
1090  END FUNCTION cp_sll_val_get_length
1091 
1092 ! **************************************************************************************************
1093 !> \brief returns the element at the given index
1094 !> \param sll the list you get the element from
1095 !> \param index the position of the element (stating at 1)
1096 !> \return ...
1097 !> \par History
1098 !> none
1099 !> \author Fawzi Mohamed
1100 !> \note
1101 !> slow (O(index))
1102 ! **************************************************************************************************
1103  FUNCTION cp_sll_int_get_el_at(sll, index) RESULT(res)
1104  integer :: res
1105  TYPE(cp_sll_int_type), POINTER :: sll
1106  INTEGER, INTENT(in) :: index
1107 
1108  TYPE(cp_sll_int_type), POINTER :: pos
1109 
1110  IF (index == -1) THEN
1111  pos => cp_sll_int_get_rest(sll, iter=-1)
1112  ELSE
1113  pos => cp_sll_int_get_rest(sll, iter=index - 1)
1114  END IF
1115  cpassert(ASSOCIATED(pos))
1116 
1117  res =pos%first_el
1118  END FUNCTION cp_sll_int_get_el_at
1119 ! **************************************************************************************************
1120 !> \brief returns the element at the given index
1121 !> \param sll the list you get the element from
1122 !> \param index the position of the element (stating at 1)
1123 !> \return ...
1124 !> \par History
1125 !> none
1126 !> \author Fawzi Mohamed
1127 !> \note
1128 !> slow (O(index))
1129 ! **************************************************************************************************
1130  FUNCTION cp_sll_real_get_el_at(sll, index) RESULT(res)
1131  REAL(kind=dp) :: res
1132  TYPE(cp_sll_real_type), POINTER :: sll
1133  INTEGER, INTENT(in) :: index
1134 
1135  TYPE(cp_sll_real_type), POINTER :: pos
1136 
1137  IF (index == -1) THEN
1138  pos => cp_sll_real_get_rest(sll, iter=-1)
1139  ELSE
1140  pos => cp_sll_real_get_rest(sll, iter=index - 1)
1141  END IF
1142  cpassert(ASSOCIATED(pos))
1143 
1144  res =pos%first_el
1145  END FUNCTION cp_sll_real_get_el_at
1146 ! **************************************************************************************************
1147 !> \brief returns the element at the given index
1148 !> \param sll the list you get the element from
1149 !> \param index the position of the element (stating at 1)
1150 !> \return ...
1151 !> \par History
1152 !> none
1153 !> \author Fawzi Mohamed
1154 !> \note
1155 !> slow (O(index))
1156 ! **************************************************************************************************
1157  FUNCTION cp_sll_logical_get_el_at(sll, index) RESULT(res)
1158  logical :: res
1159  TYPE(cp_sll_logical_type), POINTER :: sll
1160  INTEGER, INTENT(in) :: index
1161 
1162  TYPE(cp_sll_logical_type), POINTER :: pos
1163 
1164  IF (index == -1) THEN
1165  pos => cp_sll_logical_get_rest(sll, iter=-1)
1166  ELSE
1167  pos => cp_sll_logical_get_rest(sll, iter=index - 1)
1168  END IF
1169  cpassert(ASSOCIATED(pos))
1170 
1171  res =pos%first_el
1172  END FUNCTION cp_sll_logical_get_el_at
1173 ! **************************************************************************************************
1174 !> \brief returns the element at the given index
1175 !> \param sll the list you get the element from
1176 !> \param index the position of the element (stating at 1)
1177 !> \return ...
1178 !> \par History
1179 !> none
1180 !> \author Fawzi Mohamed
1181 !> \note
1182 !> slow (O(index))
1183 ! **************************************************************************************************
1184  FUNCTION cp_sll_char_get_el_at(sll, index) RESULT(res)
1185  character(len=default_string_length) :: res
1186  TYPE(cp_sll_char_type), POINTER :: sll
1187  INTEGER, INTENT(in) :: index
1188 
1189  TYPE(cp_sll_char_type), POINTER :: pos
1190 
1191  IF (index == -1) THEN
1192  pos => cp_sll_char_get_rest(sll, iter=-1)
1193  ELSE
1194  pos => cp_sll_char_get_rest(sll, iter=index - 1)
1195  END IF
1196  cpassert(ASSOCIATED(pos))
1197 
1198  res =pos%first_el
1199  END FUNCTION cp_sll_char_get_el_at
1200 ! **************************************************************************************************
1201 !> \brief returns the element at the given index
1202 !> \param sll the list you get the element from
1203 !> \param index the position of the element (stating at 1)
1204 !> \return ...
1205 !> \par History
1206 !> none
1207 !> \author Fawzi Mohamed
1208 !> \note
1209 !> slow (O(index))
1210 ! **************************************************************************************************
1211  FUNCTION cp_sll_val_get_el_at(sll, index) RESULT(res)
1212  type(val_type),pointer :: res
1213  TYPE(cp_sll_val_type), POINTER :: sll
1214  INTEGER, INTENT(in) :: index
1215 
1216  TYPE(cp_sll_val_type), POINTER :: pos
1217 
1218  IF (index == -1) THEN
1219  pos => cp_sll_val_get_rest(sll, iter=-1)
1220  ELSE
1221  pos => cp_sll_val_get_rest(sll, iter=index - 1)
1222  END IF
1223  cpassert(ASSOCIATED(pos))
1224 
1225  res =>pos%first_el
1226  END FUNCTION cp_sll_val_get_el_at
1227 
1228 ! **************************************************************************************************
1229 !> \brief sets the element at the given index
1230 !> \param sll the list you get the element from
1231 !> \param index the position of the element (stating at 1)
1232 !> -1 means at the end
1233 !> \param value the new element
1234 !> \par History
1235 !> none
1236 !> \author Fawzi Mohamed
1237 !> \note
1238 !> slow (O(index))
1239 ! **************************************************************************************************
1240  SUBROUTINE cp_sll_int_set_el_at(sll, index, value)
1241  integer, intent(in) :: value
1242  TYPE(cp_sll_int_type), POINTER :: sll
1243  INTEGER, INTENT(in) :: index
1244 
1245  TYPE(cp_sll_int_type), POINTER :: pos
1246 
1247  IF (index == -1) THEN
1248  pos => cp_sll_int_get_rest(sll, iter=-1)
1249  ELSE
1250  pos => cp_sll_int_get_rest(sll, iter=index - 1)
1251  END IF
1252  cpassert(ASSOCIATED(pos))
1253 
1254  pos%first_el =value
1255  END SUBROUTINE cp_sll_int_set_el_at
1256 ! **************************************************************************************************
1257 !> \brief sets the element at the given index
1258 !> \param sll the list you get the element from
1259 !> \param index the position of the element (stating at 1)
1260 !> -1 means at the end
1261 !> \param value the new element
1262 !> \par History
1263 !> none
1264 !> \author Fawzi Mohamed
1265 !> \note
1266 !> slow (O(index))
1267 ! **************************************************************************************************
1268  SUBROUTINE cp_sll_real_set_el_at(sll, index, value)
1269  REAL(kind=dp), intent(in) :: value
1270  TYPE(cp_sll_real_type), POINTER :: sll
1271  INTEGER, INTENT(in) :: index
1272 
1273  TYPE(cp_sll_real_type), POINTER :: pos
1274 
1275  IF (index == -1) THEN
1276  pos => cp_sll_real_get_rest(sll, iter=-1)
1277  ELSE
1278  pos => cp_sll_real_get_rest(sll, iter=index - 1)
1279  END IF
1280  cpassert(ASSOCIATED(pos))
1281 
1282  pos%first_el =value
1283  END SUBROUTINE cp_sll_real_set_el_at
1284 ! **************************************************************************************************
1285 !> \brief sets the element at the given index
1286 !> \param sll the list you get the element from
1287 !> \param index the position of the element (stating at 1)
1288 !> -1 means at the end
1289 !> \param value the new element
1290 !> \par History
1291 !> none
1292 !> \author Fawzi Mohamed
1293 !> \note
1294 !> slow (O(index))
1295 ! **************************************************************************************************
1296  SUBROUTINE cp_sll_logical_set_el_at(sll, index, value)
1297  logical, intent(in) :: value
1298  TYPE(cp_sll_logical_type), POINTER :: sll
1299  INTEGER, INTENT(in) :: index
1300 
1301  TYPE(cp_sll_logical_type), POINTER :: pos
1302 
1303  IF (index == -1) THEN
1304  pos => cp_sll_logical_get_rest(sll, iter=-1)
1305  ELSE
1306  pos => cp_sll_logical_get_rest(sll, iter=index - 1)
1307  END IF
1308  cpassert(ASSOCIATED(pos))
1309 
1310  pos%first_el =value
1311  END SUBROUTINE cp_sll_logical_set_el_at
1312 ! **************************************************************************************************
1313 !> \brief sets the element at the given index
1314 !> \param sll the list you get the element from
1315 !> \param index the position of the element (stating at 1)
1316 !> -1 means at the end
1317 !> \param value the new element
1318 !> \par History
1319 !> none
1320 !> \author Fawzi Mohamed
1321 !> \note
1322 !> slow (O(index))
1323 ! **************************************************************************************************
1324  SUBROUTINE cp_sll_char_set_el_at(sll, index, value)
1325  character(len=default_string_length), intent(in) :: value
1326  TYPE(cp_sll_char_type), POINTER :: sll
1327  INTEGER, INTENT(in) :: index
1328 
1329  TYPE(cp_sll_char_type), POINTER :: pos
1330 
1331  IF (index == -1) THEN
1332  pos => cp_sll_char_get_rest(sll, iter=-1)
1333  ELSE
1334  pos => cp_sll_char_get_rest(sll, iter=index - 1)
1335  END IF
1336  cpassert(ASSOCIATED(pos))
1337 
1338  pos%first_el =value
1339  END SUBROUTINE cp_sll_char_set_el_at
1340 ! **************************************************************************************************
1341 !> \brief sets the element at the given index
1342 !> \param sll the list you get the element from
1343 !> \param index the position of the element (stating at 1)
1344 !> -1 means at the end
1345 !> \param value the new element
1346 !> \par History
1347 !> none
1348 !> \author Fawzi Mohamed
1349 !> \note
1350 !> slow (O(index))
1351 ! **************************************************************************************************
1352  SUBROUTINE cp_sll_val_set_el_at(sll, index, value)
1353  type(val_type),pointer, intent(in) :: value
1354  TYPE(cp_sll_val_type), POINTER :: sll
1355  INTEGER, INTENT(in) :: index
1356 
1357  TYPE(cp_sll_val_type), POINTER :: pos
1358 
1359  IF (index == -1) THEN
1360  pos => cp_sll_val_get_rest(sll, iter=-1)
1361  ELSE
1362  pos => cp_sll_val_get_rest(sll, iter=index - 1)
1363  END IF
1364  cpassert(ASSOCIATED(pos))
1365 
1366  pos%first_el =>value
1367  END SUBROUTINE cp_sll_val_set_el_at
1368 
1369 ! * iteration *
1370 
1371 ! **************************************************************************************************
1372 !> \brief returns true if the actual element is valid (i.e. iterator ont at end)
1373 !> moves the iterator to the next element
1374 !> \param iterator iterator that moves along the list
1375 !> \param el_att the actual element (valid only if the function returns true)
1376 !> \return ...
1377 !> \par History
1378 !> none
1379 !> \author Fawzi Mohamed
1380 ! **************************************************************************************************
1381  FUNCTION cp_sll_int_next(iterator, el_att) RESULT(res)
1382  TYPE(cp_sll_int_type), POINTER :: iterator
1383  integer, intent(out), OPTIONAL :: el_att
1384  LOGICAL :: res
1385 
1386  IF (ASSOCIATED(iterator)) THEN
1387  res = .true.
1388  if (present(el_att)) el_att =iterator%first_el
1389  iterator => iterator%rest
1390  ELSE
1391  res = .false.
1392  END IF
1393  END FUNCTION cp_sll_int_next
1394 ! **************************************************************************************************
1395 !> \brief returns true if the actual element is valid (i.e. iterator ont at end)
1396 !> moves the iterator to the next element
1397 !> \param iterator iterator that moves along the list
1398 !> \param el_att the actual element (valid only if the function returns true)
1399 !> \return ...
1400 !> \par History
1401 !> none
1402 !> \author Fawzi Mohamed
1403 ! **************************************************************************************************
1404  FUNCTION cp_sll_real_next(iterator, el_att) RESULT(res)
1405  TYPE(cp_sll_real_type), POINTER :: iterator
1406  REAL(kind=dp), intent(out), OPTIONAL :: el_att
1407  LOGICAL :: res
1408 
1409  IF (ASSOCIATED(iterator)) THEN
1410  res = .true.
1411  if (present(el_att)) el_att =iterator%first_el
1412  iterator => iterator%rest
1413  ELSE
1414  res = .false.
1415  END IF
1416  END FUNCTION cp_sll_real_next
1417 ! **************************************************************************************************
1418 !> \brief returns true if the actual element is valid (i.e. iterator ont at end)
1419 !> moves the iterator to the next element
1420 !> \param iterator iterator that moves along the list
1421 !> \param el_att the actual element (valid only if the function returns true)
1422 !> \return ...
1423 !> \par History
1424 !> none
1425 !> \author Fawzi Mohamed
1426 ! **************************************************************************************************
1427  FUNCTION cp_sll_logical_next(iterator, el_att) RESULT(res)
1428  TYPE(cp_sll_logical_type), POINTER :: iterator
1429  logical, intent(out), OPTIONAL :: el_att
1430  LOGICAL :: res
1431 
1432  IF (ASSOCIATED(iterator)) THEN
1433  res = .true.
1434  if (present(el_att)) el_att =iterator%first_el
1435  iterator => iterator%rest
1436  ELSE
1437  res = .false.
1438  END IF
1439  END FUNCTION cp_sll_logical_next
1440 ! **************************************************************************************************
1441 !> \brief returns true if the actual element is valid (i.e. iterator ont at end)
1442 !> moves the iterator to the next element
1443 !> \param iterator iterator that moves along the list
1444 !> \param el_att the actual element (valid only if the function returns true)
1445 !> \return ...
1446 !> \par History
1447 !> none
1448 !> \author Fawzi Mohamed
1449 ! **************************************************************************************************
1450  FUNCTION cp_sll_char_next(iterator, el_att) RESULT(res)
1451  TYPE(cp_sll_char_type), POINTER :: iterator
1452  character(len=default_string_length), intent(out), OPTIONAL :: el_att
1453  LOGICAL :: res
1454 
1455  IF (ASSOCIATED(iterator)) THEN
1456  res = .true.
1457  if (present(el_att)) el_att =iterator%first_el
1458  iterator => iterator%rest
1459  ELSE
1460  res = .false.
1461  END IF
1462  END FUNCTION cp_sll_char_next
1463 ! **************************************************************************************************
1464 !> \brief returns true if the actual element is valid (i.e. iterator ont at end)
1465 !> moves the iterator to the next element
1466 !> \param iterator iterator that moves along the list
1467 !> \param el_att the actual element (valid only if the function returns true)
1468 !> \return ...
1469 !> \par History
1470 !> none
1471 !> \author Fawzi Mohamed
1472 ! **************************************************************************************************
1473  FUNCTION cp_sll_val_next(iterator, el_att) RESULT(res)
1474  TYPE(cp_sll_val_type), POINTER :: iterator
1475  type(val_type),pointer, intent(out), OPTIONAL :: el_att
1476  LOGICAL :: res
1477 
1478  IF (ASSOCIATED(iterator)) THEN
1479  res = .true.
1480  if (present(el_att)) el_att =>iterator%first_el
1481  iterator => iterator%rest
1482  ELSE
1483  res = .false.
1484  END IF
1485  END FUNCTION cp_sll_val_next
1486 
1487 ! ============ structure modifications ============
1488 
1489 ! **************************************************************************************************
1490 !> \brief insert an element at the beginning of the list
1491 !> \param sll the single linked list point at the beginning of which
1492 !> you want to add the element
1493 !> \param el the element to add
1494 !> \par History
1495 !> none
1496 !> \author Fawzi Mohamed
1497 !> \note
1498 !> fast (O(1))
1499 ! **************************************************************************************************
1500  SUBROUTINE cp_sll_int_insert_el(sll, el)
1501  TYPE(cp_sll_int_type), POINTER :: sll
1502  integer, intent(in):: el
1503 
1504  TYPE(cp_sll_int_type), POINTER :: newslot
1505 
1506  NULLIFY (newslot)
1507 
1508  CALL cp_sll_int_create(newslot, first_el=el, &
1509  rest=sll)
1510  sll => newslot
1511  END SUBROUTINE cp_sll_int_insert_el
1512 ! **************************************************************************************************
1513 !> \brief insert an element at the beginning of the list
1514 !> \param sll the single linked list point at the beginning of which
1515 !> you want to add the element
1516 !> \param el the element to add
1517 !> \par History
1518 !> none
1519 !> \author Fawzi Mohamed
1520 !> \note
1521 !> fast (O(1))
1522 ! **************************************************************************************************
1523  SUBROUTINE cp_sll_real_insert_el(sll, el)
1524  TYPE(cp_sll_real_type), POINTER :: sll
1525  REAL(kind=dp), intent(in):: el
1526 
1527  TYPE(cp_sll_real_type), POINTER :: newslot
1528 
1529  NULLIFY (newslot)
1530 
1531  CALL cp_sll_real_create(newslot, first_el=el, &
1532  rest=sll)
1533  sll => newslot
1534  END SUBROUTINE cp_sll_real_insert_el
1535 ! **************************************************************************************************
1536 !> \brief insert an element at the beginning of the list
1537 !> \param sll the single linked list point at the beginning of which
1538 !> you want to add the element
1539 !> \param el the element to add
1540 !> \par History
1541 !> none
1542 !> \author Fawzi Mohamed
1543 !> \note
1544 !> fast (O(1))
1545 ! **************************************************************************************************
1546  SUBROUTINE cp_sll_logical_insert_el(sll, el)
1547  TYPE(cp_sll_logical_type), POINTER :: sll
1548  logical, intent(in):: el
1549 
1550  TYPE(cp_sll_logical_type), POINTER :: newslot
1551 
1552  NULLIFY (newslot)
1553 
1554  CALL cp_sll_logical_create(newslot, first_el=el, &
1555  rest=sll)
1556  sll => newslot
1557  END SUBROUTINE cp_sll_logical_insert_el
1558 ! **************************************************************************************************
1559 !> \brief insert an element at the beginning of the list
1560 !> \param sll the single linked list point at the beginning of which
1561 !> you want to add the element
1562 !> \param el the element to add
1563 !> \par History
1564 !> none
1565 !> \author Fawzi Mohamed
1566 !> \note
1567 !> fast (O(1))
1568 ! **************************************************************************************************
1569  SUBROUTINE cp_sll_char_insert_el(sll, el)
1570  TYPE(cp_sll_char_type), POINTER :: sll
1571  character(len=default_string_length), intent(in):: el
1572 
1573  TYPE(cp_sll_char_type), POINTER :: newslot
1574 
1575  NULLIFY (newslot)
1576 
1577  CALL cp_sll_char_create(newslot, first_el=el, &
1578  rest=sll)
1579  sll => newslot
1580  END SUBROUTINE cp_sll_char_insert_el
1581 ! **************************************************************************************************
1582 !> \brief insert an element at the beginning of the list
1583 !> \param sll the single linked list point at the beginning of which
1584 !> you want to add the element
1585 !> \param el the element to add
1586 !> \par History
1587 !> none
1588 !> \author Fawzi Mohamed
1589 !> \note
1590 !> fast (O(1))
1591 ! **************************************************************************************************
1592  SUBROUTINE cp_sll_val_insert_el(sll, el)
1593  TYPE(cp_sll_val_type), POINTER :: sll
1594  type(val_type),pointer, intent(in):: el
1595 
1596  TYPE(cp_sll_val_type), POINTER :: newslot
1597 
1598  NULLIFY (newslot)
1599 
1600  CALL cp_sll_val_create(newslot, first_el=el, &
1601  rest=sll)
1602  sll => newslot
1603  END SUBROUTINE cp_sll_val_insert_el
1604 
1605 ! **************************************************************************************************
1606 !> \brief remove the first element of the linked list
1607 !> \param sll the list whose first element has to be removed
1608 !> \par History
1609 !> none
1610 !> \author Fawzi Mohamed
1611 !> \note
1612 !> fast (O(1))
1613 ! **************************************************************************************************
1614  SUBROUTINE cp_sll_int_rm_first_el(sll)
1615  TYPE(cp_sll_int_type), POINTER :: sll
1616 
1617  TYPE(cp_sll_int_type), POINTER :: node_to_rm
1618  node_to_rm => sll
1619 
1620  IF (ASSOCIATED(sll)) THEN
1621  sll => sll%rest
1622  CALL cp_sll_int_dealloc_node(node_to_rm)
1623  ELSE
1624  cpabort("tried to remove first el of an empty list")
1625  END IF
1626  END SUBROUTINE cp_sll_int_rm_first_el
1627 ! **************************************************************************************************
1628 !> \brief remove the first element of the linked list
1629 !> \param sll the list whose first element has to be removed
1630 !> \par History
1631 !> none
1632 !> \author Fawzi Mohamed
1633 !> \note
1634 !> fast (O(1))
1635 ! **************************************************************************************************
1636  SUBROUTINE cp_sll_real_rm_first_el(sll)
1637  TYPE(cp_sll_real_type), POINTER :: sll
1638 
1639  TYPE(cp_sll_real_type), POINTER :: node_to_rm
1640  node_to_rm => sll
1641 
1642  IF (ASSOCIATED(sll)) THEN
1643  sll => sll%rest
1644  CALL cp_sll_real_dealloc_node(node_to_rm)
1645  ELSE
1646  cpabort("tried to remove first el of an empty list")
1647  END IF
1648  END SUBROUTINE cp_sll_real_rm_first_el
1649 ! **************************************************************************************************
1650 !> \brief remove the first element of the linked list
1651 !> \param sll the list whose first element has to be removed
1652 !> \par History
1653 !> none
1654 !> \author Fawzi Mohamed
1655 !> \note
1656 !> fast (O(1))
1657 ! **************************************************************************************************
1659  TYPE(cp_sll_logical_type), POINTER :: sll
1660 
1661  TYPE(cp_sll_logical_type), POINTER :: node_to_rm
1662  node_to_rm => sll
1663 
1664  IF (ASSOCIATED(sll)) THEN
1665  sll => sll%rest
1666  CALL cp_sll_logical_dealloc_node(node_to_rm)
1667  ELSE
1668  cpabort("tried to remove first el of an empty list")
1669  END IF
1670  END SUBROUTINE cp_sll_logical_rm_first_el
1671 ! **************************************************************************************************
1672 !> \brief remove the first element of the linked list
1673 !> \param sll the list whose first element has to be removed
1674 !> \par History
1675 !> none
1676 !> \author Fawzi Mohamed
1677 !> \note
1678 !> fast (O(1))
1679 ! **************************************************************************************************
1680  SUBROUTINE cp_sll_char_rm_first_el(sll)
1681  TYPE(cp_sll_char_type), POINTER :: sll
1682 
1683  TYPE(cp_sll_char_type), POINTER :: node_to_rm
1684  node_to_rm => sll
1685 
1686  IF (ASSOCIATED(sll)) THEN
1687  sll => sll%rest
1688  CALL cp_sll_char_dealloc_node(node_to_rm)
1689  ELSE
1690  cpabort("tried to remove first el of an empty list")
1691  END IF
1692  END SUBROUTINE cp_sll_char_rm_first_el
1693 ! **************************************************************************************************
1694 !> \brief remove the first element of the linked list
1695 !> \param sll the list whose first element has to be removed
1696 !> \par History
1697 !> none
1698 !> \author Fawzi Mohamed
1699 !> \note
1700 !> fast (O(1))
1701 ! **************************************************************************************************
1702  SUBROUTINE cp_sll_val_rm_first_el(sll)
1703  TYPE(cp_sll_val_type), POINTER :: sll
1704 
1705  TYPE(cp_sll_val_type), POINTER :: node_to_rm
1706  node_to_rm => sll
1707 
1708  IF (ASSOCIATED(sll)) THEN
1709  sll => sll%rest
1710  CALL cp_sll_val_dealloc_node(node_to_rm)
1711  ELSE
1712  cpabort("tried to remove first el of an empty list")
1713  END IF
1714  END SUBROUTINE cp_sll_val_rm_first_el
1715 
1716 ! **************************************************************************************************
1717 !> \brief inserts the element at the given index
1718 !> \param sll the list you get the element from
1719 !> \param el the new element
1720 !> \param index the position of the element (stating at 1).
1721 !> If it is -1, it means at end
1722 !> \par History
1723 !> none
1724 !> \author Fawzi Mohamed
1725 !> \note
1726 !> slow (O(index))
1727 ! **************************************************************************************************
1728  SUBROUTINE cp_sll_int_insert_el_at(sll, el, index)
1729  integer, intent(in) :: el
1730  INTEGER, INTENT(in) :: index
1731  TYPE(cp_sll_int_type), POINTER :: sll
1732 
1733  TYPE(cp_sll_int_type), POINTER :: pos
1734 
1735  IF (index == 1) THEN
1736  CALL cp_sll_int_insert_el(sll, el)
1737  ELSE
1738  IF (index == -1) THEN
1739  pos => cp_sll_int_get_rest(sll, iter=-1)
1740  ELSE
1741  pos => cp_sll_int_get_rest(sll, iter=index - 2)
1742  END IF
1743  cpassert(ASSOCIATED(pos))
1744  CALL cp_sll_int_insert_el(pos%rest, el)
1745  END IF
1746  END SUBROUTINE cp_sll_int_insert_el_at
1747 ! **************************************************************************************************
1748 !> \brief inserts the element at the given index
1749 !> \param sll the list you get the element from
1750 !> \param el the new element
1751 !> \param index the position of the element (stating at 1).
1752 !> If it is -1, it means at end
1753 !> \par History
1754 !> none
1755 !> \author Fawzi Mohamed
1756 !> \note
1757 !> slow (O(index))
1758 ! **************************************************************************************************
1759  SUBROUTINE cp_sll_real_insert_el_at(sll, el, index)
1760  REAL(kind=dp), intent(in) :: el
1761  INTEGER, INTENT(in) :: index
1762  TYPE(cp_sll_real_type), POINTER :: sll
1763 
1764  TYPE(cp_sll_real_type), POINTER :: pos
1765 
1766  IF (index == 1) THEN
1767  CALL cp_sll_real_insert_el(sll, el)
1768  ELSE
1769  IF (index == -1) THEN
1770  pos => cp_sll_real_get_rest(sll, iter=-1)
1771  ELSE
1772  pos => cp_sll_real_get_rest(sll, iter=index - 2)
1773  END IF
1774  cpassert(ASSOCIATED(pos))
1775  CALL cp_sll_real_insert_el(pos%rest, el)
1776  END IF
1777  END SUBROUTINE cp_sll_real_insert_el_at
1778 ! **************************************************************************************************
1779 !> \brief inserts the element at the given index
1780 !> \param sll the list you get the element from
1781 !> \param el the new element
1782 !> \param index the position of the element (stating at 1).
1783 !> If it is -1, it means at end
1784 !> \par History
1785 !> none
1786 !> \author Fawzi Mohamed
1787 !> \note
1788 !> slow (O(index))
1789 ! **************************************************************************************************
1790  SUBROUTINE cp_sll_logical_insert_el_at(sll, el, index)
1791  logical, intent(in) :: el
1792  INTEGER, INTENT(in) :: index
1793  TYPE(cp_sll_logical_type), POINTER :: sll
1794 
1795  TYPE(cp_sll_logical_type), POINTER :: pos
1796 
1797  IF (index == 1) THEN
1798  CALL cp_sll_logical_insert_el(sll, el)
1799  ELSE
1800  IF (index == -1) THEN
1801  pos => cp_sll_logical_get_rest(sll, iter=-1)
1802  ELSE
1803  pos => cp_sll_logical_get_rest(sll, iter=index - 2)
1804  END IF
1805  cpassert(ASSOCIATED(pos))
1806  CALL cp_sll_logical_insert_el(pos%rest, el)
1807  END IF
1808  END SUBROUTINE cp_sll_logical_insert_el_at
1809 ! **************************************************************************************************
1810 !> \brief inserts the element at the given index
1811 !> \param sll the list you get the element from
1812 !> \param el the new element
1813 !> \param index the position of the element (stating at 1).
1814 !> If it is -1, it means at end
1815 !> \par History
1816 !> none
1817 !> \author Fawzi Mohamed
1818 !> \note
1819 !> slow (O(index))
1820 ! **************************************************************************************************
1821  SUBROUTINE cp_sll_char_insert_el_at(sll, el, index)
1822  character(len=default_string_length), intent(in) :: el
1823  INTEGER, INTENT(in) :: index
1824  TYPE(cp_sll_char_type), POINTER :: sll
1825 
1826  TYPE(cp_sll_char_type), POINTER :: pos
1827 
1828  IF (index == 1) THEN
1829  CALL cp_sll_char_insert_el(sll, el)
1830  ELSE
1831  IF (index == -1) THEN
1832  pos => cp_sll_char_get_rest(sll, iter=-1)
1833  ELSE
1834  pos => cp_sll_char_get_rest(sll, iter=index - 2)
1835  END IF
1836  cpassert(ASSOCIATED(pos))
1837  CALL cp_sll_char_insert_el(pos%rest, el)
1838  END IF
1839  END SUBROUTINE cp_sll_char_insert_el_at
1840 ! **************************************************************************************************
1841 !> \brief inserts the element at the given index
1842 !> \param sll the list you get the element from
1843 !> \param el the new element
1844 !> \param index the position of the element (stating at 1).
1845 !> If it is -1, it means at end
1846 !> \par History
1847 !> none
1848 !> \author Fawzi Mohamed
1849 !> \note
1850 !> slow (O(index))
1851 ! **************************************************************************************************
1852  SUBROUTINE cp_sll_val_insert_el_at(sll, el, index)
1853  type(val_type),pointer, intent(in) :: el
1854  INTEGER, INTENT(in) :: index
1855  TYPE(cp_sll_val_type), POINTER :: sll
1856 
1857  TYPE(cp_sll_val_type), POINTER :: pos
1858 
1859  IF (index == 1) THEN
1860  CALL cp_sll_val_insert_el(sll, el)
1861  ELSE
1862  IF (index == -1) THEN
1863  pos => cp_sll_val_get_rest(sll, iter=-1)
1864  ELSE
1865  pos => cp_sll_val_get_rest(sll, iter=index - 2)
1866  END IF
1867  cpassert(ASSOCIATED(pos))
1868  CALL cp_sll_val_insert_el(pos%rest, el)
1869  END IF
1870  END SUBROUTINE cp_sll_val_insert_el_at
1871 
1872 ! **************************************************************************************************
1873 !> \brief removes the element at the given index
1874 !> \param sll the list you get the element from
1875 !> \param index the position of the element (stating at 1)
1876 !> \par History
1877 !> none
1878 !> \author Fawzi Mohamed
1879 !> \note
1880 !> slow (O(index))
1881 ! **************************************************************************************************
1882  SUBROUTINE cp_sll_int_rm_el_at(sll, index)
1883  TYPE(cp_sll_int_type), POINTER :: sll
1884  INTEGER, INTENT(in)::index
1885 
1886  TYPE(cp_sll_int_type), POINTER :: pos
1887 
1888  IF (index == 1) THEN
1889  CALL cp_sll_int_rm_first_el(sll)
1890  ELSE
1891  IF (index == -1) THEN
1892  pos => cp_sll_int_get_rest(sll, iter=-1)
1893  ELSE
1894  pos => cp_sll_int_get_rest(sll, iter=index - 2)
1895  END IF
1896  cpassert(ASSOCIATED(pos))
1897  CALL cp_sll_int_rm_first_el(pos%rest)
1898  END IF
1899  END SUBROUTINE cp_sll_int_rm_el_at
1900 ! **************************************************************************************************
1901 !> \brief removes the element at the given index
1902 !> \param sll the list you get the element from
1903 !> \param index the position of the element (stating at 1)
1904 !> \par History
1905 !> none
1906 !> \author Fawzi Mohamed
1907 !> \note
1908 !> slow (O(index))
1909 ! **************************************************************************************************
1910  SUBROUTINE cp_sll_real_rm_el_at(sll, index)
1911  TYPE(cp_sll_real_type), POINTER :: sll
1912  INTEGER, INTENT(in)::index
1913 
1914  TYPE(cp_sll_real_type), POINTER :: pos
1915 
1916  IF (index == 1) THEN
1917  CALL cp_sll_real_rm_first_el(sll)
1918  ELSE
1919  IF (index == -1) THEN
1920  pos => cp_sll_real_get_rest(sll, iter=-1)
1921  ELSE
1922  pos => cp_sll_real_get_rest(sll, iter=index - 2)
1923  END IF
1924  cpassert(ASSOCIATED(pos))
1925  CALL cp_sll_real_rm_first_el(pos%rest)
1926  END IF
1927  END SUBROUTINE cp_sll_real_rm_el_at
1928 ! **************************************************************************************************
1929 !> \brief removes the element at the given index
1930 !> \param sll the list you get the element from
1931 !> \param index the position of the element (stating at 1)
1932 !> \par History
1933 !> none
1934 !> \author Fawzi Mohamed
1935 !> \note
1936 !> slow (O(index))
1937 ! **************************************************************************************************
1938  SUBROUTINE cp_sll_logical_rm_el_at(sll, index)
1939  TYPE(cp_sll_logical_type), POINTER :: sll
1940  INTEGER, INTENT(in)::index
1941 
1942  TYPE(cp_sll_logical_type), POINTER :: pos
1943 
1944  IF (index == 1) THEN
1945  CALL cp_sll_logical_rm_first_el(sll)
1946  ELSE
1947  IF (index == -1) THEN
1948  pos => cp_sll_logical_get_rest(sll, iter=-1)
1949  ELSE
1950  pos => cp_sll_logical_get_rest(sll, iter=index - 2)
1951  END IF
1952  cpassert(ASSOCIATED(pos))
1953  CALL cp_sll_logical_rm_first_el(pos%rest)
1954  END IF
1955  END SUBROUTINE cp_sll_logical_rm_el_at
1956 ! **************************************************************************************************
1957 !> \brief removes the element at the given index
1958 !> \param sll the list you get the element from
1959 !> \param index the position of the element (stating at 1)
1960 !> \par History
1961 !> none
1962 !> \author Fawzi Mohamed
1963 !> \note
1964 !> slow (O(index))
1965 ! **************************************************************************************************
1966  SUBROUTINE cp_sll_char_rm_el_at(sll, index)
1967  TYPE(cp_sll_char_type), POINTER :: sll
1968  INTEGER, INTENT(in)::index
1969 
1970  TYPE(cp_sll_char_type), POINTER :: pos
1971 
1972  IF (index == 1) THEN
1973  CALL cp_sll_char_rm_first_el(sll)
1974  ELSE
1975  IF (index == -1) THEN
1976  pos => cp_sll_char_get_rest(sll, iter=-1)
1977  ELSE
1978  pos => cp_sll_char_get_rest(sll, iter=index - 2)
1979  END IF
1980  cpassert(ASSOCIATED(pos))
1981  CALL cp_sll_char_rm_first_el(pos%rest)
1982  END IF
1983  END SUBROUTINE cp_sll_char_rm_el_at
1984 ! **************************************************************************************************
1985 !> \brief removes the element at the given index
1986 !> \param sll the list you get the element from
1987 !> \param index the position of the element (stating at 1)
1988 !> \par History
1989 !> none
1990 !> \author Fawzi Mohamed
1991 !> \note
1992 !> slow (O(index))
1993 ! **************************************************************************************************
1994  SUBROUTINE cp_sll_val_rm_el_at(sll, index)
1995  TYPE(cp_sll_val_type), POINTER :: sll
1996  INTEGER, INTENT(in)::index
1997 
1998  TYPE(cp_sll_val_type), POINTER :: pos
1999 
2000  IF (index == 1) THEN
2001  CALL cp_sll_val_rm_first_el(sll)
2002  ELSE
2003  IF (index == -1) THEN
2004  pos => cp_sll_val_get_rest(sll, iter=-1)
2005  ELSE
2006  pos => cp_sll_val_get_rest(sll, iter=index - 2)
2007  END IF
2008  cpassert(ASSOCIATED(pos))
2009  CALL cp_sll_val_rm_first_el(pos%rest)
2010  END IF
2011  END SUBROUTINE cp_sll_val_rm_el_at
2012 
2013 ! **************************************************************************************************
2014 !> \brief removes all the elements from the list
2015 !> \param sll the list that should be removed
2016 !> \par History
2017 !> none
2018 !> \author Fawzi Mohamed
2019 !> \note
2020 !> check more?
2021 ! **************************************************************************************************
2022  SUBROUTINE cp_sll_int_rm_all_el(sll)
2023  TYPE(cp_sll_int_type), POINTER :: sll
2024 
2025  TYPE(cp_sll_int_type), POINTER :: next_node, actual_node
2026 
2027  actual_node => sll
2028  DO
2029  IF (.NOT. ASSOCIATED(actual_node)) EXIT
2030  next_node => actual_node%rest
2031  CALL cp_sll_int_dealloc_node(actual_node)
2032  actual_node => next_node
2033  END DO
2034  NULLIFY (sll)
2035  END SUBROUTINE cp_sll_int_rm_all_el
2036 ! **************************************************************************************************
2037 !> \brief removes all the elements from the list
2038 !> \param sll the list that should be removed
2039 !> \par History
2040 !> none
2041 !> \author Fawzi Mohamed
2042 !> \note
2043 !> check more?
2044 ! **************************************************************************************************
2045  SUBROUTINE cp_sll_real_rm_all_el(sll)
2046  TYPE(cp_sll_real_type), POINTER :: sll
2047 
2048  TYPE(cp_sll_real_type), POINTER :: next_node, actual_node
2049 
2050  actual_node => sll
2051  DO
2052  IF (.NOT. ASSOCIATED(actual_node)) EXIT
2053  next_node => actual_node%rest
2054  CALL cp_sll_real_dealloc_node(actual_node)
2055  actual_node => next_node
2056  END DO
2057  NULLIFY (sll)
2058  END SUBROUTINE cp_sll_real_rm_all_el
2059 ! **************************************************************************************************
2060 !> \brief removes all the elements from the list
2061 !> \param sll the list that should be removed
2062 !> \par History
2063 !> none
2064 !> \author Fawzi Mohamed
2065 !> \note
2066 !> check more?
2067 ! **************************************************************************************************
2069  TYPE(cp_sll_logical_type), POINTER :: sll
2070 
2071  TYPE(cp_sll_logical_type), POINTER :: next_node, actual_node
2072 
2073  actual_node => sll
2074  DO
2075  IF (.NOT. ASSOCIATED(actual_node)) EXIT
2076  next_node => actual_node%rest
2077  CALL cp_sll_logical_dealloc_node(actual_node)
2078  actual_node => next_node
2079  END DO
2080  NULLIFY (sll)
2081  END SUBROUTINE cp_sll_logical_rm_all_el
2082 ! **************************************************************************************************
2083 !> \brief removes all the elements from the list
2084 !> \param sll the list that should be removed
2085 !> \par History
2086 !> none
2087 !> \author Fawzi Mohamed
2088 !> \note
2089 !> check more?
2090 ! **************************************************************************************************
2091  SUBROUTINE cp_sll_char_rm_all_el(sll)
2092  TYPE(cp_sll_char_type), POINTER :: sll
2093 
2094  TYPE(cp_sll_char_type), POINTER :: next_node, actual_node
2095 
2096  actual_node => sll
2097  DO
2098  IF (.NOT. ASSOCIATED(actual_node)) EXIT
2099  next_node => actual_node%rest
2100  CALL cp_sll_char_dealloc_node(actual_node)
2101  actual_node => next_node
2102  END DO
2103  NULLIFY (sll)
2104  END SUBROUTINE cp_sll_char_rm_all_el
2105 ! **************************************************************************************************
2106 !> \brief removes all the elements from the list
2107 !> \param sll the list that should be removed
2108 !> \par History
2109 !> none
2110 !> \author Fawzi Mohamed
2111 !> \note
2112 !> check more?
2113 ! **************************************************************************************************
2114  SUBROUTINE cp_sll_val_rm_all_el(sll)
2115  TYPE(cp_sll_val_type), POINTER :: sll
2116 
2117  TYPE(cp_sll_val_type), POINTER :: next_node, actual_node
2118 
2119  actual_node => sll
2120  DO
2121  IF (.NOT. ASSOCIATED(actual_node)) EXIT
2122  next_node => actual_node%rest
2123  CALL cp_sll_val_dealloc_node(actual_node)
2124  actual_node => next_node
2125  END DO
2126  NULLIFY (sll)
2127  END SUBROUTINE cp_sll_val_rm_all_el
2128 
2129 ! **************************************************************************************************
2130 !> \brief returns a newly allocated array with the same contents as
2131 !> the linked list
2132 !> \param sll the list to transform in array
2133 !> \return ...
2134 !> \par History
2135 !> 07.2002 created [fawzi]
2136 !> \author Fawzi Mohamed
2137 ! **************************************************************************************************
2138  FUNCTION cp_sll_int_to_array(sll) RESULT(res)
2139  TYPE(cp_sll_int_type), POINTER :: sll
2140  integer, DIMENSION(:), POINTER :: res
2141 
2142  INTEGER :: len, i
2143  LOGICAL :: ok
2144  TYPE(cp_sll_int_type), POINTER :: iter
2145 
2146  len = cp_sll_int_get_length(sll)
2147  ALLOCATE (res(len))
2148  iter => sll
2149  DO i = 1, len
2150  res(i) =iter%first_el
2151  ok = cp_sll_int_next(iter)
2152  cpassert(ok .OR. i == len)
2153  END DO
2154  END FUNCTION cp_sll_int_to_array
2155 ! **************************************************************************************************
2156 !> \brief returns a newly allocated array with the same contents as
2157 !> the linked list
2158 !> \param sll the list to transform in array
2159 !> \return ...
2160 !> \par History
2161 !> 07.2002 created [fawzi]
2162 !> \author Fawzi Mohamed
2163 ! **************************************************************************************************
2164  FUNCTION cp_sll_real_to_array(sll) RESULT(res)
2165  TYPE(cp_sll_real_type), POINTER :: sll
2166  REAL(kind=dp), DIMENSION(:), POINTER :: res
2167 
2168  INTEGER :: len, i
2169  LOGICAL :: ok
2170  TYPE(cp_sll_real_type), POINTER :: iter
2171 
2172  len = cp_sll_real_get_length(sll)
2173  ALLOCATE (res(len))
2174  iter => sll
2175  DO i = 1, len
2176  res(i) =iter%first_el
2177  ok = cp_sll_real_next(iter)
2178  cpassert(ok .OR. i == len)
2179  END DO
2180  END FUNCTION cp_sll_real_to_array
2181 ! **************************************************************************************************
2182 !> \brief returns a newly allocated array with the same contents as
2183 !> the linked list
2184 !> \param sll the list to transform in array
2185 !> \return ...
2186 !> \par History
2187 !> 07.2002 created [fawzi]
2188 !> \author Fawzi Mohamed
2189 ! **************************************************************************************************
2190  FUNCTION cp_sll_logical_to_array(sll) RESULT(res)
2191  TYPE(cp_sll_logical_type), POINTER :: sll
2192  logical, DIMENSION(:), POINTER :: res
2193 
2194  INTEGER :: len, i
2195  LOGICAL :: ok
2196  TYPE(cp_sll_logical_type), POINTER :: iter
2197 
2198  len = cp_sll_logical_get_length(sll)
2199  ALLOCATE (res(len))
2200  iter => sll
2201  DO i = 1, len
2202  res(i) =iter%first_el
2203  ok = cp_sll_logical_next(iter)
2204  cpassert(ok .OR. i == len)
2205  END DO
2206  END FUNCTION cp_sll_logical_to_array
2207 ! **************************************************************************************************
2208 !> \brief returns a newly allocated array with the same contents as
2209 !> the linked list
2210 !> \param sll the list to transform in array
2211 !> \return ...
2212 !> \par History
2213 !> 07.2002 created [fawzi]
2214 !> \author Fawzi Mohamed
2215 ! **************************************************************************************************
2216  FUNCTION cp_sll_char_to_array(sll) RESULT(res)
2217  TYPE(cp_sll_char_type), POINTER :: sll
2218  character(len=default_string_length), DIMENSION(:), POINTER :: res
2219 
2220  INTEGER :: len, i
2221  LOGICAL :: ok
2222  TYPE(cp_sll_char_type), POINTER :: iter
2223 
2224  len = cp_sll_char_get_length(sll)
2225  ALLOCATE (res(len))
2226  iter => sll
2227  DO i = 1, len
2228  res(i) =iter%first_el
2229  ok = cp_sll_char_next(iter)
2230  cpassert(ok .OR. i == len)
2231  END DO
2232  END FUNCTION cp_sll_char_to_array
2233 ! **************************************************************************************************
2234 !> \brief returns a newly allocated array with the same contents as
2235 !> the linked list
2236 !> \param sll the list to transform in array
2237 !> \return ...
2238 !> \par History
2239 !> 07.2002 created [fawzi]
2240 !> \author Fawzi Mohamed
2241 ! **************************************************************************************************
2242  FUNCTION cp_sll_val_to_array(sll) RESULT(res)
2243  TYPE(cp_sll_val_type), POINTER :: sll
2244  type(val_p_type), DIMENSION(:), POINTER :: res
2245 
2246  INTEGER :: len, i
2247  LOGICAL :: ok
2248  TYPE(cp_sll_val_type), POINTER :: iter
2249 
2250  len = cp_sll_val_get_length(sll)
2251  ALLOCATE (res(len))
2252  iter => sll
2253  DO i = 1, len
2254  res(i) %val=>iter%first_el
2255  ok = cp_sll_val_next(iter)
2256  cpassert(ok .OR. i == len)
2257  END DO
2258  END FUNCTION cp_sll_val_to_array
2259 END MODULE
type(cp_sll_val_type) function, pointer, public cp_sll_val_get_rest(sll, iter)
returns the rest of the list
subroutine, public cp_sll_real_rm_all_el(sll)
removes all the elements from the list
logical function, public cp_sll_logical_get_el_at(sll, index)
returns the element at the given index
subroutine, public cp_sll_int_insert_el_at(sll, el, index)
inserts the element at the given index
subroutine, public cp_sll_char_set_el_at(sll, index, value)
sets the element at the given index
subroutine, public cp_sll_int_rm_el_at(sll, index)
removes the element at the given index
subroutine, public cp_sll_char_insert_el_at(sll, el, index)
inserts the element at the given index
logical function, dimension(:), pointer, public cp_sll_logical_to_array(sll)
returns a newly allocated array with the same contents as the linked list
type(cp_sll_int_type) function, pointer, public cp_sll_int_get_rest(sll, iter)
returns the rest of the list
integer function, public cp_sll_int_get_length(sll)
returns the length of the list
subroutine, public cp_sll_logical_insert_el_at(sll, el, index)
inserts the element at the given index
real(kind=dp) function, public cp_sll_real_get_el_at(sll, index)
returns the element at the given index
subroutine, public cp_sll_logical_rm_el_at(sll, index)
removes the element at the given index
integer function, public cp_sll_val_get_length(sll)
returns the length of the list
subroutine, public cp_sll_char_rm_all_el(sll)
removes all the elements from the list
subroutine, public cp_sll_logical_set_el_at(sll, index, value)
sets the element at the given index
subroutine, public cp_sll_char_dealloc(sll)
deallocates the singly linked list starting at sll. Does not work if loops are present!
logical function, public cp_sll_logical_next(iterator, el_att)
returns true if the actual element is valid (i.e. iterator ont at end) moves the iterator to the next...
character(len=default_string_length) function, public cp_sll_char_get_first_el(sll)
returns the first element stored in the list
subroutine, public cp_sll_int_set_el_at(sll, index, value)
sets the element at the given index
logical function, public cp_sll_int_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_int_create(sll, first_el, rest)
allocates and initializes a single linked list
subroutine, public cp_sll_logical_rm_all_el(sll)
removes all the elements from the list
subroutine, public cp_sll_val_rm_first_el(sll)
remove the first element of the linked list
logical function, public cp_sll_val_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_real_rm_el_at(sll, index)
removes the element at the given index
subroutine, public cp_sll_char_rm_first_el(sll)
remove the first element of the linked list
type(val_p_type) function, dimension(:), pointer, public cp_sll_val_to_array(sll)
returns a newly allocated array with the same contents as the linked list
subroutine, public cp_sll_val_rm_all_el(sll)
removes all the elements from the list
integer function, public cp_sll_real_get_length(sll)
returns the length of the list
subroutine, public cp_sll_real_insert_el_at(sll, el, index)
inserts the element at the given index
subroutine, public cp_sll_val_insert_el(sll, el)
insert an element at the beginning of the list
real(kind=dp) function, public cp_sll_real_get_first_el(sll)
returns the first element stored in the list
real(kind=dp) function, dimension(:), pointer, public cp_sll_real_to_array(sll)
returns a newly allocated array with the same contents as the linked list
subroutine, public cp_sll_val_rm_el_at(sll, index)
removes the element at the given index
subroutine, public cp_sll_val_create(sll, first_el, rest)
allocates and initializes a single linked list
integer function, public cp_sll_int_get_first_el(sll)
returns the first element stored in the list
subroutine, public cp_sll_int_rm_first_el(sll)
remove the first element of the linked list
subroutine, public cp_sll_int_insert_el(sll, el)
insert an element at the beginning of the list
subroutine, public cp_sll_real_create(sll, first_el, rest)
allocates and initializes a single linked list
subroutine, public cp_sll_logical_create(sll, first_el, rest)
allocates and initializes a single linked list
subroutine, public cp_sll_real_rm_first_el(sll)
remove the first element of the linked list
subroutine, public cp_sll_char_create(sll, first_el, rest)
allocates and initializes a single linked list
subroutine, public cp_sll_int_dealloc(sll)
deallocates the singly linked list starting at sll. Does not work if loops are present!
subroutine, public cp_sll_val_set_el_at(sll, index, value)
sets the element at the given index
character(len=default_string_length) function, public cp_sll_char_get_el_at(sll, index)
returns the element at the given index
subroutine, public cp_sll_int_rm_all_el(sll)
removes all the elements from the list
subroutine, public cp_sll_char_insert_el(sll, el)
insert an element at the beginning of the list
subroutine, public cp_sll_real_dealloc(sll)
deallocates the singly linked list starting at sll. Does not work if loops are present!
character(len=default_string_length) function, dimension(:), pointer, public cp_sll_char_to_array(sll)
returns a newly allocated array with the same contents as the linked list
logical function, public cp_sll_char_next(iterator, el_att)
returns true if the actual element is valid (i.e. iterator ont at end) moves the iterator to the next...
type(cp_sll_char_type) function, pointer, public cp_sll_char_get_rest(sll, iter)
returns the rest of the list
integer function, public cp_sll_int_get_el_at(sll, index)
returns the element at the given index
integer function, dimension(:), pointer, public cp_sll_int_to_array(sll)
returns a newly allocated array with the same contents as the linked list
subroutine, public cp_sll_logical_insert_el(sll, el)
insert an element at the beginning of the list
subroutine, public cp_sll_val_insert_el_at(sll, el, index)
inserts the element at the given index
logical function, public cp_sll_logical_get_first_el(sll)
returns the first element stored in the list
subroutine, public cp_sll_char_rm_el_at(sll, index)
removes the element at the given index
type(val_type) function, pointer, public cp_sll_val_get_el_at(sll, index)
returns the element at the given index
type(cp_sll_logical_type) function, pointer, public cp_sll_logical_get_rest(sll, iter)
returns the rest of the list
type(cp_sll_real_type) function, pointer, public cp_sll_real_get_rest(sll, iter)
returns the rest of the list
subroutine, public cp_sll_logical_dealloc(sll)
deallocates the singly linked list starting at sll. Does not work if loops are present!
subroutine, public cp_sll_logical_rm_first_el(sll)
remove the first element of the linked list
integer function, public cp_sll_logical_get_length(sll)
returns the length of the list
subroutine, public cp_sll_real_set_el_at(sll, index, value)
sets the element at the given index
logical function, public cp_sll_real_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_real_insert_el(sll, el)
insert an element at the beginning of the list
integer function, public cp_sll_char_get_length(sll)
returns the length of the list
type(val_type) function, pointer, public cp_sll_val_get_first_el(sll)
returns the first element stored in the list
subroutine, public cp_sll_val_dealloc(sll)
deallocates the singly linked list starting at sll. Does not work if loops are present!
a wrapper for basic fortran types.
Defines the basic variable types.
Definition: kinds.F:23
integer, parameter, public dp
Definition: kinds.F:34
integer, parameter, public default_string_length
Definition: kinds.F:57