📄 _hashtable.h
字号:
} ~hashtable() { clear(); } size_type size() const { return _M_num_elements._M_data; } size_type max_size() const { return size_type(-1); } bool empty() const { return size() == 0; } void swap(_Self& __ht) { _STLP_STD::swap(_M_hash, __ht._M_hash); _STLP_STD::swap(_M_equals, __ht._M_equals); _STLP_STD::swap(_M_get_key, __ht._M_get_key); _M_buckets.swap(__ht._M_buckets); _STLP_STD::swap(_M_num_elements, __ht._M_num_elements); } iterator begin() { for (size_type __n = 0; __n < _M_buckets.size(); ++__n) if (_M_buckets[__n]) return iterator((_Node*)_M_buckets[__n], this); return end(); } iterator end() { return iterator((_Node*)0, this); } const_iterator begin() const { for (size_type __n = 0; __n < _M_buckets.size(); ++__n) if (_M_buckets[__n]) return const_iterator((_Node*)_M_buckets[__n], this); return end(); } const_iterator end() const { return const_iterator((_Node*)0, this); } static bool _STLP_CALL _M_equal (const hashtable<_Val, _Key, _HF, _ExK, _EqK, _All>&, const hashtable<_Val, _Key, _HF, _ExK, _EqK, _All>&);public: size_type bucket_count() const { return _M_buckets.size(); } size_type max_bucket_count() const { return _Stl_prime_type::_M_list[(int)__stl_num_primes - 1]; } size_type elems_in_bucket(size_type __bucket) const { size_type __result = 0; for (_Node* __cur = (_Node*)_M_buckets[__bucket]; __cur; __cur = __cur->_M_next) __result += 1; return __result; } pair<iterator, bool> insert_unique(const value_type& __obj) { resize(_M_num_elements._M_data + 1); return insert_unique_noresize(__obj); } iterator insert_equal(const value_type& __obj) { resize(_M_num_elements._M_data + 1); return insert_equal_noresize(__obj); } pair<iterator, bool> insert_unique_noresize(const value_type& __obj); iterator insert_equal_noresize(const value_type& __obj); #ifdef _STLP_MEMBER_TEMPLATES template <class _InputIterator> void insert_unique(_InputIterator __f, _InputIterator __l) { insert_unique(__f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIterator)); } template <class _InputIterator> void insert_equal(_InputIterator __f, _InputIterator __l) { insert_equal(__f, __l, _STLP_ITERATOR_CATEGORY(__f, _InputIterator)); } template <class _InputIterator> void insert_unique(_InputIterator __f, _InputIterator __l, const input_iterator_tag &) { for ( ; __f != __l; ++__f) insert_unique(*__f); } template <class _InputIterator> void insert_equal(_InputIterator __f, _InputIterator __l, const input_iterator_tag &) { for ( ; __f != __l; ++__f) insert_equal(*__f); } template <class _ForwardIterator> void insert_unique(_ForwardIterator __f, _ForwardIterator __l, const forward_iterator_tag &) { size_type __n = distance(__f, __l); resize(_M_num_elements._M_data + __n); for ( ; __n > 0; --__n, ++__f) insert_unique_noresize(*__f); } template <class _ForwardIterator> void insert_equal(_ForwardIterator __f, _ForwardIterator __l, const forward_iterator_tag &) { size_type __n = distance(__f, __l); resize(_M_num_elements._M_data + __n); for ( ; __n > 0; --__n, ++__f) insert_equal_noresize(*__f); }#else /* _STLP_MEMBER_TEMPLATES */ void insert_unique(const value_type* __f, const value_type* __l) { size_type __n = __l - __f; resize(_M_num_elements._M_data + __n); for ( ; __n > 0; --__n, ++__f) insert_unique_noresize(*__f); } void insert_equal(const value_type* __f, const value_type* __l) { size_type __n = __l - __f; resize(_M_num_elements._M_data + __n); for ( ; __n > 0; --__n, ++__f) insert_equal_noresize(*__f); } void insert_unique(const_iterator __f, const_iterator __l) { size_type __n = distance(__f, __l); resize(_M_num_elements._M_data + __n); for ( ; __n > 0; --__n, ++__f) insert_unique_noresize(*__f); } void insert_equal(const_iterator __f, const_iterator __l) { size_type __n = distance(__f, __l); resize(_M_num_elements._M_data + __n); for ( ; __n > 0; --__n, ++__f) insert_equal_noresize(*__f); }#endif /*_STLP_MEMBER_TEMPLATES */ reference find_or_insert(const value_type& __obj);private:# if defined(_STLP_MEMBER_TEMPLATES) && ! defined ( _STLP_NO_EXTENSIONS ) && !(defined(__MRC__)||(defined(__SC__)&&!defined(__DMC_))) template <class _KT> _Node* _M_find(const _KT& __key) const# else _Node* _M_find(const key_type& __key) const# endif { size_type __n = _M_hash(__key)% _M_buckets.size(); _Node* __first; for ( __first = (_Node*)_M_buckets[__n]; __first && !_M_equals(_M_get_key(__first->_M_val), __key); __first = __first->_M_next) {} return __first; } public:# if defined(_STLP_MEMBER_TEMPLATES) && ! defined ( _STLP_NO_EXTENSIONS ) && !(defined(__MRC__)||(defined(__SC__)&&!defined(__DMC__))) template <class _KT> iterator find(const _KT& __key) # else iterator find(const key_type& __key) # endif { return iterator(_M_find(__key), this); } # if defined(_STLP_MEMBER_TEMPLATES) && ! defined ( _STLP_NO_EXTENSIONS ) && !(defined(__MRC__)||(defined(__SC__)&&!defined(__DMC__))) template <class _KT> const_iterator find(const _KT& __key) const# else const_iterator find(const key_type& __key) const# endif { return const_iterator(_M_find(__key), this); } size_type count(const key_type& __key) const { const size_type __n = _M_bkt_num_key(__key); size_type __result = 0; for (const _Node* __cur = (_Node*)_M_buckets[__n]; __cur; __cur = __cur->_M_next) if (_M_equals(_M_get_key(__cur->_M_val), __key)) ++__result; return __result; } pair<iterator, iterator> equal_range(const key_type& __key); pair<const_iterator, const_iterator> equal_range(const key_type& __key) const; size_type erase(const key_type& __key); // void erase(const iterator& __it); ` void erase(const const_iterator& __it) ; // void erase(const const_iterator& __first, const const_iterator __last) { // erase((const iterator&)__first, (const iterator&)__last); // } void erase(const_iterator __first, const_iterator __last); void resize(size_type __num_elements_hint); void clear();public: // this is for hash_map::operator[] reference _M_insert(const value_type& __obj);private: size_type _M_next_size(size_type __n) const; void _M_initialize_buckets(size_type __n) { const size_type __n_buckets = _M_next_size(__n); _M_buckets.reserve(__n_buckets); _M_buckets.insert(_M_buckets.end(), __n_buckets, (void*) 0); _M_num_elements._M_data = 0; } size_type _M_bkt_num_key(const key_type& __key) const { return _M_bkt_num_key(__key, _M_buckets.size()); } size_type _M_bkt_num(const value_type& __obj) const { return _M_bkt_num_key(_M_get_key(__obj)); } size_type _M_bkt_num_key(const key_type& __key, size_t __n) const { return _M_hash(__key) % __n; } size_type _M_bkt_num(const value_type& __obj, size_t __n) const { return _M_bkt_num_key(_M_get_key(__obj), __n); } _Node* _M_new_node(const value_type& __obj) { _Node* __n = _M_num_elements.allocate(1); __n->_M_next = 0; _STLP_TRY { _Construct(&__n->_M_val, __obj); // return __n; } _STLP_UNWIND(_M_num_elements.deallocate(__n, 1)); return __n; } void _M_delete_node(_Node* __n) { _STLP_STD::_Destroy(&__n->_M_val); _M_num_elements.deallocate(__n, 1); } void _M_erase_bucket(const size_type __n, _Node* __first, _Node* __last); void _M_erase_bucket(const size_type __n, _Node* __last); void _M_copy_from(const _Self& __ht);};#define _STLP_TEMPLATE_HEADER template <class _Val, class _Key, class _HF, class _ExK, class _EqK, class _All>#define _STLP_TEMPLATE_CONTAINER hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>#include <stl/_relops_hash_cont.h>#undef _STLP_TEMPLATE_CONTAINER#undef _STLP_TEMPLATE_HEADER_STLP_END_NAMESPACE# undef hashtable# if !defined (_STLP_LINK_TIME_INSTANTIATION)# include <stl/_hashtable.c># endif# if defined (_STLP_DEBUG)# include <stl/debug/_hashtable.h># endif#endif /* _STLP_INTERNAL_HASHTABLE_H */// Local Variables:// mode:C++// End:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -