Module stack3_mod
Uses:
module kinds_mod
Types:
public type stack3
Subroutines and functions:
private subroutine stack3_create (st, inisize)
private subroutine stack3_delete (st)
private subroutine stack3_trim (st)
private subroutine stack3_push (st, v)
private subroutine stack3_move (st_src, st_dest)
private subroutine stack3_remove_duplicates (st)
A simple stack of 3D coordinates (3 integers) which grows ad infinutum if required.
Data is stored in a single contiguous array.
type(stack3) :: st
call stack3_create(st,10)
stack3_push(st,(/4,1,2/))
stack3_push(st,(/7,0,5/))
print *,'first element on stack is:',st%a(:,1)
call stack3_delete(st)
Clear the stack, i.e. set topmost element = bottom.
The size of the storage array is left unchanged.
st%pos = 0
Get element from stack.
The index must be in the interval 1 <= i <= size(st%a).
st%a(:,i)
Add
use stack3_mod
to your module/subroutine and
include 'stack3.incf'
after the contains statement to enable inlining of the stack3 routines.
Author: Matthias Lieber
Description of Types
stack3
public type stack3
integer (kind=i_k), pointer, dimension (:,:) :: a => null ()
integer (kind=i_k) :: pos = 0
end type stack3
Components:
a | the actual data is stored in a |
pos | position of topmost element in the stack |
Description of Subroutines and Functions
stack3_create
private subroutine stack3_create (st, inisize)
type (stack3), intent(inout) :: st
integer (kind=i_k), intent(in) :: inisize
end subroutine stack3_create
Parameters:
st | the stack3 |
inisize | initial size of array |
Create a stack3 or reallocate at given size.
If the stack3 is already allocated, the function reallocates
the stack3 only in the case, that the current stack size is
less then inisize. Otherwise the stack3 is only cleared,
i.e. st%pos is set to 0.
stack3_delete
private subroutine stack3_delete (st)
type (stack3), intent(inout) :: st
end subroutine stack3_delete
Parameters:
Delete the stack3 and all of its memory.
stack3_trim
private subroutine stack3_trim (st)
type (stack3), intent(inout) :: st
end subroutine stack3_trim
Parameters:
Reallocate the stack3 array to exactly fit the required size.
stack3_push
private subroutine stack3_push (st, v)
type (stack3), intent(inout) :: st
integer (kind=i_k), intent(in), dimension (3) :: v
end subroutine stack3_push
Parameters:
st | the stack3 |
v | value to push to stack3 |
Push a new element to the top of the stack3.
The storage array will be enlarged by a factor of two if required.
stack3_move
private subroutine stack3_move (st_src, st_dest)
type (stack3), intent(inout) :: st_src
type (stack3), intent(inout) :: st_dest
end subroutine stack3_move
Parameters:
st_src | the stack3 |
st_dest | the stack3 |
Move (shallow copy) the data from
st_src to
st_dest.
All data contained in
st_dest will be removed.
st_src will be empty on return.
stack3_remove_duplicates
private subroutine stack3_remove_duplicates (st)
type (stack3), intent(inout) :: st
end subroutine stack3_remove_duplicates
Parameters:
Remove duplicates from
st, this is damn costly