设为首页 加入收藏

TOP

C++ STL源码学习(之RB Tree篇)(五)
2015-07-20 17:30:19 来源: 作者: 【 】 浏览:25
Tags:STL 源码 学习 Tree篇
mp; } _Link_type _M_clone_node(_Link_type __x) { _Link_type __tmp = _M_create_node(__x->_M_value_field); __tmp->_M_color = __x->_M_color; __tmp->_M_left = 0; __tmp->_M_right = 0; return __tmp; } void destroy_node(_Link_type __p) { destroy(&__p->_M_value_field); _M_put_node(__p); } protected: size_type _M_node_count; /// keeps track of size of tree _Compare _M_key_compare; _Link_type& _M_root() const ///_M_header和_M_root互为父节点 { return (_Link_type&) _M_header->_M_parent; } _Link_type& _M_leftmost() const ///_M_header->_M_left指向最小值,即最左端结点 { return (_Link_type&) _M_header->_M_left; } _Link_type& _M_rightmost() const ///_M_header->_M_right指向最大值,即最右端结点 { return (_Link_type&) _M_header->_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 iterator; typedef _Rb_tree_iterator const_iterator; typedef reverse_bidirectional_iterator reverse_iterator; typedef reverse_bidirectional_iterator const_reverse_iterator; 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() : _Base(allocator_type()), _M_node_count(0), _M_key_compare() { _M_empty_initialize(); } _Rb_tree(const _Compare& __comp) : _Base(allocator_type()), _M_node_count(0), _M_key_compare(__comp) { _M_empty_initialize(); } _Rb_tree(const _Compare& __comp, const allocator_type& __a) : _Base(__a), _M_node_count(0), _M_key_compare(__comp) { _M_empty_initialize(); } _Rb_tree(const _Rb_tree<_Key,_Value,_KeyOfValue,_Compare,_Alloc>& __x) ///copy constructor : _Base(__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) = _S_rb_tree_red; _M_root() = _M_copy(__x._M_root(), _M_header); _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) = _S_rb_tree_red; /// used to distinguish header f
首页 上一页 2 3 4 5 6 7 8 下一页 尾页 5/9/9
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇poj 2482 Stars in Your Window(.. 下一篇Codeforces Round #271 (Div. 2)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Bash 脚本教程——Li (2025-12-26 07:53:35)
·实战篇!Linux shell (2025-12-26 07:53:32)
·整理了250个shell脚 (2025-12-26 07:53:29)
·HyperText Transfer (2025-12-26 07:20:48)
·半小时搞懂 HTTP、HT (2025-12-26 07:20:42)