File tree Expand file tree Collapse file tree 2 files changed +8
-3
lines changed
Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -48,9 +48,14 @@ struct HashTable {
4848
4949 HashTable (HashTable const & other) {
5050 _cap = other._cap ;
51- _slots = new Slot[_cap] ;
51+ _slots = nullptr ;
5252 _len = other._len ;
5353 _dead = other._dead ;
54+
55+ if (_cap == 0 )
56+ return ;
57+
58+ _slots = new Slot[_cap];
5459 for (usize i = 0 ; i < _cap; i++) {
5560 if (other._slots [i].state == State::USED) {
5661 _slots[i]._manual .ctor (other._slots [i].unwrap ());
@@ -143,7 +148,7 @@ struct HashTable {
143148
144149 template <typename Self, Meta::Equatable<T> U>
145150 auto lookup (this Self& self, U const & u) -> Meta::CopyConst<Self, Slot>* {
146- if (not self._slots )
151+ if (not self._slots or self. _cap == 0 )
147152 return nullptr ;
148153
149154 usize start = hash (u) % self._cap ;
Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ struct Map {
6767 _items.put (slot, key, std::forward<decltype (value)>(value));
6868 }
6969
70- [[]] Opt<V> remove (Meta::Equatable<K> auto const & key) {
70+ [[nodiscard ]] Opt<V> remove (Meta::Equatable<K> auto const & key) {
7171 if (auto * slot = _items.lookup (key); slot and slot->state == Items::USED) {
7272 V res = std::move (slot->unwrap ().value );
7373 _items.clear (slot);
You can’t perform that action at this time.
0 commit comments