Very basic hash table implementation for a modest number of elements that stores only pointers to values.
Generic interface to hash table get functions.
Returns pointer to element in hash table by index loc
. On error,
value
will point to null.
The function returns the following error codes:
E_BOUNDS
if the index is outside the array bounds.E_NULL
if the hash table value pointer is not associated.Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(hash_table_type), | intent(inout) | :: | hash_table |
Hash table type. |
||
integer, | intent(in) | :: | loc |
Hash value index. |
||
class(*), | intent(out), | pointer | :: | value |
Associated value. |
Returns pointer to element in hash table by key
. On error, value
will point to null. The intrinsic findloc()
should be sufficient for
a small number of elements. For larger hash tables, buckets have to be
added.
The function returns the following error codes:
E_NOT_FOUND
if the key was not found.E_NULL
if the hash table value pointer is not associated.Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(hash_table_type), | intent(inout) | :: | hash_table |
Hash table type. |
||
character(len=*), | intent(in) | :: | key |
Hash table key. |
||
class(*), | intent(out), | pointer | :: | value |
Associated value. |
Container that keeps generic pointer to hash table value.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
class(*), | public, | pointer | :: | ptr | => | null() |
Opaque hash table type of key-value pairs.
Create a new hash table with maximum number of entries.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(hash_table_type), | intent(inout) | :: | hash_table |
Hash table type. |
||
integer, | intent(in) | :: | max_entries |
Maximum number of entries. |
Returns .true.
if hash table arrays have been allocated.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(hash_table_type), | intent(inout) | :: | hash_table |
Hash table type. |
Adds element to hash table, or replaces existing value. This function does not resolve hash collisions.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(hash_table_type), | intent(inout) | :: | hash_table |
Hash table type. |
||
character(len=*), | intent(in) | :: | key |
Hash table key. |
||
class(*), | intent(inout), | target | :: | value |
Associated value. |
Finalises hash table. If the hash table items contain allocatable data types, you have to deallocate them manually beforehand.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(hash_table_type), | intent(inout) | :: | hash_table |
Hash table type. |
Returns cursor position in n
and maximum size of hash table in
max_size
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(hash_table_type), | intent(inout) | :: | hash_table |
Hash table type. |
||
integer, | intent(out), | optional | :: | n |
Current number of values. |
|
integer, | intent(out), | optional | :: | max_size |
Max. number of values. |