Skip to content

Commit

Permalink
feat(hash_table): operator=(const self&)
Browse files Browse the repository at this point in the history
  • Loading branch information
1nchy committed Sep 28, 2023
1 parent 7a64446 commit 3460c3c
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions hash_table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ template <typename _Key, typename _Value, typename _ExtKey, bool _UniqueKey, typ
public:
hash_table();
hash_table(const self& _ht);
// self& operator=(const self& _r);
self& operator=(const self& _r);
virtual ~hash_table();
template <typename _NodeGen> void _M_assign(const self& _ht, const _NodeGen&);

Expand Down Expand Up @@ -338,14 +338,20 @@ hash_table<_Key, _Value, _ExtKey, _UniqueKey, _Hash, _Alloc>::hash_table(const s
});
};

// template <typename _Key, typename _Value, typename _ExtKey, bool _UniqueKey, typename _Hash, typename _Alloc> auto
// hash_table<_Key, _Value, _ExtKey, _UniqueKey, _Hash, _Alloc>::operator=(const self& _r)
// -> self& {
// if (&_r == this) {
// return *this;
// }

// };
template <typename _Key, typename _Value, typename _ExtKey, bool _UniqueKey, typename _Hash, typename _Alloc> auto
hash_table<_Key, _Value, _ExtKey, _UniqueKey, _Hash, _Alloc>::operator=(const self& _r)
-> self& {
if (&_r == this) return *this;
clear();
_M_assign(_r, [this](const node_type* _n) {
return this->_M_allocate_node(*_n);
});
_element_count = _r.size();
_rehash_policy = _r._rehash_policy;
_bucket_count = _r._bucket_count;
_rehash_bucket_count = _r._rehash_bucket_count;
return *this;
};

template <typename _Key, typename _Value, typename _ExtKey, bool _UniqueKey, typename _Hash, typename _Alloc>
hash_table<_Key, _Value, _ExtKey, _UniqueKey, _Hash, _Alloc>::~hash_table() {
Expand All @@ -365,9 +371,9 @@ _M_assign(const self& _ht, const _NodeGen& _gen) -> void {
_buckets = _t_buckets = this->_M_allocate_buckets(_ht._bucket_count);
_rehash_buckets = _t_rehash_buckets = this->_M_allocate_buckets(_ht._rehash_bucket_count);
}
if (_element_count == 0) {
return;
}
// if (_element_count == 0) {
// return;
// }
const_iterator _ht_n = _ht.cbegin();
node_type* _prev = nullptr;
for (; _ht_n != _ht.cend(); _ht_n._M_incr()) {
Expand Down

0 comments on commit 3460c3c

Please sign in to comment.