Class that act as stacks, queues, and priority queues like idDynamicArray_Class but with an added integer index so that 'lists' of both a key and value can be maintained. These classes use dynamically allocated contiguous blocks of memory to store a list of numbers. The queues can be sorted to become priority queues and use binary searches to quickly insert new numbers. If the allocated memory is filled, the available space is doubled. Memory is only reallocated to a smaller size, if the utilization is a quarter of that allocated. The array can be specified as fixed, so that no reallocation occurs. This is useful for heaps of given like k nearest neighbours, or k smallest.
Example usage
program dynamicArray_test use variableKind, only: i32 use idArgDynamicArray_Class, only: idArgDynamicArray implicit none type(idArgDynamicArray) :: da, da2 integer(i32) :: ia da = idArgDynamicArray(10) call da%insertAt(1, 10, 10_i64) call da%insertAt(1, 20, 20_i64) call da%prepend(30, 30_i64) call da%append(40, 40_i64) call da%remove(2) call da%tighten() da2 = da da2%v%values(2) = 50_i64 call da%deallocate() call da2%deallocate() da = idArgDynamicArray(3, sorted=.true.) call da%insertSorted(1, 20_i64) call da%insertSorted(2, 30_i64) call da%insertSorted(3, 10_i64) ia = da%locationOf(20_i64) ia = da%argOf(20_i64) call da%insertSortedUnique(4, 10_i64) call da%insertSortedUnique(4, 15_i64) call da%deallocate() da = idArgDynamicArray(3, sorted=.true., fixed=.true.) call da%insertSorted(1, 20_i64) call da%insertSorted(2, 30_i64) call da%insertSorted(3, 10_i64) ia = da%locationOf(20_i64) ia = da%argOf(20_i64) call da%insertSortedUnique(4, 10_i64) call da%insertSortedUnique(4, 15_i64) call da%deallocate() end program
Overloaded by interface [[idArgDynamicArray(type)]]
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i32), | intent(in), | optional | :: | M | ||
logical, | intent(in), | optional | :: | sorted | ||
logical, | intent(in), | optional | :: | fixed |
Overloaded by interface [[idArgDynamicArray(type)]]
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=i32), | intent(in) | :: | i(:) | |||
integer(kind=i64), | intent(in) | :: | values(:) | |||
integer(kind=i32), | intent(in), | optional | :: | M | ||
logical, | intent(in), | optional | :: | sorted | ||
logical, | intent(in), | optional | :: | fixed |
Class that act as stacks, queues, and priority queues. See idArgDynamicArray_Class for more information on how to use this class.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
type(iDynamicArray), | public | :: | i | Argument of the values. |
|||
type(idDynamicArray), | public | :: | v | Values. |
private function init_idArgDynamicArray_i1(M, sorted, fixed) | Overloaded by interface [[idArgDynamicArray(type)]] |
private function init_idArgDynamicArray_id1D(i, values, M, sorted, fixed) | Overloaded by interface [[idArgDynamicArray(type)]] |
procedure, public :: append => append_idArgDynamicArray | idArgDynamicArray%append() - Append a value to the end of the dynamic array. Will change a sorted dynamic array to unsorted. |
procedure, public :: argOf => argOf_idArgDynamicArray | idArgDynamicArray%argOf() - Get the argument of a value in a sorted dynamic array |
procedure, public :: deallocate => deallocate_idArgDynamicArray | idArgDynamicArray%%deallocate() - Deallocate a dynamic array. |
procedure, public :: insertAt => insertAt_idArgDynamicArray | idArgDynamicArray%insertAt() - Insert a value at a given index. |
procedure, public :: insertSorted => insertSorted_idArgDynamicArray | idArgDynamicArray%insertSorted() - Insert a value into a sorted dynamic array. |
procedure, public :: insertSortedUnique => insertSortedUnique_idArgDynamicArray | idArgDynamicArray%insertSortedUnique() - Inserts only unique numbers into a dynamic array. |
procedure, public :: isEmpty => isEmpty_idArgDynamicArray | idArgDynamicArray%isEmpty() - True if the array is empty. |
procedure, public :: isFilled => isFilled_idArgDynamicArray | idArgDynamicArray%isFilled() - True if the allocated memory has been filled. |
procedure, public :: locationOf => locationOf_idArgDynamicArray | idArgDynamicArray%locationOf() - Get the location of a value in a sorted dynamic array. |
procedure, public :: prepend => prepend_idArgDynamicArray | idArgDynamicArray%prepend() - Prepend a value to the start of the dynamic array. Only for unsorted dynamic arrays |
procedure, public :: remove => remove_idArgDynamicArray | idArgDynamicArray%remove() - Remove an element from the array. |
procedure, public :: tighten => tighten_idArgDynamicArray | idArgDynamicArray%tighten() - Removes excess buffer memory and trims it to the current length. |