Skip to content

Commit 7b79b60

Browse files
committed
Use type nodet to represent sharing map nodes
Previously there existed a separate leaft type. Now all nodes are of the type sharing_nodet<...> (of which nodet is an alias). This replaces all node types by nodet.
1 parent c6b5133 commit 7b79b60

File tree

1 file changed

+44
-45
lines changed

1 file changed

+44
-45
lines changed

src/util/sharing_map.h

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,10 @@ class sharing_mapt
194194
typedef std::vector<key_type> keyst;
195195

196196
protected:
197-
typedef sharing_nodet<key_type, mapped_type> innert;
198-
typedef sharing_nodet<key_type, mapped_type> leaft;
197+
typedef sharing_nodet<key_type, mapped_type> nodet;
199198

200-
typedef typename innert::to_mapt to_mapt;
201-
typedef typename innert::leaf_listt leaf_listt;
199+
typedef typename nodet::to_mapt to_mapt;
200+
typedef typename nodet::leaf_listt leaf_listt;
202201

203202
struct falset
204203
{
@@ -519,8 +518,8 @@ class sharing_mapt
519518
protected:
520519
// helpers
521520

522-
leaft &get_leaf_node(const key_type &k);
523-
const leaft *get_leaf_node(const key_type &k) const;
521+
nodet &get_leaf_node(const key_type &k);
522+
const nodet *get_leaf_node(const key_type &k) const;
524523

525524
/// Move a leaf node further down the tree such as to resolve a collision with
526525
/// another key-value pair. This method is called by `insert()` to resolve a
@@ -545,12 +544,12 @@ class sharing_mapt
545544
const std::size_t starting_level,
546545
const std::size_t key_suffix,
547546
const std::size_t bit_last,
548-
innert &inner,
547+
nodet &inner,
549548
const key_type &k,
550549
valueU &&m);
551550

552551
void iterate(
553-
const innert &n,
552+
const nodet &n,
554553
std::function<void(const key_type &k, const mapped_type &m)> f) const;
555554

556555
/// Add a delta item to the delta view if the value in the \p container (which
@@ -568,13 +567,13 @@ class sharing_mapt
568567
/// \param only_common: flag indicating if only items are added to the delta
569568
/// view for which the keys are in both maps
570569
void add_item_if_not_shared(
571-
const leaft &leaf,
572-
const innert &inner,
570+
const nodet &leaf,
571+
const nodet &inner,
573572
const std::size_t level,
574573
delta_viewt &delta_view,
575574
const bool only_common) const;
576575

577-
void gather_all(const innert &n, delta_viewt &delta_view) const;
576+
void gather_all(const nodet &n, delta_viewt &delta_view) const;
578577

579578
std::size_t count_unmarked_nodes(
580579
bool leafs_only,
@@ -592,25 +591,25 @@ class sharing_mapt
592591
static const std::size_t levels;
593592

594593
// key-value map
595-
innert map;
594+
nodet map;
596595

597596
// number of elements in the map
598597
size_type num = 0;
599598
};
600599

601600
SHARING_MAPT(void)
602601
::iterate(
603-
const innert &n,
602+
const nodet &n,
604603
std::function<void(const key_type &k, const mapped_type &m)> f) const
605604
{
606605
SM_ASSERT(!n.empty());
607606

608-
std::stack<const innert *> stack;
607+
std::stack<const nodet *> stack;
609608
stack.push(&n);
610609

611610
do
612611
{
613-
const innert *ip = stack.top();
612+
const nodet *ip = stack.top();
614613
stack.pop();
615614

616615
SM_ASSERT(!ip->empty());
@@ -656,12 +655,12 @@ ::count_unmarked_nodes(
656655

657656
unsigned count = 0;
658657

659-
std::stack<const innert *> stack;
658+
std::stack<const nodet *> stack;
660659
stack.push(&map);
661660

662661
do
663662
{
664-
const innert *ip = stack.top();
663+
const nodet *ip = stack.top();
665664
SM_ASSERT(!ip->empty());
666665
stack.pop();
667666

@@ -795,7 +794,7 @@ SHARING_MAPT(void)::get_view(viewt &view) const
795794
}
796795

797796
SHARING_MAPT(void)
798-
::gather_all(const innert &n, delta_viewt &delta_view) const
797+
::gather_all(const nodet &n, delta_viewt &delta_view) const
799798
{
800799
auto f = [&delta_view](const key_type &k, const mapped_type &m) {
801800
delta_view.push_back(delta_view_itemt(k, m));
@@ -805,8 +804,8 @@ ::gather_all(const innert &n, delta_viewt &delta_view) const
805804
}
806805

807806
SHARING_MAPT(void)::add_item_if_not_shared(
808-
const leaft &leaf,
809-
const innert &inner,
807+
const nodet &leaf,
808+
const nodet &inner,
810809
const std::size_t level,
811810
delta_viewt &delta_view,
812811
const bool only_common) const
@@ -816,7 +815,7 @@ SHARING_MAPT(void)::add_item_if_not_shared(
816815

817816
key >>= level * chunk;
818817

819-
const innert *ip = &inner;
818+
const nodet *ip = &inner;
820819
SM_ASSERT(ip->is_defined_internal());
821820

822821
while(true)
@@ -899,7 +898,7 @@ ::get_delta_view(
899898
return;
900899
}
901900

902-
typedef std::pair<const innert *, const innert *> stack_itemt;
901+
typedef std::pair<const nodet *, const nodet *> stack_itemt;
903902
std::stack<stack_itemt> stack;
904903

905904
std::stack<std::size_t> level_stack;
@@ -921,8 +920,8 @@ ::get_delta_view(
921920
{
922921
const stack_itemt &si = stack.top();
923922

924-
const innert *ip1 = si.first;
925-
const innert *ip2 = si.second;
923+
const nodet *ip1 = si.first;
924+
const nodet *ip2 = si.second;
926925

927926
SM_ASSERT(!ip1->shares_with(*ip2));
928927

@@ -942,9 +941,9 @@ ::get_delta_view(
942941
{
943942
for(const auto &item : ip1->get_to_map())
944943
{
945-
const innert &child = item.second;
944+
const nodet &child = item.second;
946945

947-
const innert *p;
946+
const nodet *p;
948947
p = ip2->find_child(item.first);
949948

950949
if(p == nullptr)
@@ -967,7 +966,7 @@ ::get_delta_view(
967966

968967
for(const auto &item : ip1->get_to_map())
969968
{
970-
const innert &child = item.second;
969+
const nodet &child = item.second;
971970

972971
if(!child.shares_with(*ip2))
973972
{
@@ -1039,7 +1038,7 @@ ::get_delta_view(
10391038
for(const auto &l1 : ip1->get_container())
10401039
{
10411040
const key_type &k1 = l1.get_key();
1042-
const leaft *p;
1041+
const nodet *p;
10431042

10441043
p = ip2->find_leaf(k1);
10451044

@@ -1063,12 +1062,12 @@ ::get_delta_view(
10631062
while(!stack.empty());
10641063
}
10651064

1066-
SHARING_MAPT2(, leaft &)::get_leaf_node(const key_type &k)
1065+
SHARING_MAPT2(, nodet &)::get_leaf_node(const key_type &k)
10671066
{
10681067
SM_ASSERT(has_key(k));
10691068

10701069
std::size_t key = hash()(k);
1071-
innert *ip = &map;
1070+
nodet *ip = &map;
10721071
SM_ASSERT(ip->is_defined_internal());
10731072

10741073
while(true)
@@ -1095,13 +1094,13 @@ SHARING_MAPT2(, leaft &)::get_leaf_node(const key_type &k)
10951094
}
10961095
}
10971096

1098-
SHARING_MAPT2(const, leaft *)::get_leaf_node(const key_type &k) const
1097+
SHARING_MAPT2(const, nodet *)::get_leaf_node(const key_type &k) const
10991098
{
11001099
if(empty())
11011100
return nullptr;
11021101

11031102
std::size_t key = hash()(k);
1104-
const innert *ip = &map;
1103+
const nodet *ip = &map;
11051104
SM_ASSERT(ip->is_defined_internal());
11061105

11071106
while(true)
@@ -1139,11 +1138,11 @@ SHARING_MAPT(void)::erase(const key_type &k)
11391138
{
11401139
SM_ASSERT(has_key(k));
11411140

1142-
innert *del = nullptr;
1141+
nodet *del = nullptr;
11431142
std::size_t del_bit = 0;
11441143

11451144
std::size_t key = hash()(k);
1146-
innert *ip = &map;
1145+
nodet *ip = &map;
11471146

11481147
while(true)
11491148
{
@@ -1206,23 +1205,23 @@ ::migrate(
12061205
const std::size_t starting_level,
12071206
const std::size_t key_suffix,
12081207
const std::size_t bit_last,
1209-
innert &inner,
1208+
nodet &inner,
12101209
const key_type &k,
12111210
valueU &&m)
12121211
{
12131212
SM_ASSERT(starting_level < levels - 1);
12141213
SM_ASSERT(inner.is_defined_internal());
12151214

1216-
leaft &leaf = inner.add_child(bit_last);
1215+
nodet &leaf = inner.add_child(bit_last);
12171216
SM_ASSERT(leaf.is_defined_leaf());
12181217

12191218
std::size_t key_existing = hash()(leaf.get_key());
12201219
key_existing >>= chunk * starting_level;
12211220

1222-
leaft leaf_kept;
1221+
nodet leaf_kept;
12231222
leaf_kept.swap(leaf);
12241223

1225-
innert *ip = &leaf;
1224+
nodet *ip = &leaf;
12261225
SM_ASSERT(ip->empty());
12271226

12281227
// Find place for both elements
@@ -1246,11 +1245,11 @@ ::migrate(
12461245
{
12471246
// Place found
12481247

1249-
innert &l1 = ip->add_child(bit_existing);
1248+
nodet &l1 = ip->add_child(bit_existing);
12501249
SM_ASSERT(l1.empty());
12511250
l1.swap(leaf_kept);
12521251

1253-
innert &l2 = ip->add_child(bit);
1252+
nodet &l2 = ip->add_child(bit);
12541253
SM_ASSERT(l2.empty());
12551254
l2.make_leaf(k, std::forward<valueU>(m));
12561255

@@ -1285,7 +1284,7 @@ ::insert(const key_type &k, valueU &&m)
12851284
SM_ASSERT(!has_key(k));
12861285

12871286
std::size_t key = hash()(k);
1288-
innert *ip = &map;
1287+
nodet *ip = &map;
12891288

12901289
// The root must be an internal node
12911290
SM_ASSERT(ip->is_internal());
@@ -1300,7 +1299,7 @@ ::insert(const key_type &k, valueU &&m)
13001299
SM_ASSERT(ip->is_internal());
13011300
SM_ASSERT(level == 0 || !ip->empty());
13021301

1303-
innert &child = ip->add_child(bit);
1302+
nodet &child = ip->add_child(bit);
13041303

13051304
// Place is unoccupied
13061305
if(child.empty())
@@ -1359,7 +1358,7 @@ ::insert(const key_type &k, valueU &&m)
13591358
SHARING_MAPT4(valueU, void)
13601359
::replace(const key_type &k, valueU &&m)
13611360
{
1362-
leaft &lp = get_leaf_node(k);
1361+
nodet &lp = get_leaf_node(k);
13631362

13641363
INVARIANT(
13651364
!value_equalt()(as_const(lp).get_value(), m),
@@ -1371,7 +1370,7 @@ ::replace(const key_type &k, valueU &&m)
13711370
SHARING_MAPT(void)
13721371
::update(const key_type &k, std::function<void(mapped_type &)> mutator)
13731372
{
1374-
leaft &lp = get_leaf_node(k);
1373+
nodet &lp = get_leaf_node(k);
13751374

13761375
value_comparatort comparator(as_const(lp).get_value());
13771376

@@ -1386,7 +1385,7 @@ ::update(const key_type &k, std::function<void(mapped_type &)> mutator)
13861385
SHARING_MAPT2(optionalt<std::reference_wrapper<const, mapped_type>>)::find(
13871386
const key_type &k) const
13881387
{
1389-
const leaft *lp = get_leaf_node(k);
1388+
const nodet *lp = get_leaf_node(k);
13901389

13911390
if(lp == nullptr)
13921391
return {};

0 commit comments

Comments
 (0)