Insertion-ordered hash map: character(len=*) keys, integer(int64)
values. Default initialisation yields a valid empty map; the first
insert allocates with default capacity if init was never called.
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer(kind=default_int), | private, | allocatable | :: | buckets(:) |
Bucket table; |
||
| integer(kind=default_int), | private | :: | entry_cap | = | 0 |
Allocated length of the entry arrays. |
|
| integer(kind=int64), | private, | allocatable | :: | entry_value(:) |
Value of each entry, in insertion order. |
||
| character(len=1), | private, | allocatable | :: | key_pool(:) |
Packed storage for all key characters. |
||
| integer(kind=default_int), | private, | allocatable | :: | key_size(:) |
Length in characters of each key, in insertion order. |
||
| integer(kind=default_int), | private, | allocatable | :: | key_start(:) |
First character of each key inside |
||
| integer(kind=default_int), | private | :: | n_buckets | = | 0 |
Number of buckets, always a power of two, 0 while unallocated. |
|
| integer(kind=default_int), | private | :: | n_entries | = | 0 |
Number of live entries, i.e. the value returned by |
|
| integer(kind=default_int), | private | :: | pool_cap | = | 0 |
Allocated length of |
|
| integer(kind=default_int), | private | :: | pool_used | = | 0 |
Number of characters currently used in |
Fetch the entry at position in the iteration order, counting from 1.
This is the exact-fidelity iteration accessor: key comes back with
the key’s true length, trailing blanks included.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(hash_map_t), | intent(in) | :: | this | |||
| integer(kind=default_int), | intent(in) | :: | position | |||
| character(len=:), | intent(out), | allocatable | :: | key | ||
| integer(kind=int64), | intent(out) | :: | value | |||
| type(error_t), | intent(out), | optional | :: | err |
Current number of buckets, 0 while the map is unallocated. Exposed so that callers and tests can observe growth; it never affects iteration order.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(hash_map_t), | intent(in) | :: | this |
Remove every entry but keep the allocated capacity, so that refilling
the map does not have to reallocate. A cleared map iterates as empty
and the next insert starts a fresh insertion order at position 1.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(hash_map_t), | intent(inout) | :: | this |
Release every buffer and return the map to the unallocated state.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(hash_map_t), | intent(inout) | :: | this |
Look up key. A missing key is an ordinary outcome, not an error:
found comes back .false. and value is set to 0.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(hash_map_t), | intent(in) | :: | this | |||
| character(len=*), | intent(in) | :: | key | |||
| integer(kind=int64), | intent(out) | :: | value | |||
| logical, | intent(out) | :: | found |
.true. when key is stored in the map.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(hash_map_t), | intent(in) | :: | this | |||
| character(len=*), | intent(in) | :: | key |
Allocate the map, discarding any entries it already held.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(hash_map_t), | intent(inout) | :: | this | |||
| integer(kind=default_int), | intent(in), | optional | :: | initial_capacity |
Insert key with value, or overwrite the value of an existing key.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(hash_map_t), | intent(inout) | :: | this | |||
| character(len=*), | intent(in) | :: | key |
Stored verbatim; trailing blanks are part of the key. |
||
| integer(kind=int64), | intent(in) | :: | value |
.true. when the map holds no entries.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(hash_map_t), | intent(in) | :: | this |
All keys, in insertion order.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(hash_map_t), | intent(in) | :: | this |
Remove key from the map.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(hash_map_t), | intent(inout) | :: | this | |||
| character(len=*), | intent(in) | :: | key | |||
| type(error_t), | intent(out), | optional | :: | err |
Number of entries currently stored.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(hash_map_t), | intent(in) | :: | this |
All values, in insertion order. values() and keys() are index
aligned: values(i) belongs to keys(i). Zero-sized for an empty
map.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(hash_map_t), | intent(in) | :: | this |
type :: hash_map_t !! Insertion-ordered hash map: `character(len=*)` keys, `integer(int64)` !! values. Default initialisation yields a valid empty map; the first !! `insert` allocates with default capacity if `init` was never called. private integer(default_int) :: n_buckets = 0 !! Number of buckets, always a power of two, 0 while unallocated. integer(default_int), allocatable :: buckets(:) !! Bucket table; `BUCKET_EMPTY` or an index into the entry table. integer(default_int) :: n_entries = 0 !! Number of live entries, i.e. the value returned by `size()`. integer(default_int) :: entry_cap = 0 !! Allocated length of the entry arrays. integer(default_int), allocatable :: key_start(:) !! First character of each key inside `key_pool`, in insertion order. integer(default_int), allocatable :: key_size(:) !! Length in characters of each key, in insertion order. integer(int64), allocatable :: entry_value(:) !! Value of each entry, in insertion order. character(len=1), allocatable :: key_pool(:) !! Packed storage for all key characters. integer(default_int) :: pool_used = 0 !! Number of characters currently used in `key_pool`. integer(default_int) :: pool_cap = 0 !! Allocated length of `key_pool`. contains procedure :: init => hash_map_init procedure :: destroy => hash_map_destroy procedure :: clear => hash_map_clear procedure :: size => hash_map_size procedure :: is_empty => hash_map_is_empty procedure :: bucket_count => hash_map_bucket_count procedure :: insert => hash_map_insert procedure :: get => hash_map_get procedure :: has_key => hash_map_has_key procedure :: remove => hash_map_remove procedure :: keys => hash_map_keys procedure :: values => hash_map_values procedure :: at => hash_map_at end type hash_map_t