This repository has been archived by the owner on Nov 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
collections.f90
1517 lines (1437 loc) · 66.4 KB
/
collections.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
! collections.f90
!> @brief Provides types supporting various collections of objects.
module collections
use iso_fortran_env
use ferror
use strings
implicit none
private
public :: list
public :: items_equal
public :: compare_items
public :: dictionary
public :: hash_code
public :: linked_list
public :: data_table
! ******************************************************************************
! TYPES
! ------------------------------------------------------------------------------
!> @brief A container type allowing storage of any Fortran type.
type container
!> A pointer to a polymorphic variable allowing storage of any type.
class(*), pointer :: item => null()
end type
!> @brief A node in a linked list container.
type node
!> A pointer to a polymorphic variable allowing storage of any type.
class(*), pointer :: item => null()
!> A pointer to the next node in the collection.
type(node), pointer :: next => null()
!> A pointer to the previous node in the collection.
type(node), pointer :: previous => null()
end type
!> @brief Defines a generic list.
type list
private
!> A collection of container objects.
type(container), allocatable, dimension(:) :: m_list
!> The actual number of items in m_list
integer(int32) :: m_count = 0
contains
!> @brief Cleans up resources held by the list.
final :: list_destroy
!> @brief Gets the capacity of the list.
!!
!! @par Syntax
!! @code{.f90}
!! integer(int32) get_capacity(class(list) this)
!! @endcode
!!
!! @param[in] this The list object.
!! @return The capacity of the list.
procedure, public :: get_capacity => list_get_capacity
!> @brief Sets the capacity of the list.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine set_capacity(class(list) this, integer(int32) n, class(errors) err)
!! @endcode
!!
!! @param[in,out] this The list object.
!! @param[in] n The desired capacity of the list. This value must not
!! be less than the number of items already stored in the list.
!! @param[in,out] err An optional errors-based object that if provided
!! can be used to retrieve information relating to any errors
!! encountered during execution. If not provided, a default
!! implementation of the errors class is used internally to provide
!! error handling. Possible errors and warning messages that may be
!! encountered are as follows.
!! - FCORE_OUT_OF_MEMORY_ERROR: Occurs if there is insufficient memory.
!! - FCORE_INVALID_INPUT_ERROR: Occurs if the user asks to reduce
!! capacity via this routine.
procedure, public :: set_capacity => list_set_capacity
!> @brief Gets the number of items in the list.
!!
!! @par Syntax
!! @code{.f90}
!! integer(int32) get_count(class(list) this)
!! @endcode
!!
!! @param[in] this The list object.
!! @return The number of items stored in the list.
procedure, public :: get_count => list_get_count
!> @brief Gets an item from the list.
!!
!! @par Syntax
!! @code{.f90}
!! class(*) pointer get(class(list) this, integer(int32) i)
!! @endcode
!!
!! @param[in] this The list object.
!! @param[in] i The index of the item.
!! @return A pointer to the requested item.
procedure, public :: get => list_get
!> @brief Sets an item into the list.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine set(class(list) this, integer(int32) i, class(*) x, class(errors) err)
!! @endcode
!!
!! @param[in,out] this The list object.
!! @param[in] i The index of the item.
!! @param[in] x The item to place into the list.
!! @param[in,out] err An optional errors-based object that if provided
!! can be used to retrieve information relating to any errors
!! encountered during execution. If not provided, a default
!! implementation of the errors class is used internally to provide
!! error handling. Possible errors and warning messages that may be
!! encountered are as follows.
!! - FCORE_OUT_OF_MEMORY_ERROR: Occurs if there is insufficient memory.
!! - FCORE_INDEX_OUT_OF_RANGE_ERROR: Occurs if @p i is out of range.
procedure, public :: set => list_set
!> @brief Pushes an item onto the end of the list.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine push(class(list) this, class(*) x, class(errors) err)
!! @endcode
!!
!! @param[in,out] this The list object.
!! @param[in] x The object to add to the list.
!! @param[in,out] err An optional errors-based object that if provided
!! can be used to retrieve information relating to any errors
!! encountered during execution. If not provided, a default
!! implementation of the errors class is used internally to provide
!! error handling. Possible errors and warning messages that may be
!! encountered are as follows.
!! - FCORE_OUT_OF_MEMORY_ERROR: Occurs if there is insufficient memory.
procedure, public :: push => list_push
!> @brief Pops the last item from the end of the list.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine pop(class(list) this)
!! @endcode
!!
!! @param[in,out] this The list object.
procedure, public :: pop => list_pop
!> @brief Clears the contents of the list.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine clear(class(list) this)
!! @endcode
!!
!! @param[in,out] this The list object.
procedure, public :: clear => list_clear
!> @brief Creates a deep copy of the list.
!!
!! @par Syntax
!! @code{.f90}
!! type(list) copy(class(list) this)
!! @endcode
!!
!! @param[in] this The list object.
!! @param[in,out] err An optional errors-based object that if provided
!! can be used to retrieve information relating to any errors
!! encountered during execution. If not provided, a default
!! implementation of the errors class is used internally to provide
!! error handling. Possible errors and warning messages that may be
!! encountered are as follows.
!! - FCORE_OUT_OF_MEMORY_ERROR: Occurs if there is insufficient memory.
procedure, public :: copy => list_copy
!> @brief Inserts an item into the list.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine insert(class(list) this, integer(int32) i, class(*) x, class(errors) err)
!! @endcode
!!
!! @param[in,out] this The list object.
!! @param[in] i The index at which to insert the item. Items at, and
!! beyond this index are shifted back in the list.
!! @param[in] x The item to insert.
!! @param[in,out] err An optional errors-based object that if provided
!! can be used to retrieve information relating to any errors
!! encountered during execution. If not provided, a default
!! implementation of the errors class is used internally to provide
!! error handling. Possible errors and warning messages that may be
!! encountered are as follows.
!! - FCORE_OUT_OF_MEMORY_ERROR: Occurs if there is insufficient memory.
!! - FCORE_INDEX_OUT_OF_RANGE_ERROR: Occurs if @p i is out of range.
procedure, public :: insert => list_insert
!> @brief Removes an item from the list.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine remove(class(list) this, integer(int32) i, class(errors) err)
!! @endcode
!!
!! @param[in,out] this The list object.
!! @param[in] i The index at which to remove the item. Any objects
!! behind this object in the list are shifted forward by one.
!! @param[in,out] err An optional errors-based object that if provided
!! can be used to retrieve information relating to any errors
!! encountered during execution. If not provided, a default
!! implementation of the errors class is used internally to provide
!! error handling. Possible errors and warning messages that may be
!! encountered are as follows.
!! - FCORE_OUT_OF_MEMORY_ERROR: Occurs if there is insufficient memory.
!! - FCORE_INDEX_OUT_OF_RANGE_ERROR: Occurs if @p i is out of range.
procedure, public :: remove => list_remove
!> @brief Reverses the contents of the list.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine reverse(class(list) this)
!! @endcode
!!
!! @param[in,out] this The list object.
procedure, public :: reverse => list_reverse
!> @brief Tests to see if the list contains the specified item.
!!
!! @par Syntax
!! @code{.f90}
!! logical contains(class(list) this, class(*) item, procedure(items_equal) fcn)
!! @endcode
!!
!! @param[in] this The list object.
!! @param[in] item The item to search for.
!! @param[in] fcn The function to use to compare the contents of the
!! list against @p item.
!!
!! @return Returns true if @p item is found; else, returns false.
procedure, public :: contains => list_contains
!> @brief Finds the index of the first item in the list that matches
!! the specified object.
!!
!! @par Syntax
!! @code{.f90}
!! integer(int32) index_of(class(list), class(*) item, procedure(items_equal) fcn)
!! @endcode
!!
!! @param[in] this The list object.
!! @param[in] item The item to search for.
!! @param[in] fcn The function to use to compare the contents of the
!! list against @p item.
!!
!! @return Returns the index of the first occurrence of @p item in the
!! list. If no matching item is found, a value of 0 is returned.
procedure, public :: index_of => list_index_of
!> @brief Finds the indices of all items in the list that match the
!! specified object.
!!
!! @par Syntax
!! @code{.f90}
!! integer(int32)(:) indices_of_all(class(list) this, class(*) item, procedure(items_equal) fcn, class(errors) err)
!! @endcode
!!
!! @param[in] this The list object.
!! @param[in] item The item to search for.
!! @param[in] fcn The function to use to compare the contents of the
!! list against @p item.
!! @param[in,out] err An optional errors-based object that if provided
!! can be used to retrieve information relating to any errors
!! encountered during execution. If not provided, a default
!! implementation of the errors class is used internally to provide
!! error handling. Possible errors and warning messages that may be
!! encountered are as follows.
!! - FCORE_OUT_OF_MEMORY_ERROR: Occurs if there is insufficient memory.
!!
!! @return Returns an array of indices of all items in the list that
!! match @p item. If not matches are found, an empty array is
!! returned.
procedure, public :: indices_of_all => list_indices_of_all
!> @brief Swaps two items in the list.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine swap_items(class(list) this, integer(int32) i1, integer(int32) i2, class(errors) err)
!! @endcode
!!
!! @param[in,out] this The list object.
!! @param[in] i1 The index of the first item.
!! @param[in] i2 The index of the item with which to swap.
!! @param[in,out] err An optional errors-based object that if provided
!! can be used to retrieve information relating to any errors
!! encountered during execution. If not provided, a default
!! implementation of the errors class is used internally to provide
!! error handling. Possible errors and warning messages that may be
!! encountered are as follows.
!! - FCORE_ARRAY_SIZE_ERROR: Occurs if @p i1 or @p i2 lie outside the
!! bounds of the array.
procedure, public :: swap_items => list_swap
!> @brief Sorts an array into ascending order.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine sort(class(list) this, procedure(compare_items) fcn)
!! @endcode
!!
!! @param[in,out] this The list object.
!! @param[in] fcn The function to use to make the comparison.
procedure, public :: sort => list_sort
!> @brief Stores an item in the collection. If the collection isn't
!! large enough to accomodate, it is automatically resized to
!! accomodate.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine store(class(list) this, integer(int32) i, class(*) x, class(errors) err)
!! @endcode
!!
!! @param[in,out] this The list object.
!! @param[in] i The index of the item.
!! @param[in] x The object to store.
!! @param[in,out] err An optional errors-based object that if provided
!! can be used to retrieve information relating to any errors
!! encountered during execution. If not provided, a default
!! implementation of the errors class is used internally to provide
!! error handling. Possible errors and warning messages that may be
!! encountered are as follows.
!! - FCORE_OUT_OF_MEMORY_ERROR: Occurs if there is insufficient memory.
procedure, private :: store => list_store
end type
!> @brief Defines a key-value pair.
type key_value_pair
!> @brief The key
integer(int64) :: key
!> A pointer to a polymorphic variable allowing storage of any type.
class(*), pointer :: value => null()
end type
!> @brief Defines a generic dictionary.
type dictionary
private
!> @brief A collection of key_value_pair objects.
type(list) :: m_list
contains
!> @brief Cleans up resources held by the dictionary.
final :: dict_final
!> @brief Gets the number of items in the dictionary.
!!
!! @par Syntax
!! @code{.f90}
!! integer(int32) get_count(class(dictionary) this)
!! @endcode
!!
!! @param[in] this The dictionary object.
!! @return The number of items in the dictionary.
procedure, public :: get_count => dict_get_count
!> @brief Determines if the dictionary contains the specified key.
!!
!! @par Syntax
!! @code{.f90}
!! logical contains_key(class(dictionary) this, integer(int64) key)
!! @endcode
!!
!! @param[in] this The dictionary object.
!! @param[in] key The desired key.
!!
!! @return Returns true if the dictionary contains @p key; else, returns
!! false.
procedure, public :: contains_key => dict_contains_key
!> @brief Gets the requested item from the dictionary.
!!
!! @par Syntax
!! @code{.f90}
!! class(*) pointer get(class(dictionary) this, integer(int64) key)
!! @endcode
!!
!! @param[in] this The dictionary object.
!! @param[in] key The key of the desired object.
!!
!! @return A pointer to the requested item. A null pointer is returned
!! if the key doesn't exist in the collection.
procedure, public :: get => dict_get
!> @brief Sets an item into the dictionary.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine set(class(dictionary) this, integer(int64) key, class(*) item, class(errors) err)
!! @endcode
!!
!! @param[in,out] this The dictionary object.
!! @param[in] key The key.
!! @param[in] item The item to place into the dictionary.
!! @param[in,out] err An optional errors-based object that if provided
!! can be used to retrieve information relating to any errors
!! encountered during execution. If not provided, a default
!! implementation of the errors class is used internally to provide
!! error handling. Possible errors and warning messages that may be
!! encountered are as follows.
!! - FCORE_OUT_OF_MEMORY_ERROR: Occurs if there is insufficient memory.
!! - FCORE_NONEXISTENT_KEY_ERROR: Occurs if @p key could not be found.
procedure, public :: set => dict_set
!> @brief Adds a new key-value pair to the dictionary.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine add(class(dictionary) this, integer(int64) key, class(*) item, class(errors) err)
!! @endcode
!!
!! @param[in,out] this The dictionary object.
!! @param[in] key The key.
!! @param[in] item The item to add.
!! @param[in,out] err An optional errors-based object that if provided
!! can be used to retrieve information relating to any errors
!! encountered during execution. If not provided, a default
!! implementation of the errors class is used internally to provide
!! error handling. Possible errors and warning messages that may be
!! encountered are as follows.
!! - FCORE_OUT_OF_MEMORY_ERROR: Occurs if there is insufficient memory.
!! - FCORE_EXISTING_KEY_ERROR: Occurs if the key already exists within the
!! collection.
procedure, public :: add => dict_add
!> @brief Removes an item from the dictionary.
!!
!! @par Syntax
!! @code{.f90}
!! logical remove(class(dictionary) this, integer(int64) key)
!! @endcode
!!
!! @param[in,out] this The dictionary object.
!! @param[in] key The key.
!! @return Returns true if the item was found within the dictionary and
!! removed; else, returns false if the key was not found in the
!! dictionary.
procedure, public :: remove => dict_remove
!> @brief Clears the contents of the entire dictionary.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine clear(class(dictionary) this)
!! @endcode
!!
!! @param[in,out] this The dictionary object.
procedure, public :: clear => dict_clear
!> @brief Returns the index in the underlying collection of the entry
!! that contains the matching key.
!!
!! @par Syntax
!! @code{.f90}
!! integer(int32) index_of_key(class(dictionary) this, integer(int64) key)
!! @endcode
!!
!!
!! @param[in] this The dictionary object.
!! @param[in] key The desired key.
!!
!! @return If found, the index of the matching entry in the underlying
!! collection. If not found, a value of 0 is returned.
procedure, private :: index_of_key => dict_index_of_key
end type
!> @brief A hash code generation object.
!!
!! @par Remarks
!! This object uses the CRC-32 code provided by zmiimz, and is available
!! at https://github.com/zmiimz/fortran_notes.
type hash_code
private
integer(int64), dimension(256) :: table
logical :: have_table = .false.
integer(int64) :: crcpoly = int(z'edb88320', int64)
integer(int64) :: crcinv = int(z'5b358fd3', int64)
integer(int64) :: initxor = int(z'ffffffff', int64)
integer(int64) :: finalxor = int(z'ffffffff', int64)
contains
!> @brief Initializes the hash code generator object.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine initialize(class(hash_code) this)
!! @endcode
!!
!! @param[in,out] this The hash_code object.
procedure, public :: initialize => hc_init
!> @brief Gets a unique hash code for the supplied string.
!!
!! @par Syntax
!! @code{.f90}
!! integer(int64) get(class(hash_code) this, character(len = *) str)
!! @endcode
!!
!! @param[in,out] this The hash_code object.
!! @param[in] str The string to hash.
!!
!! @return The hash code for @p str.
procedure, public :: get => hc_get
end type
!> @brief Defines a generic linked-list container.
type linked_list
private
!> @brief The number of nodes in the container.
integer(int32) :: m_nodeCount = 0
!> @brief A pointer to the first node in the container.
type(node), pointer :: m_first => null()
!> @brief A pointer to the last node in the container.
type(node), pointer :: m_last => null()
!> @brief A pointer to the current node. - for iteration purposes
type(node), pointer :: m_current => null()
contains
!> @brief Cleans up resources held by the list.
final :: ll_final
!> @brief Gets the number of items in the list.
!!
!! @par Syntax
!! @code{.f90}
!! integer(int32) get_count(class(linked_list) this)
!! @endcode
!!
!! @param[in] this The linked_list object.
!! @return The number of items in the list.
procedure, public :: get_count => ll_get_count
!> @brief Moves to the first item in the list.
!!
!! @par Syntax
!! @code{.f90}
!! logical move_to_first(class(linked_list) this)
!! @endcode
!!
!! @param[in,out] this The linked_list object.
!! @return Returns true if the move was successful (there was something
!! defined to move to); else, false if the move was not completed.
procedure, public :: move_to_first => ll_move_to_first
!> @brief Moves to the last item in the list.
!!
!! @par Syntax
!! @code{.f90}
!! logical move_to_last(class(linked_list) this)
!! @endcode
!!
!! @param[in,out] this The linked_list object.
!! @return Returns true if the move was successful (there was something
!! defined to move to); else, false if the move was not completed.
procedure, public :: move_to_last => ll_move_to_last
!> @brief Moves to the next item in the list.
!!
!! @par Syntax
!! @code{.f90}
!! logical move_to_next(class(linked_list) this)
!! @endcode
!!
!! @param[in,out] this The linked_list object.
!! @return Returns true if the move was successful (there was something
!! defined to move to); else, false if the move was not completed.
procedure, public :: move_to_next => ll_move_to_next
!> @brief Moves to the previous item in the list.
!!
!! @par Syntax
!! @code{.f90}
!! logical move_to_previous(class(linked_list) this)
!! @endcode
!!
!! @param[in,out] this The linked_list object.
!! @return Returns true if the move was successful (there was something
!! defined to move to); else, false if the move was not completed.
procedure, public :: move_to_previous => ll_move_to_previous
!> @brief Clears the entire contents of the list.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine clear(class(linked_list) this)
!! @endcode
!!
!! @param[in] this The linked_list object.
procedure, public :: clear => ll_clear
!> @brief Pushes a new item onto the end of the list.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine push(class(linked_list) this, class(*) x, class(errors) err)
!! @endcode
!!
!! @param[in,out] this The linked_list object.
!! @param[in] x The object to store.
!! @param[in,out] err An optional errors-based object that if provided
!! can be used to retrieve information relating to any errors
!! encountered during execution. If not provided, a default
!! implementation of the errors class is used internally to provide
!! error handling. Possible errors and warning messages that may be
!! encountered are as follows.
!! - FCORE_OUT_OF_MEMORY_ERROR: Occurs if there is insufficient memory.
procedure, public :: push => ll_push
!> @brief Pops the last item off of the list.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine pop(class(linked_list) this)
!! @endcode
!!
!! @param[in,out] this The linked_list object.
procedure, public :: pop => ll_pop
!> @brief Gets a pointer to the current item.
!!
!! @par Syntax
!! @code{.f90}
!! class(*), pointer get(class(linked_list) this)
!! @endcode
!!
!! @param[in] this The linked_list object.
!! @return The requested pointer.
procedure, public :: get => ll_get_item
!> @brief Sets an item into the list at the current location.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine set(class(linked_list) this, class(*) x, class(errors) err)
!! @endcode
!!
!! @param[in,out] this The linked_list object.
!! @param[in] x The item to place in the list.
!! @param[in,out] err An optional errors-based object that if provided
!! can be used to retrieve information relating to any errors
!! encountered during execution. If not provided, a default
!! implementation of the errors class is used internally to provide
!! error handling. Possible errors and warning messages that may be
!! encountered are as follows.
!! - FCORE_OUT_OF_MEMORY_ERROR: Occurs if there is insufficient memory.
procedure, public :: set => ll_set_item
!> @brief Tests to see if the specified item exists in the list.
!!
!! @par Syntax
!! @code{.f90}
!! logical contains(class(linked_list) this, class(*) item, procedure(items_equal) fcn)
!! @endcode
!!
!! @param[in,out] this The linked_list object.
!! @param[in] item The item to search for.
!! @param[in] fcn A pointer to the routine used to compare items.
!! @return Returns true if @p item is found; else, false.
procedure, public :: contains => ll_contains
!> @brief Moves to the first occurrence of the item that matches the
!! specified criteria. If no match is found the move does not happen.
!!
!! @par Syntax
!! @code{.f90}
!! logical move_to(class(linked_list) this, class(*) item, procedure(items_equal) fcn)
!! @endcode
!!
!! @param[in,out] this The linked_list object.
!! @param[in] item The item to search for.
!! @param[in] fcn A pointer to the routine used to compare items.
!! @return Returns true if the item was found and the move was
!! successful; else, false if the item wasn't found and the move did
!! not occur.
procedure, public :: move_to => ll_move_to_matching
end type
! ------------------------------------------------------------------------------
!> @brief Defines a table convenient for storing mixed-type data.
type data_table
private
!> @brief The data table.
type(container), allocatable, dimension(:,:) :: m_table
!> @brief The headers.
type(string), allocatable, dimension(:) :: m_headers
contains
final :: dt_final
!> @brief Clears the entire contents of the data_table.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine clear(class(data_table) this)
!! @endcode
!!
!! @param[in,out] this The data_table object.
procedure, public :: clear => dt_clear
!> @brief Gets the number of rows in the table.
!!
!! @par Syntax
!! @code{.f90}
!! integer(int32) get_row_count(class(data_table) this)
!! @endcode
!!
!! @param[in] this The data_table object.
!! @return The number of rows in the table.
procedure, public :: get_row_count => dt_get_row_count
!> @brief Gets the number of columns in the table.
!!
!! @par Syntax
!! @code{.f90}
!! integer(int32) get_column_count(class(data_table) this)
!! @endcode
!!
!! @param[in] this The data_table object.
!! @return The number of columns in the table.
procedure, public :: get_column_count => dt_get_column_count
!> @brief Initializes the data table. Notice, if the data table was
!! already initialized, this routine will clear the existing table
!! and construct a new table as requested.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine initialize(class(data_table) this, integer(int32) m, integer(int32) n, class(errors) err)
!! @endcode
!!
!! @param[in,out] this The data_table object.
!! @param[in] m The number of rows (must be at least 1).
!! @param[in] n The number of columns (must be at least 1).
!! @param[in,out] err An optional errors-based object that if provided
!! can be used to retrieve information relating to any errors
!! encountered during execution. If not provided, a default
!! implementation of the errors class is used internally to provide
!! error handling. Possible errors and warning messages that may be
!! encountered are as follows.
!! - FCORE_OUT_OF_MEMORY_ERROR: Occurs if there is insufficient memory.
!! - FCORE_INVALID_INPUT_ERROR: Occurs if @p m or @p n is less than
!! or equal to zero.
procedure, public :: initialize => dt_initialize
!> @brief Gets an item from the table.
!!
!! @par Syntax
!! @code{.f90}
!! class(*) pointer get(class(data_table) this, integer(int32) i, integer(int32) j, class(errors) err)
!! @endcode
!!
!! @param[in] this The data_table object.
!! @param[in] i The row index.
!! @param[in] j The column index.
!! @param[in,out] err An optional errors-based object that if provided
!! can be used to retrieve information relating to any errors
!! encountered during execution. If not provided, a default
!! implementation of the errors class is used internally to provide
!! error handling. Possible errors and warning messages that may be
!! encountered are as follows.
!! - FCORE_INDEX_OUT_OF_RANGE_ERROR: Occurs if @p i or @p j are outside
!! the bounds of the table.
!!
!! @return The requested item.
procedure, public :: get => dt_get
!> @brief Sets an item into the table.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine set(class(data_table) this, integer(int32) i, integer(int32) j, class(*) x, class(errors) err)
!! @endcode
!!
!! @param[in,out] this The data_table object.
!! @param[in] i The row index.
!! @param[in] j The column index.
!! @param[in] x The item to set into the table. Notice, a copy is made
!! and the table takes care of management of the memory occupied by
!! the copy.
!! @param[in,out] err An optional errors-based object that if provided
!! can be used to retrieve information relating to any errors
!! encountered during execution. If not provided, a default
!! implementation of the errors class is used internally to provide
!! error handling. Possible errors and warning messages that may be
!! encountered are as follows.
!! - FCORE_NULL_REFERENCE_ERROR: Occurs if the table hasn't yet been
!! initialized.
!! - FCORE_INDEX_OUT_OF_RANGE_ERROR: Occurs if @p i or @p j are outside
!! the bounds of the table.
!! - FCORE_OUT_OF_MEMORY_ERROR: Occurs if there is insufficient memory.
procedure, public :: set => dt_set
!> @brief Inserts a series of rows into the data_table.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine insert_rows(class(data_table) this, integer(int32) rstart, class(*) x(:,:), class(errors) err)
!! @endcode
!!
!! @param[in,out] this The data_table object.
!! @param[in] rstart The index of the row at which the insertion begins.
!! @param[in] x An M-by-N matrix of items to insert into the table. The
!! number of columns (N) must be the same as the number of columns in
!! this table. A copy of each item is made, and the data_table takes
!! care of management of the memory occupied by each copy.
!! @param[in,out] err An optional errors-based object that if provided
!! can be used to retrieve information relating to any errors
!! encountered during execution. If not provided, a default
!! implementation of the errors class is used internally to provide
!! error handling. Possible errors and warning messages that may be
!! encountered are as follows.
!! - FCORE_INDEX_OUT_OF_RANGE_ERROR: Occurs if @p rstart is outside
!! the bounds of the table.
!! - FCORE_ARRAY_SIZE_ERROR: Occurs if @p x does not have the same
!! number of columns as the data_table.
!! - FCORE_OUT_OF_MEMORY_ERROR: Occurs if there is insufficient memory.
procedure, public :: insert_rows => dt_insert_rows
!> @brief Inserts a single row into the data_table.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine insert_row(class(data_table) this, integer(int32) i, class(*) x(:), class(errors) err)
!! @endcode
!!
!! @param[in,out] this The data_table object.
!! @param[in] i The row index where @p x should be inserted into the table.
!! @param[in] x The N-element array where N is equal to the number of
!! columns in this data_table. A copy of each item is made, and the
!! data_table takes care of management of the memory occupied by each
!! copy.
!! @param[in,out] err An optional errors-based object that if provided
!! can be used to retrieve information relating to any errors
!! encountered during execution. If not provided, a default
!! implementation of the errors class is used internally to provide
!! error handling. Possible errors and warning messages that may be
!! encountered are as follows.
!! - FCORE_INDEX_OUT_OF_RANGE_ERROR: Occurs if @p i is outside
!! the bounds of the table.
!! - FCORE_ARRAY_SIZE_ERROR: Occurs if @p x does not have the same
!! number of items as the data_table has columns.
!! - FCORE_OUT_OF_MEMORY_ERROR: Occurs if there is insufficient memory.
procedure, public :: insert_row => dt_insert_row
!> @brief Inserts a series of columns into the data_table.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine insert_columns(class(data_table) this, integer(int32) cstart, class(*) x(:,:), class(errors) err)
!! @endcode
!!
!! @param[in,out] this The data_table object.
!! @param[in] cstart The index of the column at which the insertion
!! begins.
!! @param[in] x An M-by-N matrix of items to insert into the table. The
!! number of rows (M) must be the same as the number of rows in
!! this table. A copy of each item is made, and the data_table takes
!! care of management of the memory occupied by each copy.
!! @param[in,out] err An optional errors-based object that if provided
!! can be used to retrieve information relating to any errors
!! encountered during execution. If not provided, a default
!! implementation of the errors class is used internally to provide
!! error handling. Possible errors and warning messages that may be
!! encountered are as follows.
!! - FCORE_INDEX_OUT_OF_RANGE_ERROR: Occurs if @p cstart is outside
!! the bounds of the table.
!! - FCORE_ARRAY_SIZE_ERROR: Occurs if @p x does not have the same
!! number of rows as the data_table.
!! - FCORE_OUT_OF_MEMORY_ERROR: Occurs if there is insufficient memory.
procedure, public :: insert_columns => dt_insert_columns
!> @brief Inserts a single column into the data_table.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine insert_column(class(data_table) this, integer(int32) i, class(*) x(:), class(errors) err)
!! @endcode
!!
!! @param[in,out] this The data_table object.
!! @param[in] i The column index where @p x should be inserted into
!! the table.
!! @param[in] x The N-element array where N is equal to the number of
!! rows in this data_table. A copy of each item is made, and the
!! data_table takes care of management of the memory occupied by each
!! copy.
!! @param[in,out] err An optional errors-based object that if provided
!! can be used to retrieve information relating to any errors
!! encountered during execution. If not provided, a default
!! implementation of the errors class is used internally to provide
!! error handling. Possible errors and warning messages that may be
!! encountered are as follows.
!! - FCORE_INDEX_OUT_OF_RANGE_ERROR: Occurs if @p i is outside
!! the bounds of the table.
!! - FCORE_ARRAY_SIZE_ERROR: Occurs if @p x does not have the same
!! number of items as the data_table has rows.
!! - FCORE_OUT_OF_MEMORY_ERROR: Occurs if there is insufficient memory.
procedure, public :: insert_column => dt_insert_column
!> @brief Appends a series of rows onto the end of the table.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine append_rows(class(data_table) this, class(*) x(:,:), class(errors) err)
!! @endcode
!!
!! @param[in,out] this The data_table object.
!! @param[in] x An M-by-N matrix of items to append onto the table. The
!! number of columns (N) must be the same as the number of columns in
!! this table. A copy of each item is made, and the data_table takes
!! care of management of the memory occupied by each copy.
!! @param[in,out] err An optional errors-based object that if provided
!! can be used to retrieve information relating to any errors
!! encountered during execution. If not provided, a default
!! implementation of the errors class is used internally to provide
!! error handling. Possible errors and warning messages that may be
!! encountered are as follows.
!! - FCORE_ARRAY_SIZE_ERROR: Occurs if @p x does not have the same
!! number of columns as the data_table.
!! - FCORE_OUT_OF_MEMORY_ERROR: Occurs if there is insufficient memory.
procedure, public :: append_rows => dt_append_rows
!> @brief Appends a single row onto the end of the data_table.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine append_row(class(data_table) this, class(*) x(:), class(errors) err)
!! @endcode
!!
!! @param[in,out] this The data_table object.
!! @param[in] x The N-element array where N is equal to the number of
!! columns in this data_table. A copy of each item is made, and the
!! data_table takes care of management of the memory occupied by each
!! copy.
!! @param[in,out] err An optional errors-based object that if provided
!! can be used to retrieve information relating to any errors
!! encountered during execution. If not provided, a default
!! implementation of the errors class is used internally to provide
!! error handling. Possible errors and warning messages that may be
!! encountered are as follows.
!! - FCORE_ARRAY_SIZE_ERROR: Occurs if @p x does not have the same
!! number of items as the data_table has columns.
!! - FCORE_OUT_OF_MEMORY_ERROR: Occurs if there is insufficient memory.
procedure, public :: append_row => dt_append_row
!> @brief Appends a series of columns onto the end of the data_table.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine append_columns(class(data_table) this, class(*) x(:,:), class(errors) err)
!! @endcode
!!
!! @param[in,out] this The data_table object.
!! @param[in] x An M-by-N matrix of items to insert into the table. The
!! number of rows (M) must be the same as the number of rows in
!! this table. A copy of each item is made, and the data_table takes
!! care of management of the memory occupied by each copy.
!! @param[in,out] err An optional errors-based object that if provided
!! can be used to retrieve information relating to any errors
!! encountered during execution. If not provided, a default
!! implementation of the errors class is used internally to provide
!! error handling. Possible errors and warning messages that may be
!! encountered are as follows.
!! - FCORE_ARRAY_SIZE_ERROR: Occurs if @p x does not have the same
!! number of rows as the data_table.
!! - FCORE_OUT_OF_MEMORY_ERROR: Occurs if there is insufficient memory.
procedure, public :: append_columns => dt_append_columns
!> @brief Appends a single column onto the end of the data_table.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine append_column(class(data_table) this, class(*) x(:), class(errors) err)
!! @endcode
!!
!! @param[in,out] this The data_table object.
!! @param[in] x The N-element array where N is equal to the number of
!! rows in this data_table. A copy of each item is made, and the
!! data_table takes care of management of the memory occupied by each
!! copy.
!! @param[in,out] err An optional errors-based object that if provided
!! can be used to retrieve information relating to any errors
!! encountered during execution. If not provided, a default
!! implementation of the errors class is used internally to provide
!! error handling. Possible errors and warning messages that may be
!! encountered are as follows.
!! - FCORE_ARRAY_SIZE_ERROR: Occurs if @p x does not have the same
!! number of items as the data_table has rows.
!! - FCORE_OUT_OF_MEMORY_ERROR: Occurs if there is insufficient memory.
procedure, public :: append_column => dt_append_column
!> @brief Removes a series of rows from the data_table.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine remove_rows(class(data_table) this, integer(int32) rstart, integer(int32) nrows, class(errors) err)
!! @endcode
!!
!! @param[in,out] this The data_table object.
!! @param[in] rstart The row index at which to start removing rows.
!! @param[in] nrows The number of rows to remove (must be greater than
!! 0).
!! @param[in,out] err An optional errors-based object that if provided
!! can be used to retrieve information relating to any errors
!! encountered during execution. If not provided, a default
!! implementation of the errors class is used internally to provide
!! error handling. Possible errors and warning messages that may be
!! encountered are as follows.
!! - FCORE_OUT_OF_MEMORY_ERROR: Occurs if there is insufficient memory.
!! - FCORE_UNINITIALIZED_OBJECT_ERROR: Occurs if the table has not
!! been initialized.
!! - FCORE_INVALID_INPUT_ERROR: Occurs if @p nrows is less than 1, or
!! if the @p nrows is too large resulting in removing more rows
!! than are available in the table.
!! - FCORE_INDEX_OUT_OF_RANGE_ERROR: Occurs if @p rstart is outside
!! the bounds of the table.
procedure, public :: remove_rows => dt_remove_rows
!> @brief Removes a series of columns from the data_table.
!!
!! @par Syntax
!! @code{.f90}
!! subroutine remove_columns(class(data_table) this, integer(int32) cstart, integer(int32) ncols, class(errors) err)
!! @endcode
!!
!! @param[in,out] this The data_table object.
!! @param[in] cstart The column index at which to start removing
!! columns.
!! @param[in] ncols The number of columns to remove (must be greater
!! than 0).
!! @param[in,out] err An optional errors-based object that if provided
!! can be used to retrieve information relating to any errors
!! encountered during execution. If not provided, a default
!! implementation of the errors class is used internally to provide
!! error handling. Possible errors and warning messages that may be
!! encountered are as follows.
!! - FCORE_OUT_OF_MEMORY_ERROR: Occurs if there is insufficient memory.
!! - FCORE_UNINITIALIZED_OBJECT_ERROR: Occurs if the table has not
!! been initialized.
!! - FCORE_INVALID_INPUT_ERROR: Occurs if @p ncols is less than 1, or
!! if the @p ncols is too large resulting in removing more columns
!! than are available in the table.
!! - FCORE_INDEX_OUT_OF_RANGE_ERROR: Occurs if @p cstart is outside
!! the bounds of the table.
procedure, public :: remove_columns => dt_remove_columns
!> @brief Tests to see if the data_table contains the specified item.
!!