43 typename PB_DS_CLASS_C_DEC::node_allocator
44 PB_DS_CLASS_C_DEC::s_node_allocator;
48 PB_DS_BIN_TREE_NAME() : m_p_head(s_node_allocator.allocate(1)), m_size(0)
51 PB_DS_STRUCT_ONLY_ASSERT_VALID((*
this))
56 PB_DS_BIN_TREE_NAME(
const Cmp_Fn& r_cmp_fn) :
57 Cmp_Fn(r_cmp_fn), m_p_head(s_node_allocator.allocate(1)), m_size(0)
60 PB_DS_STRUCT_ONLY_ASSERT_VALID((*
this))
65 PB_DS_BIN_TREE_NAME(
const Cmp_Fn& r_cmp_fn,
const node_update& r_node_update) :
67 node_update(r_node_update),
68 m_p_head(s_node_allocator.allocate(1)),
72 PB_DS_STRUCT_ONLY_ASSERT_VALID((*
this))
77 PB_DS_BIN_TREE_NAME(
const PB_DS_CLASS_C_DEC& other) :
81 #ifdef PB_DS_TREE_TRACE
82 PB_DS_TREE_TRACE_BASE_C_DEC(other),
86 m_p_head(s_node_allocator.allocate(1)),
90 m_size = other.m_size;
91 PB_DS_STRUCT_ONLY_ASSERT_VALID(other)
95 m_p_head->m_p_parent = recursive_copy_node(other.m_p_head->m_p_parent);
96 if (m_p_head->m_p_parent != 0)
97 m_p_head->m_p_parent->m_p_parent = m_p_head;
98 m_size = other.m_size;
103 _GLIBCXX_DEBUG_ONLY(debug_base::clear();)
104 s_node_allocator.deallocate(m_p_head, 1);
105 __throw_exception_again;
107 PB_DS_STRUCT_ONLY_ASSERT_VALID((*
this))
113 swap(PB_DS_CLASS_C_DEC& other)
115 PB_DS_STRUCT_ONLY_ASSERT_VALID((*
this))
116 PB_DS_STRUCT_ONLY_ASSERT_VALID(other)
118 std::swap((Cmp_Fn& )(*this), (Cmp_Fn& )other);
119 PB_DS_STRUCT_ONLY_ASSERT_VALID((*this))
120 PB_DS_STRUCT_ONLY_ASSERT_VALID(other)
126 value_swap(PB_DS_CLASS_C_DEC& other)
128 _GLIBCXX_DEBUG_ONLY(debug_base::swap(other);)
129 std::swap(m_p_head, other.m_p_head);
130 std::swap(m_size, other.m_size);
135 ~PB_DS_BIN_TREE_NAME()
138 s_node_allocator.deallocate(m_p_head, 1);
146 m_p_head->m_p_parent = 0;
147 m_p_head->m_p_left = m_p_head;
148 m_p_head->m_p_right = m_p_head;
153 typename PB_DS_CLASS_C_DEC::node_pointer
155 recursive_copy_node(
const node_pointer p_nd)
160 node_pointer p_ret = s_node_allocator.allocate(1);
163 new (p_ret) node(*p_nd);
167 s_node_allocator.deallocate(p_ret, 1);
168 __throw_exception_again;
171 p_ret->m_p_left = p_ret->m_p_right = 0;
175 p_ret->m_p_left = recursive_copy_node(p_nd->m_p_left);
176 p_ret->m_p_right = recursive_copy_node(p_nd->m_p_right);
181 __throw_exception_again;
184 if (p_ret->m_p_left != 0)
185 p_ret->m_p_left->m_p_parent = p_ret;
187 if (p_ret->m_p_right != 0)
188 p_ret->m_p_right->m_p_parent = p_ret;
190 PB_DS_ASSERT_NODE_CONSISTENT(p_ret)
199 if (m_p_head->m_p_parent == 0)
201 m_p_head->m_p_left = m_p_head->m_p_right = m_p_head;
206 node_pointer p_min = m_p_head->m_p_parent;
207 while (p_min->m_p_left != 0)
208 p_min = p_min->m_p_left;
209 m_p_head->m_p_left = p_min;
213 node_pointer p_max = m_p_head->m_p_parent;
214 while (p_max->m_p_right != 0)
215 p_max = p_max->m_p_right;
216 m_p_head->m_p_right = p_max;