diff --git a/ostd/internal/hashtable.hh b/ostd/internal/hashtable.hh index 51e34e4..a1d271d 100644 --- a/ostd/internal/hashtable.hh +++ b/ostd/internal/hashtable.hh @@ -283,13 +283,6 @@ private: } } - T *access_base(const K &key, Size &h) const { - if (!p_size) return NULL; - Chain *c = find(key, h); - if (c) return &B::get_data(c->value); - return nullptr; - } - void rehash_ahead(Size n) { if (!bucket_count()) reserve(n); @@ -307,23 +300,25 @@ protected: T &access_or_insert(const K &key) { Size h = 0; - T *v = access_base(key, h); - if (v) return *v; + Chain *c = find(key, h); + if (c) return B::get_data(c->value); rehash_ahead(1); return insert(h, key); } T &access_or_insert(K &&key) { Size h = 0; - T *v = access_base(key, h); - if (v) return *v; + Chain *c = find(key, h); + if (c) return B::get_data(c->value); rehash_ahead(1); return insert(h, move(key)); } - T &access(const K &key) const { + T *access(const K &key) const { Size h; - return *access_base(key, h); + Chain *c = find(key, h); + if (c) return &B::get_data(c->value); + return nullptr; } template @@ -505,7 +500,7 @@ public: Size bucket_size(Size n) const { Size ret = 0; - if (ret >= p_size) return ret; + if (n >= p_size) return ret; Chain **cp = p_data.first(); for (Chain *c = cp[n], *e = cp[n + 1]; c != e; c = c->next) ++ret; diff --git a/ostd/map.hh b/ostd/map.hh index ad9dd92..a46d393 100644 --- a/ostd/map.hh +++ b/ostd/map.hh @@ -139,11 +139,11 @@ namespace detail { return *this; } - T &at(const K &key) { + T *at(const K &key) { static_assert(!IsMultihash, "at() only allowed on regular maps"); return Base::access(key); } - const T &at(const K &key) const { + const T *at(const K &key) const { static_assert(!IsMultihash, "at() only allowed on regular maps"); return Base::access(key); }