@@ -106,12 +106,7 @@ Author: Daniel Poetzl
106
106
// clang-format on
107
107
108
108
// / A map implemented as a tree where subtrees can be shared between different
109
- // / maps.
110
- // /
111
- // / The map is implemented as a fixed-height n-ary trie. The height H and the
112
- // / maximum number of children per inner node S are determined by the two
113
- // / configuration parameters `bits` and `chunks` in sharing_map.h. It holds
114
- // / that H = `bits` / `chunks` and S = 2 ^ `chunks`.
109
+ // / maps. The map is implemented as a variable-height n-ary trie.
115
110
// /
116
111
// / When inserting a key-value pair into the map, first the hash of its key is
117
112
// / computed. The `bits` number of lower order bits of the hash are deemed
@@ -122,24 +117,29 @@ Author: Daniel Poetzl
122
117
// / different keys yield the same "string"), are handled by chaining the
123
118
// / corresponding key-value pairs in a `std::forward_list`.
124
119
// /
120
+ // / The depth at which a key-value pair will be stored (when calling insert())
121
+ // / depends on the shortest unique prefix of its hash code (treated as a string)
122
+ // / with respect to the hash codes of the key-value pairs already in the map.
123
+ // /
125
124
// / The use of a trie in combination with hashing has the advantage that the
126
125
// / tree is unlikely to degenerate (if the number of hash collisions is low).
127
126
// / This makes re-balancing operations unnecessary which do not interact well
128
127
// / with sharing. A disadvantage is that the height of the tree is likely
129
- // / greater than if the elements had been stored in a balanced tree (with
130
- // / greater differences for sparser maps).
128
+ // / greater than if the elements had been stored in a balanced tree.
131
129
// /
132
- // / The nodes in the sharing map are objects of type sharing_nodet. Each sharing
133
- // / node has a `shared_ptr` to an object of type `dt` which can be shared
134
- // / between nodes.
130
+ // / The nodes in the sharing map are objects of type sharing_nodet. A sharing
131
+ // / node has a shared pointer (of type small_shared_n_way_ptrt) which can point
132
+ // / to objects of type d_internalt, d_leaft, or d_containert (representing
133
+ // / internal nodes, leaf nodes, and container nodes, the latter being used for
134
+ // / chaining leafs in a linked list on hash collisions).
135
135
// /
136
136
// / Sharing is initially generated when a map is assigned to another map or
137
137
// / copied via the copy constructor. Then both maps contain a pointer to the
138
138
// / root node of the tree that represents the maps. On subsequent modifications
139
139
// / to one of the maps, nodes are copied and sharing is lessened as described in
140
140
// / the following.
141
141
// /
142
- // / The replace(), insert (), update() and erase() operations interact with
142
+ // / The replace(), update (), insert(), and erase() operations interact with
143
143
// / sharing as follows:
144
144
// / - When a key-value pair is inserted into the map (or a value of an existing
145
145
// / pair is replaced or updated) and its position is in a shared subtree,
@@ -151,7 +151,7 @@ Author: Daniel Poetzl
151
151
// / the path to the erased element after the element has been removed are
152
152
// / copied and integrated with the map, and the remaining nodes are removed.
153
153
// /
154
- // / The replace() and update() operations are the only method where sharing
154
+ // / The replace() and update() operations are the only methods where sharing
155
155
// / could unnecessarily be broken. This would happen when replacing an old
156
156
// / value with a new equal value, or calling update but making no change. The
157
157
// / sharing map provides a debug mode to detect such cases. When the template
@@ -165,7 +165,7 @@ Author: Daniel Poetzl
165
165
// / complexity of the operations. We use the following symbols:
166
166
// / - N: number of key-value pairs in the map
167
167
// / - M: maximum number of key-value pairs that are chained in a leaf node
168
- // / - H: height of the tree
168
+ // / - H: maximum height of the tree
169
169
// / - S: maximum number of children per internal node
170
170
// /
171
171
// / The first two symbols denote dynamic properties of a given map, whereas the
0 commit comments