Skip to content

Commit e4174dd

Browse files
committed
Remove the tracking of tree node depth in the sharing map
When the sharing map was a fixed-height tree, the type of a node was determined by its depth in the tree. Therefore, the node depth was tracked when traversing the tree. Now that the sharing map is a variable-height tree, the methods is_internal() and is_container() are used to determine the type of a node.
1 parent 86c5a3f commit e4174dd

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

src/util/sharing_map.h

+23-18
Original file line numberDiff line numberDiff line change
@@ -997,9 +997,9 @@ SHARING_MAPT2(, innert *)::get_container_node(const key_type &k)
997997

998998
std::size_t key = hash()(k);
999999
innert *ip = ↦
1000-
SM_ASSERT(ip->is_internal());
1000+
SM_ASSERT(ip->is_defined_internal());
10011001

1002-
for(std::size_t i = 0; i < steps; i++)
1002+
while(true)
10031003
{
10041004
std::size_t bit = key & mask;
10051005

@@ -1024,10 +1024,9 @@ SHARING_MAPT2(const, innert *)::get_container_node(const key_type &k) const
10241024

10251025
std::size_t key = hash()(k);
10261026
const innert *ip = &map;
1027-
10281027
SM_ASSERT(ip->is_defined_internal());
10291028

1030-
for(std::size_t i = 0; i < steps; i++)
1029+
while(true)
10311030
{
10321031
std::size_t bit = key & mask;
10331032

@@ -1058,7 +1057,7 @@ SHARING_MAPT(void)::erase(const key_type &k)
10581057
std::size_t key = hash()(k);
10591058
innert *ip = &map;
10601059

1061-
for(std::size_t i = 0; i < steps; i++)
1060+
while(true)
10621061
{
10631062
std::size_t bit = key & mask;
10641063

@@ -1072,7 +1071,9 @@ SHARING_MAPT(void)::erase(const key_type &k)
10721071

10731072
ip = ip->add_child(bit);
10741073

1075-
if(ip->is_defined_container())
1074+
SM_ASSERT(!ip->empty());
1075+
1076+
if(ip->is_container())
10761077
break;
10771078

10781079
key >>= chunk;
@@ -1180,7 +1181,9 @@ ::insert(const key_type &k, valueU &&m)
11801181
// The root cannot be a container node
11811182
SM_ASSERT(ip->is_internal());
11821183

1183-
for(std::size_t i = 0; i < steps; i++)
1184+
std::size_t i = 0;
1185+
1186+
while(true)
11841187
{
11851188
std::size_t bit = key & mask;
11861189

@@ -1203,12 +1206,20 @@ ::insert(const key_type &k, valueU &&m)
12031206
return;
12041207
}
12051208

1206-
if(child->is_container() && i < steps - 1)
1209+
if(child->is_container())
12071210
{
1208-
// Migrate the elements downwards
1209-
innert *cp = migrate(i, key, bit, *ip);
1211+
if(i < steps - 1)
1212+
{
1213+
// Migrate the elements downwards
1214+
innert *cp = migrate(i, key, bit, *ip);
12101215

1211-
cp->place_leaf(k, std::forward<valueU>(m));
1216+
cp->place_leaf(k, std::forward<valueU>(m));
1217+
}
1218+
else
1219+
{
1220+
// Add to the bottom container
1221+
child->place_leaf(k, std::forward<valueU>(m));
1222+
}
12121223

12131224
num++;
12141225

@@ -1219,14 +1230,8 @@ ::insert(const key_type &k, valueU &&m)
12191230

12201231
ip = child;
12211232
key >>= chunk;
1233+
i++;
12221234
}
1223-
1224-
SM_ASSERT(ip->is_defined_container());
1225-
1226-
// Add to the bottom container
1227-
ip->place_leaf(k, std::forward<valueU>(m));
1228-
1229-
num++;
12301235
}
12311236

12321237
SHARING_MAPT4(valueU, void)

0 commit comments

Comments
 (0)