FMUTIL
0.1
Fortran Miscellaneous UTILities
|
Vector module. More...
Data Types | |
interface | assign_vecelem |
Interface for the procedure invoked during assignment of VecElem. More... | |
type | bkt |
Internal Bucket sturcture. Each bucket can contain a number of elements. More... | |
type | bktptr |
Pointer to a single bucket. More... | |
type | invalidvecelem |
Invalid Vector element type that is returned in case of an exception. More... | |
type | vecelem |
Abstract vector element type that must be extended by user to define the type for the Vector elements. More... | |
type | vector |
Vector type. More... | |
Functions/Subroutines | |
subroutine | initialize (me, NewBktsToAllocate, BktCap, MoldElem) |
Optional procedure to initialize Vector type and allocate internal storage. It can be used to modify the default settings for storage allocation. If Init is not called first, Vector is initialized using the default settings and storage is allocated on the first call to push data in the Vector. This procedure will only change the number of new buckets to create on Vector capacity increase if it is invoked after the first call to push data in the Vector. More... | |
pure integer function | vec_size (me) |
Returns the total number of allocated elements in the Vector. More... | |
pure integer function | capacity (me) |
Returns the total number of elements that can be saved in the Vector without any need for increasing the memory footprint. More... | |
pure integer function | nusedbkts (me) |
Returns the total number of internal data buckets allocated by the Vector. Each bucket can contain multiple elements defined by its capacity. More... | |
subroutine | reserve (me, n) |
Increases the capcity of Vector to 'n' if the current capacity is smaller than 'n'. More... | |
subroutine | shrinktofit (me) |
Deallocate unused buckets to make Capacity as close to Size as possible. More... | |
class(vecelem) function, pointer | elem_at (me, Index) |
Returns a pointer to the element with the requested index (1-based) Pointer will not be associated in case of an exception. More... | |
class(vecelem) function, allocatable | elem_front (me) |
Returns the element with the index=1. More... | |
class(vecelem) function, allocatable | elem_back (me) |
Returns the last element in the Vector. More... | |
class(vecelem) function, dimension(:), allocatable | vec_slice (me, lower, upper, stride) |
Returns the element array within the requested lower and upper bounds. This is inefficient as it copies the requested slice of the Vector in an array and returns it. If bounds result in zero-length slice, an empty array of VecElem type is returned. More... | |
class(vecelem) function, dimension(:), pointer | bkt_slice (me, lower, upper) |
Returns a pointer to the Vector slice specified using the user-specified lower and upper bounds. If the requested slice is beyond the extent of the data bucket that contains the element corresponding to the lower bound, then the data array is truncated at the bucket boundary and the upper bound is updated to indicate the actual upper bound of data that can be referenced using the returned pointer. This is an efficient method as no copying of data is done. In case of an exception, the returned pointer will not be associated. More... | |
integer function | push_back (me, velem) |
Function to add an element at the back of the vector. More... | |
class(vecelem) function, allocatable | pop_back (me) |
Function to extract the last element of the vector. More... | |
subroutine | elem_insert (me, pos, NewElems, count) |
Inserts the element/elements at the given index and relocate existing elements at the later indices. Very inefficient way to add elements to Vector unless elements are inserted after the last element. More... | |
subroutine | elem_erase (me, lower, upper) |
Delete the element/elements between and including lower and upper bounds. The elements are moved to fill up empty locations. Very inefficient way to delete elements from Vector. More... | |
subroutine | clear (me) |
Clear the contents of Vector but the bucket memory is not deallocated. More... | |
subroutine | create_newbkts (me, NumBkts) |
Subroutine to allocate storage for a new bucket. More... | |
pure subroutine | index2bkt (me, Index, Bkt, BktOffset) |
Converts Vector index to bucket number and offset into the bucket. More... | |
subroutine | assign_invalidelem (lhs, rhs) |
subroutine | assignvector (lhs, rhs) |
Subroutine for Vector assignment operator. More... | |
subroutine | destroy (me) |
Destructor. More... | |
subroutine | bktinit (me, status, cap, mold_elem) |
Bucket Type Methods. More... | |
subroutine | add_bktelem (me, offset, elem) |
subroutine | del_bktelem (me, offset) |
subroutine | bktclear (me) |
class(vecelem) function, pointer | bktelem (me, offset) |
class(vecelem) function, dimension(:), pointer | bktsliceptr (me, start_ind, end_ind) |
pure logical function | is_bktempty (me) |
pure integer function | bktsz (me) |
Variables | |
integer, parameter | default_bktcap = 3 |
Default capacity of internal buckets. More... | |
integer, parameter | default_newbktsallocated = 2 |
Default number of buckets to create on vector capacity increase. More... | |
Vector module.
This module provides the Vector data structure (similar to C++ STL Vector) represented internally using an array of buckets, which is again an array.
|
private |
Definition at line 942 of file vector.f90.
|
private |
Definition at line 874 of file vector.f90.
|
private |
Subroutine for Vector assignment operator.
Definition at line 882 of file vector.f90.
Referenced by vectors::vector::assignment().
|
private |
Returns a pointer to the Vector slice specified using the user-specified lower and upper bounds. If the requested slice is beyond the extent of the data bucket that contains the element corresponding to the lower bound, then the data array is truncated at the bucket boundary and the upper bound is updated to indicate the actual upper bound of data that can be referenced using the returned pointer. This is an efficient method as no copying of data is done. In case of an exception, the returned pointer will not be associated.
[in] | lower | Lower bound as m in MATLAB-like syntax Vector(m:n) |
[in,out] | upper | Upper bound as n in MATLAB-like syntax Vector(m:n)
|
Definition at line 482 of file vector.f90.
|
private |
Definition at line 963 of file vector.f90.
|
private |
Definition at line 972 of file vector.f90.
|
private |
Bucket Type Methods.
Definition at line 928 of file vector.f90.
|
private |
Definition at line 987 of file vector.f90.
|
private |
Definition at line 1018 of file vector.f90.
|
private |
Returns the total number of elements that can be saved in the Vector without any need for increasing the memory footprint.
Definition at line 285 of file vector.f90.
|
private |
Clear the contents of Vector but the bucket memory is not deallocated.
Definition at line 793 of file vector.f90.
|
private |
Subroutine to allocate storage for a new bucket.
Definition at line 810 of file vector.f90.
|
private |
Definition at line 954 of file vector.f90.
|
private |
Destructor.
Definition at line 912 of file vector.f90.
Referenced by vectors::vector::destroy().
|
private |
Returns a pointer to the element with the requested index (1-based) Pointer will not be associated in case of an exception.
[in] | index | Index of the requested element |
Definition at line 366 of file vector.f90.
Returns the last element in the Vector.
Definition at line 401 of file vector.f90.
|
private |
Delete the element/elements between and including lower and upper bounds. The elements are moved to fill up empty locations. Very inefficient way to delete elements from Vector.
[in] | lower | Lower bound |
[in] | upper | Upper bound. All the elements witin lower and upper bounds are deleted. If upper is omitted only a single element with index=lower is deleted. |
Definition at line 716 of file vector.f90.
Returns the element with the index=1.
Definition at line 390 of file vector.f90.
|
private |
Inserts the element/elements at the given index and relocate existing elements at the later indices. Very inefficient way to add elements to Vector unless elements are inserted after the last element.
[in] | pos | Position at which the new elements are inserted (1-based index) Must be >= 1 and <= vector size |
[in] | newelems | Array of New Elements to be inserted |
[in] | count | If provided, NewElems are repeated count times before inserted Total number of elements inserted=count*size(NewElems) Default value is 1. Must be >= 1 |
Definition at line 605 of file vector.f90.
|
private |
Converts Vector index to bucket number and offset into the bucket.
[in] | index | Given index |
[out] | bkt | Bucket number |
[out] | bktoffset | Offset into a bucket |
Definition at line 853 of file vector.f90.
subroutine vectors::initialize | ( | class(vector), intent(inout) | me, |
integer, intent(in), optional | NewBktsToAllocate, | ||
integer, intent(in), optional | BktCap, | ||
class(vecelem), intent(in), optional | MoldElem | ||
) |
Optional procedure to initialize Vector type and allocate internal storage. It can be used to modify the default settings for storage allocation. If Init is not called first, Vector is initialized using the default settings and storage is allocated on the first call to push data in the Vector. This procedure will only change the number of new buckets to create on Vector capacity increase if it is invoked after the first call to push data in the Vector.
[in] | newbktstoallocate | Number of new buckets to allocate on Vector's capacity expansion |
[in] | bktcap | Each bucket capacity. Note that providing a value for the bucket capacity will have effect only if Vector is not already initialized. |
[in] | moldelem | Element mold to use for allocating bucket's memory |
Definition at line 231 of file vector.f90.
|
private |
Definition at line 1007 of file vector.f90.
|
private |
Returns the total number of internal data buckets allocated by the Vector. Each bucket can contain multiple elements defined by its capacity.
Definition at line 297 of file vector.f90.
Function to extract the last element of the vector.
Definition at line 577 of file vector.f90.
|
private |
Function to add an element at the back of the vector.
[in] | velem | Element to add to the vector |
Definition at line 533 of file vector.f90.
|
private |
Increases the capcity of Vector to 'n' if the current capacity is smaller than 'n'.
[in] | n | Reserve space of the minimum 'n' elements |
Definition at line 309 of file vector.f90.
|
private |
Deallocate unused buckets to make Capacity as close to Size as possible.
Definition at line 332 of file vector.f90.
|
private |
Returns the total number of allocated elements in the Vector.
Definition at line 267 of file vector.f90.
|
private |
Returns the element array within the requested lower and upper bounds. This is inefficient as it copies the requested slice of the Vector in an array and returns it. If bounds result in zero-length slice, an empty array of VecElem type is returned.
[in] | lower | Lower bound as m in MATLAB-like syntax Vector(m:n) |
[in] | upper | Upper bound as n in MATLAB-like syntax Vector(m:n)
|
[in] | stride | stride as in MATLAB-like syntax Vector(m:stride:n)
|
Definition at line 419 of file vector.f90.
|
private |
Default capacity of internal buckets.
Definition at line 41 of file vector.f90.
|
private |
Default number of buckets to create on vector capacity increase.
Definition at line 44 of file vector.f90.