MODFLOW 6  version 6.7.0.dev0
USGS Modular Hydrologic Model
ptrhashtablemodule Module Reference

Data Types

type  ptrhashtabletype
 HashTable that stores void pointer items. More...
 

Functions/Subroutines

class(iteratortype) function, allocatable iterator (this)
 An iterator used to iterate through the HashTable. More...
 
subroutine add (this, key, val)
 Add a void pointer to the HashTable. More...
 
class(*) function, pointer get (this, key)
 Get a void pointer from the HashTable using a key. More...
 
logical function contains (this, key)
 Boolean indicating if an item exists in the hashtable. More...
 
integer(i4b) function count (this)
 The nummer of items in the HashTable. More...
 
subroutine clear (this)
 Clears the HashTable. More...
 
integer(i4b) function compute_hash (key)
 Compute the hash of a key. More...
 

Variables

integer(i4b), parameter, private hash_size = 4993
 
integer(i4b), parameter, private multiplier = 31
 
integer(i4b), parameter, public bucket_size = 1000
 

Function/Subroutine Documentation

◆ add()

subroutine ptrhashtablemodule::add ( class(ptrhashtabletype), target  this,
character(len=*), intent(in)  key,
class(*), intent(in), pointer  val 
)
private
Parameters
[in]keykey of the item to be added
[in]valvalue to be added

Definition at line 48 of file PtrHashTable.f90.

49  class(PtrHashTableType), target :: this
50  character(len=*), intent(in) :: key !< key of the item to be added
51  class(*), pointer, intent(in) :: val !< value to be added
52  ! -- local
53  type(KeyValueListType), pointer :: bucket !< bucket the key points to
54  integer(I4B) :: hash !< hashed value of the key
55 
56  if (this%contains(key)) then
57  call store_warning( &
58  "Already existing variable being added to the HashTable -"//key)
59  end if
60 
61  hash = compute_hash(key)
62 
63  bucket => this%buckets(hash)
64  call bucket%add(key, val)
65  this%cnt = this%cnt + 1
Here is the call graph for this function:

◆ clear()

subroutine ptrhashtablemodule::clear ( class(ptrhashtabletype), target  this)
private

Loops over all the buckets and clears them.

Definition at line 113 of file PtrHashTable.f90.

114  class(PtrHashTableType), target :: this
115  ! -- local
116  type(KeyValueListType), pointer :: bucket
117  integer(I4B) :: bucket_index
118 
119  do bucket_index = 1, bucket_size
120  bucket => this%buckets(bucket_index)
121  call bucket%clear()
122  end do
123 
124  this%cnt = 0

◆ compute_hash()

integer(i4b) function ptrhashtablemodule::compute_hash ( character(len=*), intent(in)  key)
private

The hash produced will be in the interval 1 - BUCKET_SIZE

Parameters
[in]keythe key
Returns
the hash

Definition at line 131 of file PtrHashTable.f90.

132  character(len=*), intent(in) :: key !< the key
133  integer(I4B) :: hash !< the hash
134  ! -- local
135  integer(I4B) :: i !< character index of the key
136 
137  hash = 0
138  do i = 1, len_trim(key)
139  hash = modulo(multiplier * hash + ichar(key(i:i)), hash_size)
140  end do
141  hash = 1 + modulo(hash, bucket_size)
142 
Here is the caller graph for this function:

◆ contains()

logical function ptrhashtablemodule::contains ( class(ptrhashtabletype), target  this,
character(len=*), intent(in)  key 
)
private
Parameters
[in]keykey of the item to retrieve
Returns
item found

Definition at line 89 of file PtrHashTable.f90.

90  class(PtrHashTableType), target :: this
91  character(len=*), intent(in) :: key !< key of the item to retrieve
92  logical :: res !< item found
93 
94  ! -- local
95  res = associated(this%get(key))
96 

◆ count()

integer(i4b) function ptrhashtablemodule::count ( class(ptrhashtabletype this)
private

Definition at line 102 of file PtrHashTable.f90.

103  class(PtrHashTableType) :: this
104  integer(I4B) :: val
105 
106  val = this%cnt

◆ get()

class(*) function, pointer ptrhashtablemodule::get ( class(ptrhashtabletype), target  this,
character(len=*), intent(in)  key 
)
private
Parameters
[in]keykey of the item to retrieve
Returns
item associated with the key

Definition at line 71 of file PtrHashTable.f90.

72  class(PtrHashTableType), target :: this
73  character(len=*), intent(in) :: key !< key of the item to retrieve
74  class(*), pointer :: val !< item associated with the key
75  ! -- local
76  type(KeyValueListType), pointer :: bucket !< bucket the key points to
77  integer(I4B) :: hash !< hashed value of the key
78 
79  hash = compute_hash(key)
80 
81  bucket => this%buckets(hash)
82  val => bucket%get(key)
83 
Here is the call graph for this function:

◆ iterator()

class(iteratortype) function, allocatable ptrhashtablemodule::iterator ( class(ptrhashtabletype), target  this)
private

Definition at line 38 of file PtrHashTable.f90.

39  class(PtrHashTableType), target :: this
40  class(IteratorType), allocatable :: itr
41 
42  itr = ptrhashtableiteratortype(this%buckets)

Variable Documentation

◆ bucket_size

integer(i4b), parameter, public ptrhashtablemodule::bucket_size = 1000

Definition at line 15 of file PtrHashTable.f90.

15  integer(I4B), parameter, public :: BUCKET_SIZE = 1000

◆ hash_size

integer(i4b), parameter, private ptrhashtablemodule::hash_size = 4993
private

Definition at line 13 of file PtrHashTable.f90.

13  integer(I4B), parameter, private :: HASH_SIZE = 4993

◆ multiplier

integer(i4b), parameter, private ptrhashtablemodule::multiplier = 31
private

Definition at line 14 of file PtrHashTable.f90.

14  integer(I4B), parameter, private :: MULTIPLIER = 31