Skip to content

Commit d2ed841

Browse files
committed
Addressed sharing map review comments
1 parent 4662bdd commit d2ed841

File tree

2 files changed

+35
-40
lines changed

2 files changed

+35
-40
lines changed

src/util/sharing_map.h

+28-31
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ Author: Daniel Poetzl
1212
#ifndef CPROVER_UTIL_SHARING_MAP_H
1313
#define CPROVER_UTIL_SHARING_MAP_H
1414

15-
//#define SM_DEBUG
16-
1715
#ifdef SM_DEBUG
1816
#include <iostream>
1917
#endif
@@ -31,22 +29,22 @@ Author: Daniel Poetzl
3129
#include "sharing_node.h"
3230
#include "threeval.h"
3331

34-
//#define SM_INTERNAL_CHECKS
35-
3632
#ifdef SM_INTERNAL_CHECKS
3733
#define SM_ASSERT(b) INVARIANT(b, "Sharing map internal invariant")
3834
#else
3935
#define SM_ASSERT(b)
4036
#endif
4137

42-
#define SHARING_MAPT(R) \
43-
template <class keyT, class valueT, class hashT, class equalT> \
38+
// clang-format off
39+
#define SHARING_MAPT(R) \
40+
template <class keyT, class valueT, class hashT, class equalT> \
4441
R sharing_mapt<keyT, valueT, hashT, equalT>
4542

46-
#define SHARING_MAPT2(CV, ST) \
47-
template <class keyT, class valueT, class hashT, class equalT> \
48-
CV typename sharing_mapt<keyT, valueT, hashT, equalT>::ST \
43+
#define SHARING_MAPT2(CV, ST) \
44+
template <class keyT, class valueT, class hashT, class equalT> \
45+
CV typename sharing_mapt<keyT, valueT, hashT, equalT>::ST \
4946
sharing_mapt<keyT, valueT, hashT, equalT>
47+
// clang-format on
5048

5149
// Note: Due to a bug in Visual Studio we need to add an additional "const"
5250
// qualifier to the return values of insert(), place(), and find(). The type
@@ -299,7 +297,17 @@ class sharing_mapt
299297
innert *get_container_node(const key_type &k);
300298
const innert *get_container_node(const key_type &k) const;
301299

302-
const leaft *get_leaf_node(const key_type &k) const;
300+
const leaft *get_leaf_node(const key_type &k) const
301+
{
302+
const innert *cp = get_container_node(k);
303+
if(cp == nullptr)
304+
return nullptr;
305+
306+
const leaft *lp;
307+
lp = cp->find_leaf(k);
308+
309+
return lp;
310+
}
303311

304312
void iterate(
305313
const baset &n,
@@ -468,6 +476,13 @@ ::get_delta_view(
468476
typedef std::tuple<unsigned, const baset *, const baset *> stack_itemt;
469477
std::stack<stack_itemt> stack;
470478

479+
// We do a DFS "in lockstep" simultaneously on both maps. For
480+
// corresponding nodes we check whether they are shared between the
481+
// maps, and if not, we recurse into the corresponding subtrees.
482+
483+
// The stack contains the children of already visited nodes that we
484+
// still have to visit during the traversal.
485+
471486
stack.push(stack_itemt(0, &map, &other.map));
472487

473488
do
@@ -543,11 +558,9 @@ SHARING_MAPT2(, innert *)::get_container_node(const key_type &k)
543558
std::size_t key = hash()(k);
544559
innert *ip = &map;
545560

546-
std::size_t bit;
547-
548561
for(std::size_t i = 0; i < steps; i++)
549562
{
550-
bit = key & mask;
563+
std::size_t bit = key & mask;
551564

552565
ip = ip->add_child(bit);
553566

@@ -565,11 +578,9 @@ SHARING_MAPT2(const, innert *)::get_container_node(const key_type &k) const
565578
std::size_t key = hash()(k);
566579
const innert *ip = &map;
567580

568-
std::size_t bit;
569-
570581
for(std::size_t i = 0; i < steps; i++)
571582
{
572-
bit = key & mask;
583+
std::size_t bit = key & mask;
573584

574585
ip = ip->find_child(bit);
575586
if(ip == nullptr)
@@ -581,18 +592,6 @@ SHARING_MAPT2(const, innert *)::get_container_node(const key_type &k) const
581592
return ip;
582593
}
583594

584-
SHARING_MAPT2(const, leaft *)::get_leaf_node(const key_type &k) const
585-
{
586-
const innert *cp = get_container_node(k);
587-
if(cp == nullptr)
588-
return nullptr;
589-
590-
const leaft *lp;
591-
lp = cp->find_leaf(k);
592-
593-
return lp;
594-
}
595-
596595
/// Erase element
597596
///
598597
/// Complexity:
@@ -618,11 +617,9 @@ SHARING_MAPT2(, size_type)::erase(const key_type &k, const tvt &key_exists)
618617
std::size_t key = hash()(k);
619618
innert *ip = &map;
620619

621-
std::size_t bit;
622-
623620
for(std::size_t i = 0; i < steps; i++)
624621
{
625-
bit = key & mask;
622+
std::size_t bit = key & mask;
626623

627624
const to_mapt &m = as_const(ip)->get_to_map();
628625

src/util/sharing_node.h

+7-9
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ Author: Daniel Poetzl
1212
#ifndef CPROVER_UTIL_SHARING_NODE_H
1313
#define CPROVER_UTIL_SHARING_NODE_H
1414

15-
//#define DEBUG
16-
17-
#ifdef DEBUG
15+
#ifdef SN_DEBUG
1816
#include <iostream>
1917
#endif
2018

@@ -40,8 +38,6 @@ Author: Daniel Poetzl
4038
#include "small_shared_ptr.h"
4139
#include "small_shared_two_way_ptr.h"
4240

43-
//#define SN_INTERNAL_CHECKS
44-
4541
#ifdef SN_INTERNAL_CHECKS
4642
#define SN_ASSERT(b) INVARIANT(b, "Sharing node internal invariant")
4743
#define SN_ASSERT_USE(v, b) SN_ASSERT(b)
@@ -50,13 +46,15 @@ Author: Daniel Poetzl
5046
#define SN_ASSERT_USE(v, b) v = v;
5147
#endif
5248

53-
#define SN_TYPE_PAR_DECL \
54-
template <typename keyT, \
55-
typename valueT, \
49+
// clang-format off
50+
#define SN_TYPE_PAR_DECL \
51+
template <typename keyT, \
52+
typename valueT, \
5653
typename equalT = std::equal_to<keyT>>
5754

58-
#define SN_TYPE_PAR_DEF \
55+
#define SN_TYPE_PAR_DEF \
5956
template <typename keyT, typename valueT, typename equalT>
57+
// clang-format on
6058

6159
#define SN_TYPE_ARGS keyT, valueT, equalT
6260

0 commit comments

Comments
 (0)