Skip to content

Commit d4d4ca5

Browse files
committed
Update high-level sharing map documentation
Update the documentation to reflect the fact that the sharing map is now a variable-height tree.
1 parent dc1e454 commit d4d4ca5

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/util/sharing_map.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,7 @@ Author: Daniel Poetzl
106106
// clang-format on
107107

108108
/// 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.
115110
///
116111
/// When inserting a key-value pair into the map, first the hash of its key is
117112
/// computed. The `bits` number of lower order bits of the hash are deemed
@@ -122,24 +117,29 @@ Author: Daniel Poetzl
122117
/// different keys yield the same "string"), are handled by chaining the
123118
/// corresponding key-value pairs in a `std::forward_list`.
124119
///
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+
///
125124
/// The use of a trie in combination with hashing has the advantage that the
126125
/// tree is unlikely to degenerate (if the number of hash collisions is low).
127126
/// This makes re-balancing operations unnecessary which do not interact well
128127
/// 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.
131129
///
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).
135135
///
136136
/// Sharing is initially generated when a map is assigned to another map or
137137
/// copied via the copy constructor. Then both maps contain a pointer to the
138138
/// root node of the tree that represents the maps. On subsequent modifications
139139
/// to one of the maps, nodes are copied and sharing is lessened as described in
140140
/// the following.
141141
///
142-
/// The replace(), insert(), update() and erase() operations interact with
142+
/// The replace(), update(), insert(), and erase() operations interact with
143143
/// sharing as follows:
144144
/// - When a key-value pair is inserted into the map (or a value of an existing
145145
/// pair is replaced or updated) and its position is in a shared subtree,
@@ -151,7 +151,7 @@ Author: Daniel Poetzl
151151
/// the path to the erased element after the element has been removed are
152152
/// copied and integrated with the map, and the remaining nodes are removed.
153153
///
154-
/// The replace() and update() operations are the only method where sharing
154+
/// The replace() and update() operations are the only methods where sharing
155155
/// could unnecessarily be broken. This would happen when replacing an old
156156
/// value with a new equal value, or calling update but making no change. The
157157
/// sharing map provides a debug mode to detect such cases. When the template
@@ -165,7 +165,7 @@ Author: Daniel Poetzl
165165
/// complexity of the operations. We use the following symbols:
166166
/// - N: number of key-value pairs in the map
167167
/// - 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
169169
/// - S: maximum number of children per internal node
170170
///
171171
/// The first two symbols denote dynamic properties of a given map, whereas the

0 commit comments

Comments
 (0)