Skip to content

Commit

Permalink
Use std::size_t instead of unsigned in the sharing map
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoe committed Apr 25, 2018
1 parent 3e22217 commit 47463a3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
28 changes: 12 additions & 16 deletions src/util/sharing_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class sharing_mapt
typedef sharing_mapt<key_type, mapped_type, hash, key_equal> self_type;
typedef sharing_nodet<key_type, mapped_type, key_equal> node_type;

typedef size_t size_type;
typedef std::size_t size_type;

/// Return type of methods that retrieve a const reference to a value. First
/// component is a reference to the value (or a dummy value if the given key
Expand Down Expand Up @@ -165,13 +165,13 @@ class sharing_mapt
static const std::string not_found_msg;

/// Number of bits in the hash deemed significant
static const size_t bits;
static const std::size_t bits;

/// Size of a chunk of the hash that represents a character
static const size_t chunk;
static const std::size_t chunk;

static const size_t mask;
static const size_t steps;
static const std::size_t mask;
static const std::size_t steps;

// interface

Expand Down Expand Up @@ -536,9 +536,9 @@ SHARING_MAPT2(, node_type *)::get_container_node(const key_type &k)
size_t key=hash()(k);
node_type *p=&map;

for(unsigned i=0; i<steps; i++)
for(std::size_t i = 0; i < steps; i++)
{
unsigned bit=key&mask;
std::size_t bit = key & mask;
key>>=chunk;

p=p->add_child(bit);
Expand All @@ -552,9 +552,9 @@ SHARING_MAPT2(const, node_type *)::get_container_node(const key_type &k) const
size_t key=hash()(k);
const node_type *p=&map;

for(unsigned i=0; i<steps; i++)
for(std::size_t i = 0; i < steps; i++)
{
unsigned bit=key&mask;
std::size_t bit = key & mask;
key>>=chunk;

p=p->find_child(bit);
Expand Down Expand Up @@ -598,14 +598,14 @@ SHARING_MAPT2(, size_type)::erase(
return 0;

node_type *del=nullptr;
unsigned del_bit = 0;
std::size_t del_bit = 0;

size_t key=hash()(k);
node_type *p=&map;

for(unsigned i=0; i<steps; i++)
for(std::size_t i = 0; i < steps; i++)
{
unsigned bit=key&mask;
std::size_t bit = key & mask;
key>>=chunk;

const subt &sub=as_const(p)->get_sub();
Expand Down Expand Up @@ -712,8 +712,6 @@ SHARING_MAPT2(, const_find_type)::insert(
///
/// \param k: The key of the element to insert
/// \param m: The mapped value to insert
/// \param key_exists: Hint to indicate whether the element is known to exist
/// (possible values false or unknown)
/// \return Pair of reference to existing or newly inserted element, and boolean
/// indicating if new element was inserted
SHARING_MAPT2(, find_type)::place(
Expand Down Expand Up @@ -778,8 +776,6 @@ SHARING_MAPT2(, find_type)::find(
/// - Best case: O(H)
///
/// \param k: The key of the element to search
/// \param key_exists: Hint to indicate whether the element is known to exist
/// (possible values `unknown` or `true`)
/// \return Pair of const reference to found value (or dummy value if not
/// found), and boolean indicating if element was found.
SHARING_MAPT2(, const_find_type)::find(const key_type &k) const
Expand Down
8 changes: 4 additions & 4 deletions src/util/sharing_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class sharing_nodet

typedef sharing_nodet<key_type, mapped_type, key_equal> self_type;

typedef std::map<unsigned, self_type> subt;
typedef std::map<std::size_t, self_type> subt;
typedef std::list<self_type> containert;

typedef const std::pair<const self_type &, const bool> const_find_type;
Expand Down Expand Up @@ -156,7 +156,7 @@ class sharing_nodet

// internal nodes

const self_type *find_child(const unsigned n) const
const self_type *find_child(const std::size_t n) const
{
const subt &s=get_sub();
typename subt::const_iterator it=s.find(n);
Expand All @@ -167,13 +167,13 @@ class sharing_nodet
return nullptr;
}

self_type *add_child(const unsigned n)
self_type *add_child(const std::size_t n)
{
subt &s=get_sub();
return &s[n];
}

void remove_child(const unsigned n)
void remove_child(const std::size_t n)
{
subt &s=get_sub();
size_t r=s.erase(n);
Expand Down

0 comments on commit 47463a3

Please sign in to comment.