@@ -535,8 +535,26 @@ class sharing_mapt
535
535
return lp;
536
536
}
537
537
538
+ // / Move a container node (containing a single leaf) further down the tree
539
+ // / such as to resolve a collision with another key-value pair. This method is
540
+ // / called by `insert()` to resolve a collision between a key-value pair to be
541
+ // / newly inserted, and a key-value pair existing in the map.
542
+ // /
543
+ // / \param starting_level: the depth of the inner node pointing to the
544
+ // / container node with a single leaf
545
+ // / \param key_suffix: hash code of the existing key in the map, shifted to
546
+ // / the right by `chunk * starting_level` bits (i.e., \p key_suffix is the
547
+ // / rest of the hash code used to determine the position of the key-value
548
+ // / pair below level \p starting_level
549
+ // / \param bit_last: last portion of the hash code of the key existing in the
550
+ // / map (`inner[bit_last]` points to the container node to move further down
551
+ // / the tree)
552
+ // / \param inner: inner node of which the child `inner[bit_last]` is the
553
+ // / container node to move further down the tree
554
+ // / \return pointer to the container to which the element to be newly inserted
555
+ // / can be added
538
556
innert *migrate (
539
- const std::size_t i ,
557
+ const std::size_t starting_level ,
540
558
const std::size_t key_suffix,
541
559
const std::size_t bit_last,
542
560
innert &inner);
@@ -545,6 +563,20 @@ class sharing_mapt
545
563
const innert &n,
546
564
std::function<void (const key_type &k, const mapped_type &m)> f) const ;
547
565
566
+ // / Add a delta item to the delta view if the value in the \p container (which
567
+ // / must only contain a single leaf) is not shared with any of the values in
568
+ // / the subtree below \p inner. This method is called by `get_delta_view()`
569
+ // / when a container containing a single leaf is encountered in the first map,
570
+ // / and the corresponding node in the second map is an inner node.
571
+ // /
572
+ // / \param container: container node containing a single leaf, part of the
573
+ // / first map in a call `map1.get_delta_view(map2, ...)`
574
+ // / \param inner: inner node which is part of the second map
575
+ // / \param level: depth of the nodes in the maps (both \p container and \p
576
+ // / inner must be at the same depth in their respective maps)
577
+ // / \param delta_view: delta view to add delta items to
578
+ // / \param only_common: flag indicating if only items are added to the delta
579
+ // / view for which the keys are in both maps
548
580
void add_item_if_not_shared (
549
581
const innert &container,
550
582
const innert &inner,
@@ -572,7 +604,7 @@ class sharing_mapt
572
604
573
605
// derived config
574
606
static const std::size_t mask;
575
- static const std::size_t steps ;
607
+ static const std::size_t levels ;
576
608
577
609
// key-value map
578
610
innert map;
@@ -1108,12 +1140,12 @@ SHARING_MAPT(void)::erase(const key_type &k)
1108
1140
}
1109
1141
1110
1142
SHARING_MAPT2 (, innert *)::migrate(
1111
- const std::size_t step ,
1143
+ const std::size_t starting_level ,
1112
1144
const std::size_t key_suffix,
1113
1145
const std::size_t bit_last,
1114
1146
innert &inner)
1115
1147
{
1116
- SM_ASSERT (step < steps - 1 );
1148
+ SM_ASSERT (starting_level < levels - 1 );
1117
1149
SM_ASSERT (inner.is_defined_internal ());
1118
1150
1119
1151
const innert &child = *inner.find_child (bit_last);
@@ -1127,7 +1159,7 @@ SHARING_MAPT2(, innert *)::migrate(
1127
1159
const leaft &leaf = ll.front ();
1128
1160
std::size_t key_existing = hash ()(leaf.get_key ());
1129
1161
1130
- key_existing >>= chunk * step ;
1162
+ key_existing >>= chunk * starting_level ;
1131
1163
1132
1164
// Copy the container
1133
1165
innert container_copy (child);
@@ -1141,13 +1173,13 @@ SHARING_MAPT2(, innert *)::migrate(
1141
1173
1142
1174
// Find place for both elements
1143
1175
1144
- std::size_t i = step + 1 ;
1176
+ std::size_t level = starting_level + 1 ;
1145
1177
std::size_t key = key_suffix;
1146
1178
1147
1179
key_existing >>= chunk;
1148
1180
key >>= chunk;
1149
1181
1150
- SM_ASSERT (i < steps );
1182
+ SM_ASSERT (level < levels );
1151
1183
1152
1184
do
1153
1185
{
@@ -1171,8 +1203,8 @@ SHARING_MAPT2(, innert *)::migrate(
1171
1203
key >>= chunk;
1172
1204
key_existing >>= chunk;
1173
1205
1174
- i ++;
1175
- } while (i < steps );
1206
+ level ++;
1207
+ } while (level < levels );
1176
1208
1177
1209
leaft leaf_copy (as_const (&container_copy)->get_container ().front ());
1178
1210
ip->get_container ().push_front (leaf_copy);
@@ -1191,15 +1223,15 @@ ::insert(const key_type &k, valueU &&m)
1191
1223
// The root cannot be a container node
1192
1224
SM_ASSERT (ip->is_internal ());
1193
1225
1194
- std::size_t i = 0 ;
1226
+ std::size_t level = 0 ;
1195
1227
1196
1228
while (true )
1197
1229
{
1198
1230
std::size_t bit = key & mask;
1199
1231
1200
1232
SM_ASSERT (ip != nullptr );
1201
1233
SM_ASSERT (ip->is_internal ());
1202
- SM_ASSERT (i == 0 || !ip->empty ());
1234
+ SM_ASSERT (level == 0 || !ip->empty ());
1203
1235
1204
1236
innert *child = ip->add_child (bit);
1205
1237
@@ -1218,10 +1250,10 @@ ::insert(const key_type &k, valueU &&m)
1218
1250
1219
1251
if (child->is_container ())
1220
1252
{
1221
- if (i < steps - 1 )
1253
+ if (level < levels - 1 )
1222
1254
{
1223
1255
// Migrate the elements downwards
1224
- innert *cp = migrate (i , key, bit, *ip);
1256
+ innert *cp = migrate (level , key, bit, *ip);
1225
1257
1226
1258
cp->place_leaf (k, std::forward<valueU>(m));
1227
1259
}
@@ -1236,11 +1268,11 @@ ::insert(const key_type &k, valueU &&m)
1236
1268
return ;
1237
1269
}
1238
1270
1239
- SM_ASSERT (i == steps - 1 || child->is_defined_internal ());
1271
+ SM_ASSERT (level == levels - 1 || child->is_defined_internal ());
1240
1272
1241
1273
ip = child;
1242
1274
key >>= chunk;
1243
- i ++;
1275
+ level ++;
1244
1276
}
1245
1277
}
1246
1278
@@ -1298,6 +1330,6 @@ SHARING_MAPT(const std::size_t)::bits = 30;
1298
1330
SHARING_MAPT (const std::size_t )::chunk = 3;
1299
1331
1300
1332
SHARING_MAPT (const std::size_t )::mask = 0xffff >> (16 - chunk);
1301
- SHARING_MAPT (const std::size_t )::steps = bits / chunk;
1333
+ SHARING_MAPT (const std::size_t )::levels = bits / chunk;
1302
1334
1303
1335
#endif
0 commit comments