?? stl_tree.h
字號(hào):
{ return (_Link_type&) _M_header._M_data->_M_parent; }
_Link_type& _M_leftmost() const
{ return (_Link_type&) _M_header._M_data->_M_left; }
_Link_type& _M_rightmost() const
{ return (_Link_type&) _M_header._M_data->_M_right; }
static _Link_type& _S_left(_Link_type __x)
{ return (_Link_type&)(__x->_M_left); }
static _Link_type& _S_right(_Link_type __x)
{ return (_Link_type&)(__x->_M_right); }
static _Link_type& _S_parent(_Link_type __x)
{ return (_Link_type&)(__x->_M_parent); }
static reference _S_value(_Link_type __x)
{ return __x->_M_value_field; }
static const _Key& _S_key(_Link_type __x)
{ return _KeyOfValue()(_S_value(__x)); }
static _Color_type& _S_color(_Link_type __x)
{ return (_Color_type&)(__x->_M_color); }
static _Link_type& _S_left(_Base_ptr __x)
{ return (_Link_type&)(__x->_M_left); }
static _Link_type& _S_right(_Base_ptr __x)
{ return (_Link_type&)(__x->_M_right); }
static _Link_type& _S_parent(_Base_ptr __x)
{ return (_Link_type&)(__x->_M_parent); }
static reference _S_value(_Base_ptr __x)
{ return ((_Link_type)__x)->_M_value_field; }
static const _Key& _S_key(_Base_ptr __x)
{ return _KeyOfValue()(_S_value(_Link_type(__x)));}
static _Color_type& _S_color(_Base_ptr __x)
{ return (_Color_type&)(_Link_type(__x)->_M_color); }
static _Link_type _S_minimum(_Link_type __x)
{ return (_Link_type) _Rb_tree_node_base::_S_minimum(__x); }
static _Link_type _S_maximum(_Link_type __x)
{ return (_Link_type) _Rb_tree_node_base::_S_maximum(__x); }
public:
typedef _Rb_tree_iterator<value_type, _Nonconst_traits<value_type> > iterator;
typedef _Rb_tree_iterator<value_type, _Const_traits<value_type> > const_iterator;
#if defined ( __STL_CLASS_PARTIAL_SPECIALIZATION ) && \
! defined (__STL_PARTIAL_SPECIALIZATION_BUG)
typedef __STLPORT_STD::reverse_iterator<const_iterator> const_reverse_iterator;
typedef __STLPORT_STD::reverse_iterator<iterator> reverse_iterator;
#else /* __STL_CLASS_PARTIAL_SPECIALIZATION */
# if defined (__STL_MSVC50_COMPATIBILITY)
typedef reverse_bidirectional_iterator<iterator, value_type, reference,
pointer, difference_type>
reverse_iterator;
typedef reverse_bidirectional_iterator<const_iterator, value_type,
const_reference, const_pointer, difference_type>
const_reverse_iterator;
# else
typedef reverse_bidirectional_iterator<iterator, value_type, reference,
difference_type>
reverse_iterator;
typedef reverse_bidirectional_iterator<const_iterator, value_type,
const_reference, difference_type>
const_reverse_iterator;
# endif
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
private:
iterator _M_insert(_Base_ptr __x, _Base_ptr __y, const value_type& __v);
_Link_type _M_copy(_Link_type __x, _Link_type __p);
void _M_erase(_Link_type __x);
public:
// allocation/deallocation
_Rb_tree()
: _Rb_tree_base<_Value, _Alloc>(allocator_type()), _M_node_count(0), _M_key_compare(_Compare())
{ _M_empty_initialize(); }
_Rb_tree(const _Compare& __comp)
: _Rb_tree_base<_Value, _Alloc>(allocator_type()), _M_node_count(0), _M_key_compare(__comp)
{ _M_empty_initialize(); }
_Rb_tree(const _Compare& __comp, const allocator_type& __a)
: _Rb_tree_base<_Value, _Alloc>(__a), _M_node_count(0), _M_key_compare(__comp)
{ _M_empty_initialize(); }
_Rb_tree(const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __x)
: _Rb_tree_base<_Value, _Alloc>(__x.get_allocator()),
_M_node_count(0), _M_key_compare(__x._M_key_compare)
{
if (__x._M_root() == 0)
_M_empty_initialize();
else {
_S_color(_M_header._M_data) = _S_rb_tree_red;
_M_root() = _M_copy(__x._M_root(), _M_header._M_data);
_M_leftmost() = _S_minimum(_M_root());
_M_rightmost() = _S_maximum(_M_root());
}
_M_node_count = __x._M_node_count;
}
~_Rb_tree() { clear(); }
_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>&
operator=(const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __x);
private:
void _M_empty_initialize() {
_S_color(_M_header._M_data) = _S_rb_tree_red; // used to distinguish header from
// __root, in iterator.operator++
_M_root() = 0;
_M_leftmost() = _M_header._M_data;
_M_rightmost() = _M_header._M_data;
}
public:
// accessors:
_Compare key_comp() const { return _M_key_compare; }
# if defined (__STL_DEBUG)
iterator begin() { return _Make_iterator(_M_leftmost()); }
const_iterator begin() const { return _Make_const_iterator(_M_leftmost()); }
iterator end() { return _Make_iterator(_M_header._M_data); }
const_iterator end() const { return _Make_const_iterator(_M_header._M_data); }
void _Invalidate_iterator(const iterator& __it) {
__invalidate_iterator(&_M_iter_list,__it);
}
# else
iterator begin() { return _M_leftmost(); }
const_iterator begin() const { return _M_leftmost(); }
iterator end() { return _M_header._M_data; }
const_iterator end() const { return _M_header._M_data; }
# endif
reverse_iterator rbegin() { return reverse_iterator(end()); }
const_reverse_iterator rbegin() const {
return const_reverse_iterator(end());
}
reverse_iterator rend() { return reverse_iterator(begin()); }
const_reverse_iterator rend() const {
return const_reverse_iterator(begin());
}
bool empty() const { return _M_node_count == 0; }
size_type size() const { return _M_node_count; }
size_type max_size() const { return size_type(-1); }
void swap(_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __t) {
__stl_debug_do(_M_iter_list._Swap_owners(__t._M_iter_list, true));
__STLPORT_STD::swap(_M_header._M_data, __t._M_header._M_data);
__STLPORT_STD::swap(_M_node_count, __t._M_node_count);
__STLPORT_STD::swap(_M_key_compare, __t._M_key_compare);
}
public:
// insert/erase
pair<iterator,bool> insert_unique(const value_type& __x);
iterator insert_equal(const value_type& __x);
iterator insert_unique(iterator __position, const value_type& __x);
iterator insert_equal(iterator __position, const value_type& __x);
#ifdef __STL_MEMBER_TEMPLATES
template<class _II>
void insert_equal(_II __first, _II __last) {
for ( ; __first != __last; ++__first)
insert_equal(*__first);
}
template<class _II>
void insert_unique(_II __first, _II __last) {
for ( ; __first != __last; ++__first)
insert_unique(*__first);
}
#else /* __STL_MEMBER_TEMPLATES */
void insert_unique(const_iterator __first, const_iterator __last) {
for ( ; __first != __last; ++__first)
insert_unique(*__first);
}
void insert_unique(const value_type* __first, const value_type* __last) {
for ( ; __first != __last; ++__first)
insert_unique(*__first);
}
void insert_equal(const_iterator __first, const_iterator __last) {
for ( ; __first != __last; ++__first)
insert_equal(*__first);
}
void insert_equal(const value_type* __first, const value_type* __last) {
for ( ; __first != __last; ++__first)
insert_equal(*__first);
}
#endif /* __STL_MEMBER_TEMPLATES */
void erase(iterator __position) {
__stl_debug_check(__check_if_owner(&_M_iter_list,__position));
__stl_verbose_assert(__position._M_node!=_M_header._M_data, _StlMsg_ERASE_PAST_THE_END);
__stl_debug_do(_Invalidate_iterator(__position));
_Link_type __y =
(_Link_type) _Rb_global_inst::_Rebalance_for_erase(__position._M_node,
_M_header._M_data->_M_parent,
_M_header._M_data->_M_left,
_M_header._M_data->_M_right);
destroy_node(__y);
--_M_node_count;
}
size_type erase(const key_type& __x);
void erase(iterator __first, iterator __last);
void erase(const key_type* __first, const key_type* __last);
void clear() {
if (_M_node_count != 0) {
_M_erase(_M_root());
_M_leftmost() = _M_header._M_data;
_M_root() = 0;
_M_rightmost() = _M_header._M_data;
_M_node_count = 0;
__stl_debug_do(_Invalidate_all());
}
}
public:
// set operations:
iterator find(const key_type& __x);
const_iterator find(const key_type& __x) const;
size_type count(const key_type& __x) const;
iterator lower_bound(const key_type& __x);
const_iterator lower_bound(const key_type& __x) const;
iterator upper_bound(const key_type& __x);
const_iterator upper_bound(const key_type& __x) const;
pair<iterator,iterator> equal_range(const key_type& __x) {
return pair<iterator, iterator>(lower_bound(__x), upper_bound(__x));
}
pair<const_iterator, const_iterator> equal_range(const key_type& __x) const {
return pair<const_iterator,const_iterator>(lower_bound(__x),
upper_bound(__x));
}
public:
// Debugging.
bool __rb_verify() const;
};
template <class _Key, class _Value, class _KeyOfValue,
class _Compare, class _Alloc>
inline bool
operator==(const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __x,
const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __y)
{
return __x.size() == __y.size() &&
equal(__x.begin(), __x.end(), __y.begin());
}
template <class _Key, class _Value, class _KeyOfValue,
class _Compare, class _Alloc>
inline bool
operator<(const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __x,
const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __y)
{
return lexicographical_compare(__x.begin(), __x.end(),
__y.begin(), __y.end());
}
#ifdef __STL_USE_SEPARATE_RELOPS_NAMESPACE
template <class _Key, class _Value, class _KeyOfValue,
class _Compare, class _Alloc>
inline bool
operator!=(const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __x,
const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __y) {
return !(__x == __y);
}
template <class _Key, class _Value, class _KeyOfValue,
class _Compare, class _Alloc>
inline bool
operator>(const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __x,
const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __y) {
return __y < __x;
}
template <class _Key, class _Value, class _KeyOfValue,
class _Compare, class _Alloc>
inline bool
operator<=(const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __x,
const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __y) {
return !(__y < __x);
}
template <class _Key, class _Value, class _KeyOfValue,
class _Compare, class _Alloc>
inline bool
operator>=(const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __x,
const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __y) {
return !(__x < __y);
}
#endif /* __STL_USE_SEPARATE_RELOPS_NAMESPACE */
#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
template <class _Key, class _Value, class _KeyOfValue,
class _Compare, class _Alloc>
inline void
swap(_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __x,
_Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __y)
{
__x.swap(__y);
}
#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
// Class rb_tree is not part of the C++ standard. It is provided for
// compatibility with the HP STL.
template <class _Key, class _Value, class _KeyOfValue, class _Compare,
__STL_DEFAULT_ALLOCATOR_SELECT(_Value) >
struct rb_tree : public _Rb_tree<_Key, _Value, _KeyOfValue, _Compare, _Alloc>
{
typedef _Rb_tree<_Key, _Value, _KeyOfValue, _Compare, _Alloc> _Base;
typedef typename _Base::allocator_type allocator_type;
rb_tree()
: _Rb_tree<_Key, _Value, _KeyOfValue, _Compare, _Alloc>(_Compare(), allocator_type()) {}
rb_tree(const _Compare& __comp,
const allocator_type& __a = __STL_ALLOC_INSTANCE(allocator_type))
: _Rb_tree<_Key, _Value, _KeyOfValue, _Compare, _Alloc>(__comp, __a) {}
~rb_tree() {}
};
# undef _Make_iterator
# undef _Make_const_iterator
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
#pragma reset woff 1375
#endif
__STL_END_NAMESPACE
# if !defined (__STL_LINK_TIME_INSTANTIATION)
# include <stl_tree.c>
# endif
#endif /* __SGI_STL_INTERNAL_TREE_H */
// Local Variables:
// mode:C++
// End:
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -