Skip to content

Commit 1373561

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 8dd4a4c commit 1373561

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 container node (containing a single leaf) further down the tree
526525
/// such as to resolve a collision with another key-value pair. This method is
@@ -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)
@@ -1096,13 +1095,13 @@ SHARING_MAPT2(, leaft &)::get_leaf_node(const key_type &k)
10961095
}
10971096
}
10981097

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

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

11081107
while(true)
@@ -1141,11 +1140,11 @@ SHARING_MAPT(void)::erase(const key_type &k)
11411140
{
11421141
SM_ASSERT(has_key(k));
11431142

1144-
innert *del = nullptr;
1143+
nodet *del = nullptr;
11451144
std::size_t del_bit = 0;
11461145

11471146
std::size_t key = hash()(k);
1148-
innert *ip = &map;
1147+
nodet *ip = &map;
11491148

11501149
while(true)
11511150
{
@@ -1210,23 +1209,23 @@ ::migrate(
12101209
const std::size_t starting_level,
12111210
const std::size_t key_suffix,
12121211
const std::size_t bit_last,
1213-
innert &inner,
1212+
nodet &inner,
12141213
const key_type &k,
12151214
valueU &&m)
12161215
{
12171216
SM_ASSERT(starting_level < levels - 1);
12181217
SM_ASSERT(inner.is_defined_internal());
12191218

1220-
leaft &leaf = inner.add_child(bit_last);
1219+
nodet &leaf = inner.add_child(bit_last);
12211220
SM_ASSERT(leaf.is_defined_leaf());
12221221

12231222
std::size_t key_existing = hash()(leaf.get_key());
12241223
key_existing >>= chunk * starting_level;
12251224

1226-
leaft leaf_kept;
1225+
nodet leaf_kept;
12271226
leaf_kept.swap(leaf);
12281227

1229-
innert *ip = &leaf;
1228+
nodet *ip = &leaf;
12301229
SM_ASSERT(ip->empty());
12311230

12321231
// Find place for both elements
@@ -1250,11 +1249,11 @@ ::migrate(
12501249
{
12511250
// Place found
12521251

1253-
innert &l1 = ip->add_child(bit_existing);
1252+
nodet &l1 = ip->add_child(bit_existing);
12541253
SM_ASSERT(l1.empty());
12551254
l1.swap(leaf_kept);
12561255

1257-
innert &l2 = ip->add_child(bit);
1256+
nodet &l2 = ip->add_child(bit);
12581257
SM_ASSERT(l2.empty());
12591258
l2.make_leaf(k, std::forward<valueU>(m));
12601259

@@ -1289,7 +1288,7 @@ ::insert(const key_type &k, valueU &&m)
12891288
SM_ASSERT(!has_key(k));
12901289

12911290
std::size_t key = hash()(k);
1292-
innert *ip = &map;
1291+
nodet *ip = &map;
12931292

12941293
// The root must be an internal node
12951294
SM_ASSERT(ip->is_internal());
@@ -1304,7 +1303,7 @@ ::insert(const key_type &k, valueU &&m)
13041303
SM_ASSERT(ip->is_internal());
13051304
SM_ASSERT(level == 0 || !ip->empty());
13061305

1307-
innert &child = ip->add_child(bit);
1306+
nodet &child = ip->add_child(bit);
13081307

13091308
// Place is unoccupied
13101309
if(child.empty())
@@ -1365,7 +1364,7 @@ ::insert(const key_type &k, valueU &&m)
13651364
SHARING_MAPT4(valueU, void)
13661365
::replace(const key_type &k, valueU &&m)
13671366
{
1368-
leaft &lp = get_leaf_node(k);
1367+
nodet &lp = get_leaf_node(k);
13691368

13701369
INVARIANT(
13711370
!value_equalt()(as_const(lp).get_value(), m),
@@ -1377,7 +1376,7 @@ ::replace(const key_type &k, valueU &&m)
13771376
SHARING_MAPT(void)
13781377
::update(const key_type &k, std::function<void(mapped_type &)> mutator)
13791378
{
1380-
leaft &lp = get_leaf_node(k);
1379+
nodet &lp = get_leaf_node(k);
13811380

13821381
value_comparatort comparator(as_const(lp).get_value());
13831382

@@ -1392,7 +1391,7 @@ ::update(const key_type &k, std::function<void(mapped_type &)> mutator)
13921391
SHARING_MAPT2(optionalt<std::reference_wrapper<const, mapped_type>>)::find(
13931392
const key_type &k) const
13941393
{
1395-
const leaft *lp = get_leaf_node(k);
1394+
const nodet *lp = get_leaf_node(k);
13961395

13971396
if(lp == nullptr)
13981397
return {};

0 commit comments

Comments
 (0)