fix(library/phash_map,library/phashtable): missing const and operator

This commit is contained in:
Leonardo de Moura 2017-05-08 14:29:07 -07:00
parent d2b6b3f573
commit bea122bb22
2 changed files with 16 additions and 2 deletions

View file

@ -30,6 +30,10 @@ public:
default_map_entry() {}
default_map_entry(key_value const & d, unsigned h):parent(d, h) {}
static default_map_entry mk_deleted() { return default_map_entry(false); }
default_map_entry & operator=(default_map_entry const & src) {
parent::operator=(src);
return *this;
}
};
template<typename Entry, typename HashProc, typename EqProc, bool ThreadSafe>
@ -97,7 +101,7 @@ public:
}
template<typename F>
void for_each(F && f) {
void for_each(F && f) const {
m_table.for_each([&](key_value const & e) {
f(e.m_key, e.m_value);
});

View file

@ -59,6 +59,16 @@ public:
new (&m_data) T(d);
m_state = Used;
}
default_hash_entry & operator=(default_hash_entry const & src) {
if (is_used())
m_data.~T();
m_hash = src.m_hash;
m_state = src.m_state;
if (m_state == Used)
new (&m_data) T(src.get_data());
return *this;
}
};
template<typename Entry, typename HashProc, typename EqProc, bool ThreadSafe = false>
@ -194,7 +204,7 @@ public:
#undef INSERT_LOOP_BODY
template<typename F>
void for_each(F && fn) {
void for_each(F && fn) const {
m_table.for_each([&](entry const & e) {
if (e.is_used()) {
fn(e.get_data());