Skip to content

Commit dd120fe

Browse files
authored
Merge pull request fortran-lang#12 from jvdp1/hash_maps_review
Review of the specs of hash maps
2 parents 5fa8bb2 + b4c0b75 commit dd120fe

File tree

1 file changed

+64
-31
lines changed

1 file changed

+64
-31
lines changed

doc/specs/stdlib_hashmaps.md

+64-31
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ Procedures to manipulate `other_type` data:
170170
`other_out`.
171171

172172
* `get( other, value )` - extracts the contents of `other` into the
173-
class(*) variable `value`.
173+
`class(*)` variable `value`.
174174

175-
* `set( other, value )` - sets the content of `other` to the class(*)
175+
* `set( other, value )` - sets the content of `other` to the `class(*)`
176176
variable `value`.
177177

178178
* `free_other( other )` - frees the memory in `other`.
@@ -194,7 +194,7 @@ Procedures to hash keys to 32 bit integers:
194194

195195
Operator to compare two `key_type` values for equality
196196

197-
* `key1 == key2` - compares `key1' with 'key2' for equality
197+
* `key1 == key2` - compares `key1` with `key2` for equality
198198

199199
### Specifications of the `stdlib_hashmap_wrappers` procedures
200200

@@ -445,7 +445,7 @@ Experimental
445445

446446
##### Description
447447

448-
Deallocates the memory associated with an variable of type
448+
Deallocates the memory associated with a variable of type
449449
`key_type`.
450450

451451
##### Syntax
@@ -486,7 +486,7 @@ Experimental
486486

487487
##### Description
488488

489-
Deallocates the memory associated with an variable of type
489+
Deallocates the memory associated with a variable of type
490490
`other_type`.
491491

492492
##### Syntax
@@ -580,7 +580,7 @@ an allocatable of `class(*)`. It is an `intent(out)` argument.
580580
end do
581581
call set( key, value )
582582
call get( key, result )
583-
print *, `RESULT == VALUE = ', all( value == result )
583+
print *, 'RESULT == VALUE = ', all( value == result )
584584
end program demo_get
585585
```
586586

@@ -654,7 +654,7 @@ Returns `.true.` if two keys are equal, and `.false.` otherwise.
654654

655655
##### Syntax
656656

657-
`test = [stdlib_hashmap_wrappers:key1==key2]`
657+
`test = key1 == key2`
658658

659659
##### Class
660660

@@ -920,8 +920,8 @@ shall be of type `class(*)`. It is an `intent(in)` argument.
920920
##### Note
921921

922922
Values of types other than a scalar default character or an
923-
`INT8` vector can be used as the basis of a `key` by transferring the
924-
value to an `INT8` vector.
923+
`int8` vector can be used as the basis of a `key` by transferring the
924+
value to an `int8` vector.
925925

926926
##### Example
927927

@@ -940,7 +940,7 @@ value to an `INT8` vector.
940940
end do
941941
call set( key, value )
942942
call get( key, result )
943-
print *, `RESULT == VALUE = ', all( value == result )
943+
print *, 'RESULT == VALUE = ', all( value == result )
944944
end program demo_set
945945
```
946946

@@ -1038,35 +1038,57 @@ type. Each of these types are described below.
10381038
The `hashmap_type` abstract type serves as the parent type for the two
10391039
types `chaining_hashmap_type` and `open_hashmap_type`. It defines
10401040
seven private components:
1041+
10411042
* `call_count` - the number of procedure calls on the map;
1043+
10421044
* `nbits` - the number of bits used to address the slots;
1045+
10431046
* `num_entries` - the humber of entries in the map;
1047+
10441048
* `num_free` - the number of entries in the free list of removed
10451049
entries;
1050+
10461051
* `probe_count` - the number of map probes since the last resizing or
10471052
initialization;
1053+
10481054
* `total_probes` - the number of probes of the map up to the last
10491055
resizing or initialization; and
1056+
10501057
* `hasher` - a pointer to the hash function used by the map.
1058+
10511059
It also defines five non-overridable procedures:
1060+
10521061
* `calls` - returns the number of procedure calls on the map;
1062+
10531063
* `entries` - returns the number of entries in the map;
1064+
10541065
* `map_probes` - returns the number of map probes since
10551066
initialization;
1067+
10561068
* `num_slots` - returns the number of slots in the map; and
1069+
10571070
* `slots_bits` - returns the number of bits used to address the slots;
10581071
and eleven deferred procedures:
1072+
10591073
* `get_other_data` - gets the other map data associated with the key;
1074+
10601075
* `init` - initializes the hash map;
1076+
10611077
* `key_test` - returns a logical flag indicating whether the key is
10621078
defined in the map.
1079+
10631080
* `loading` - returns the ratio of the number of entries to the number
10641081
of slots;
1082+
10651083
* `map_entry` - inserts a key and its other associated data into the
10661084
map;
1085+
10671086
* `rehash` - rehashes the map with the provided hash function;
1087+
10681088
* `remove` - removes the entry associated wit the key;
1089+
10691090
* `set_other_data` - replaces the other data associated with the key;
1091+
10701092
* `total_depth` - returns the number of probes needed to address all
10711093
the entries in the map;
10721094

@@ -1158,13 +1180,18 @@ costs. The type's definition is below:
11581180
The `chaining_hashmap_type` derived type extends the `hashmap_type` to
11591181
implements a separate chaining hash map. In addition to the components
11601182
of the `hashmap_type` it provides the four components:
1183+
11611184
* `cache` - a pool of `chaining_map_entry_pool` objects used to reduce
11621185
allocation costs;
1186+
11631187
* `free_list` - a free list of map entries;
1188+
11641189
* `inverse` - an array of `chaining_map_entry_ptr` bucket lists
11651190
(inverses) storing entries at fixed locations once
11661191
entered; and
1192+
11671193
* `slots` - an array of bucket lists serving as the hash map.
1194+
11681195
It also implements all of the deferred procedures of the
11691196
`hashmap_type` and a finalizer for its maps. The type's definition is
11701197
as follows:
@@ -1227,14 +1254,20 @@ containing the elements of the table. The type's definition is below:
12271254
The `open_hashmap_type` derived type extends the `hashmap_type` to
12281255
implement an open addressing hash map. In addition to the components
12291256
of the `hashmap_type` it provides the four components:
1257+
12301258
* `cache` - a pool of `open_map_entry_pool` objects used to reduce
12311259
allocation costs;
1260+
12321261
* `free_list` - a free list of map entries;
1262+
12331263
* `index_mask` - an `and` mask used in linear addressing;
1264+
12341265
* `inverse` - an array of `open_map_entry_ptr` bucket lists
12351266
(inverses) storing entries at fixed locations once
12361267
entered; and
1268+
12371269
* `slots` - an array of bucket lists serving as the hash map.
1270+
12381271
It also implements all of the deferred procedures of the
12391272
`hashmap_type` and a finalizer for its maps. The type's definition is
12401273
as follows:
@@ -1332,7 +1365,7 @@ Returns the number of procedure calls on a hash map.
13321365

13331366
##### Syntax
13341367

1335-
`value = [[stdlib_hashmaps:map % calls]]()`
1368+
`value = map % [[hashmap_type(type):calls(bound)]]()`
13361369

13371370
##### Class
13381371

@@ -1379,7 +1412,7 @@ Returns the number of entries in a hash map.
13791412

13801413
##### Syntax
13811414

1382-
`value = [[stdlib_hashmaps:map % entries]]()`
1415+
`value = map % [[hashmap_type(type):entries(bound)]]()`
13831416

13841417
##### Class
13851418

@@ -1426,7 +1459,7 @@ Returns the other data associated with the `key`,
14261459

14271460
##### Syntax
14281461

1429-
`value = [[stdlib_hashmaps:map % get_other_data)]]( key, other [, exists] )`
1462+
`value = map % [[hashmap_type(type):get_other_data(bound)]]( key, other [, exists] )`
14301463

14311464
##### Class
14321465

@@ -1447,7 +1480,7 @@ Subroutine
14471480
with the `key`.
14481481

14491482
`exists` (optional): shall be a variable of type logical. It is an
1450-
`intent(out)` argument. If `.true.` an entry with the given `key`
1483+
`intent(out)` argument. If `.true.` an entry with the given `key`
14511484
exists in the map and `other` is defined. If `.false.` `other` is
14521485
undefined.
14531486

@@ -1457,7 +1490,7 @@ undefined.
14571490
associated with a `key`:
14581491

14591492

1460-
```Fortran
1493+
```fortran
14611494
program demo_get_other_data
14621495
use, intrinsic:: iso_fortran_env, only: &
14631496
int8
@@ -1494,7 +1527,7 @@ undefined.
14941527
```
14951528

14961529

1497-
#### init - initializes a hash map
1530+
#### `init` - initializes a hash map
14981531

14991532
##### Status
15001533

@@ -1506,9 +1539,9 @@ Initializes a `hashmap_type` object.
15061539

15071540
##### Syntax
15081541

1509-
`call [[stdlib_hashmaps:map%init]]( hasher [, slots_bits, status ] )`
1542+
`call map % [[hashmap_type(type):init(bound)]]( hasher [, slots_bits, status ] )`
15101543

1511-
####@# Class
1544+
##### Class
15121545

15131546
Subroutine
15141547

@@ -1576,7 +1609,7 @@ entry in the map.
15761609

15771610
##### Syntax
15781611

1579-
`result = call [[stdlib_hashmaps:map % valid_key]]( key, present )`
1612+
`result = call map % [[hashmap_type(type):key_test(bound)]]( key, present )`
15801613

15811614
##### Class
15821615

@@ -1630,7 +1663,7 @@ slots in the hash map.
16301663

16311664
##### Syntax
16321665

1633-
`value = [[stdlib_hashmaps:map%loading]]( )`
1666+
`value = map % [[hashmap_type(type):loading(bound)]]( )`
16341667

16351668
##### Class
16361669

@@ -1677,7 +1710,7 @@ Inserts an entry into the hash map if it is not already present.
16771710

16781711
##### Syntax
16791712

1680-
`call [[stdlib_hashmaps:map%map_entry]]( key[, other, conflict ] )`
1713+
`call map % [[hashmap_type(type):map_entry(bound)]]( key[, other, conflict ] )`
16811714

16821715

16831716
##### Class
@@ -1742,7 +1775,7 @@ Returns the total number of table probes on the hash map.
17421775

17431776
##### Syntax
17441777

1745-
`Result = [[stdlib_hashmap:map%map_probes]]( )`
1778+
`result = map % [[hashmap_type(type):map_probes(bound)]]( )`
17461779

17471780
##### Class
17481781

@@ -1790,7 +1823,7 @@ Returns the total number of slots on a hash map
17901823

17911824
##### Syntax
17921825

1793-
`Result = [[stdlib_hashmaps:map%num_slots]]( )`
1826+
`result = map % [[hashmap_type(type):num_slots(bound)]]( )`
17941827

17951828
##### Class
17961829

@@ -1826,7 +1859,7 @@ The result is the number of slots in `map`.
18261859
```
18271860

18281861

1829-
#### rehash - changes the hashing function
1862+
#### `rehash` - changes the hashing function
18301863

18311864
##### Status
18321865

@@ -1838,7 +1871,7 @@ Changes the hashing function for the map entries to that of `hasher`.
18381871

18391872
##### Syntax
18401873

1841-
`call [[stdlib_hashmaps:map%rehash]]( hasher )`
1874+
`call map % [[hashmap_type(type):rehash(bound)]]( hasher )`
18421875

18431876
##### Class
18441877

@@ -1847,7 +1880,7 @@ Subroutine
18471880
##### Arguments
18481881

18491882
`map` (pass): shall be a scalar variable of class
1850-
`chaining_hashmap_type` oe `open_hashmap_type`.
1883+
`chaining_hashmap_type` or `open_hashmap_type`.
18511884
It is an `intent(inout)` argument. It is the hash map whose hashing
18521885
method is to be changed.
18531886

@@ -1886,7 +1919,7 @@ Removes an entry from the hash map, `map`.
18861919

18871920
##### Syntax
18881921

1889-
`call [[stdlib_hashmaps:map%remove]]( key[, existed ])`
1922+
`call map % [[hashmap_type(type):remove(bound)]]( key[, existed ])`
18901923

18911924
##### Class
18921925

@@ -1931,7 +1964,7 @@ absent, the procedure returns with no entry with the given key.
19311964
end program demo_remove
19321965
```
19331966

1934-
#### `set_other_data` - replaces the other dataa for an entry
1967+
#### `set_other_data` - replaces the other data for an entry
19351968

19361969
##### Status
19371970

@@ -1944,7 +1977,7 @@ Replaces the other data in the map for the entry with the key value,
19441977

19451978
##### Syntax
19461979

1947-
`call [[stdlib_hashmaps:map%set_other_data]]( key, other[, exists] )`
1980+
`call map % [[hashmap_type(type):set_other_data(bound)]]( key, other[, exists] )`
19481981

19491982
##### Class
19501983

@@ -2008,7 +2041,7 @@ Returns the total number of bits used to address the hash map slots.
20082041

20092042
##### Syntax
20102043

2011-
`Result = [[stdlib_hashmaps:map%slots_bits]]( )`
2044+
`result = map % [[hashmap_type(type):slots_bits(bound)]]( )`
20122045

20132046
##### Class
20142047

@@ -2057,7 +2090,7 @@ their slot index for a hash map
20572090

20582091
##### Syntax
20592092

2060-
`Result = [[stdlib_hashmaps:map%total_depth]]( )`
2093+
`result = map % [[hashmap_type:total_depth]]( )`
20612094

20622095
##### Class
20632096

0 commit comments

Comments
 (0)