FMUTIL  0.1
Fortran Miscellaneous UTILities
vectors Module Reference

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...
 

Detailed Description

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.

Author
Bharat Mahajan
Date
Created: 05/27/2020

Function/Subroutine Documentation

◆ add_bktelem()

subroutine vectors::add_bktelem ( class(bkt), intent(inout)  me,
integer, intent(in)  offset,
class(vecelem), intent(in)  elem 
)
private

Definition at line 942 of file vector.f90.

◆ assign_invalidelem()

subroutine vectors::assign_invalidelem ( class(invalidvecelem), intent(out)  lhs,
class(vecelem), intent(in)  rhs 
)
private

Definition at line 874 of file vector.f90.

◆ assignvector()

subroutine vectors::assignvector ( class(vector), intent(out)  lhs,
class(vector), intent(in)  rhs 
)
private

Subroutine for Vector assignment operator.

Definition at line 882 of file vector.f90.

Referenced by vectors::vector::assignment().

+ Here is the caller graph for this function:

◆ bkt_slice()

class(vecelem) function, dimension(:), pointer vectors::bkt_slice ( class(vector), intent(inout)  me,
integer, intent(in)  lower,
integer, intent(inout)  upper 
)
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.

Parameters
[in]lowerLower bound as m in MATLAB-like syntax Vector(m:n)
[in,out]upperUpper bound as n in MATLAB-like syntax Vector(m:n)
  • Can be a negative integer as '-|a|' where |a| < Vector size
  • It is updated to return the index of the last element that can be referenced using the returned pointer if the Vector slice is not entirely contained in a single bucket.
Returns
Array of VecElem type containing the subsection of Vector

Definition at line 482 of file vector.f90.

◆ bktclear()

subroutine vectors::bktclear ( class(bkt), intent(inout)  me)
private

Definition at line 963 of file vector.f90.

◆ bktelem()

class(vecelem) function, pointer vectors::bktelem ( class(bkt), intent(in), target  me,
integer, intent(in)  offset 
)
private

Definition at line 972 of file vector.f90.

◆ bktinit()

subroutine vectors::bktinit ( class(bkt), intent(inout)  me,
integer, intent(out)  status,
integer, intent(in)  cap,
class(vecelem), intent(in)  mold_elem 
)
private

Bucket Type Methods.

Definition at line 928 of file vector.f90.

◆ bktsliceptr()

class(vecelem) function, dimension(:), pointer vectors::bktsliceptr ( class(bkt), intent(in), target  me,
integer, intent(in)  start_ind,
integer, intent(in)  end_ind 
)
private

Definition at line 987 of file vector.f90.

◆ bktsz()

pure integer function vectors::bktsz ( class(bkt), intent(in)  me)
private

Definition at line 1018 of file vector.f90.

◆ capacity()

pure integer function vectors::capacity ( class(vector), intent(in)  me)
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.

◆ clear()

subroutine vectors::clear ( class(vector), intent(inout)  me)
private

Clear the contents of Vector but the bucket memory is not deallocated.

Definition at line 793 of file vector.f90.

◆ create_newbkts()

subroutine vectors::create_newbkts ( class(vector), intent(inout)  me,
integer, intent(in)  NumBkts 
)
private

Subroutine to allocate storage for a new bucket.

Definition at line 810 of file vector.f90.

◆ del_bktelem()

subroutine vectors::del_bktelem ( class(bkt), intent(inout)  me,
integer, intent(in)  offset 
)
private

Definition at line 954 of file vector.f90.

◆ destroy()

subroutine vectors::destroy ( type(vector), intent(inout)  me)
private

Destructor.

Definition at line 912 of file vector.f90.

Referenced by vectors::vector::destroy().

+ Here is the caller graph for this function:

◆ elem_at()

class(vecelem) function, pointer vectors::elem_at ( class(vector), intent(inout)  me,
integer, intent(in)  Index 
)
private

Returns a pointer to the element with the requested index (1-based) Pointer will not be associated in case of an exception.

Parameters
[in]indexIndex of the requested element
Returns
pointer to the requested element

Definition at line 366 of file vector.f90.

◆ elem_back()

class(vecelem) function, allocatable vectors::elem_back ( class(vector), intent(inout)  me)
private

Returns the last element in the Vector.

Definition at line 401 of file vector.f90.

◆ elem_erase()

subroutine vectors::elem_erase ( class(vector), intent(inout)  me,
integer, intent(in)  lower,
integer, intent(in), optional  upper 
)
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.

Parameters
[in]lowerLower bound
[in]upperUpper 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.

◆ elem_front()

class(vecelem) function, allocatable vectors::elem_front ( class(vector), intent(inout)  me)
private

Returns the element with the index=1.

Definition at line 390 of file vector.f90.

◆ elem_insert()

subroutine vectors::elem_insert ( class(vector), intent(inout)  me,
integer, intent(in)  pos,
class(vecelem), dimension(:), intent(in)  NewElems,
integer, intent(in), optional  count 
)
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.

Parameters
[in]posPosition at which the new elements are inserted (1-based index) Must be >= 1 and <= vector size
[in]newelemsArray of New Elements to be inserted
[in]countIf 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.

◆ index2bkt()

pure subroutine vectors::index2bkt ( class(vector), intent(in)  me,
integer, intent(in)  Index,
integer, intent(out)  Bkt,
integer, intent(out)  BktOffset 
)
private

Converts Vector index to bucket number and offset into the bucket.

Parameters
[in]indexGiven index
[out]bktBucket number
[out]bktoffsetOffset into a bucket

Definition at line 853 of file vector.f90.

◆ initialize()

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.

Parameters
[in]newbktstoallocateNumber of new buckets to allocate on Vector's capacity expansion
[in]bktcapEach bucket capacity. Note that providing a value for the bucket capacity will have effect only if Vector is not already initialized.
[in]moldelemElement mold to use for allocating bucket's memory

Definition at line 231 of file vector.f90.

◆ is_bktempty()

pure logical function vectors::is_bktempty ( class(bkt), intent(in)  me)
private

Definition at line 1007 of file vector.f90.

◆ nusedbkts()

pure integer function vectors::nusedbkts ( class(vector), intent(in)  me)
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.

◆ pop_back()

class(vecelem) function, allocatable vectors::pop_back ( class(vector), intent(inout)  me)
private

Function to extract the last element of the vector.

Definition at line 577 of file vector.f90.

◆ push_back()

integer function vectors::push_back ( class(vector), intent(inout)  me,
class(vecelem), intent(in)  velem 
)
private

Function to add an element at the back of the vector.

Parameters
[in]velemElement to add to the vector
Returns
0 on error, otherwise returns the position of the element

Definition at line 533 of file vector.f90.

◆ reserve()

subroutine vectors::reserve ( class(vector), intent(inout)  me,
integer, intent(in)  n 
)
private

Increases the capcity of Vector to 'n' if the current capacity is smaller than 'n'.

Parameters
[in]nReserve space of the minimum 'n' elements

Definition at line 309 of file vector.f90.

◆ shrinktofit()

subroutine vectors::shrinktofit ( class(vector), intent(inout)  me)
private

Deallocate unused buckets to make Capacity as close to Size as possible.

Definition at line 332 of file vector.f90.

◆ vec_size()

pure integer function vectors::vec_size ( class(vector), intent(in)  me)
private

Returns the total number of allocated elements in the Vector.

Definition at line 267 of file vector.f90.

◆ vec_slice()

class(vecelem) function, dimension(:), allocatable vectors::vec_slice ( class(vector), intent(inout)  me,
integer, intent(in)  lower,
integer, intent(in)  upper,
integer, intent(in), optional  stride 
)
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.

Parameters
[in]lowerLower bound as m in MATLAB-like syntax Vector(m:n)
[in]upperUpper bound as n in MATLAB-like syntax Vector(m:n)
  • Can be a negative integer as '-|a|' where |a| < Vector size
[in]stridestride as in MATLAB-like syntax Vector(m:stride:n)
  • Default is 1
Returns
Array of VecElem type containing the subsection of Vector

Definition at line 419 of file vector.f90.

Variable Documentation

◆ default_bktcap

integer, parameter vectors::default_bktcap = 3
private

Default capacity of internal buckets.

Definition at line 41 of file vector.f90.

◆ default_newbktsallocated

integer, parameter vectors::default_newbktsallocated = 2
private

Default number of buckets to create on vector capacity increase.

Definition at line 44 of file vector.f90.