3 // Copyright (C) 2005 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
32 // Permission to use, copy, modify, sell, and distribute this software
33 // is hereby granted without fee, provided that the above copyright
34 // notice appears in all copies, and that both that copyright notice and
35 // this permission notice appear in supporting documentation. None of
36 // the above authors, nor IBM Haifa Research Laboratories, make any
37 // representation about the suitability of this software for any
38 // purpose. It is provided "as is" without express or implied warranty.
41 * @file constructors_destructor_fn_imps.hpp
42 * Contains an implementation class for bin_search_tree_.
46 typename PB_ASSOC_CLASS_C_DEC::node_allocator
47 PB_ASSOC_CLASS_C_DEC::s_node_allocator;
50 PB_ASSOC_CLASS_C_DEC::
51 PB_ASSOC_CLASS_NAME() :
52 m_p_head(s_node_allocator.allocate(1)),
59 PB_ASSOC_DBG_ONLY(assert_valid(true, true);)
63 PB_ASSOC_CLASS_C_DEC::
64 PB_ASSOC_CLASS_NAME(const Cmp_Fn& r_cmp_fn) :
66 m_p_head(s_node_allocator.allocate(1)),
73 PB_ASSOC_DBG_ONLY(assert_valid(true, true);)
77 PB_ASSOC_CLASS_C_DEC::
78 PB_ASSOC_CLASS_NAME(const Cmp_Fn& r_cmp_fn, const Node_Updator& r_node_updator) :
80 Node_Updator(r_node_updator),
81 m_p_head(s_node_allocator.allocate(1)),
88 PB_ASSOC_DBG_ONLY(assert_valid(true, true);)
92 PB_ASSOC_CLASS_C_DEC::
93 PB_ASSOC_CLASS_NAME(const PB_ASSOC_CLASS_C_DEC& r_other) :
94 #ifdef PB_ASSOC_BIN_SEARCH_TREE_DEBUG_
95 my_map_debug_base(r_other),
96 #endif // #ifdef PB_ASSOC_BIN_SEARCH_TREE_DEBUG_
98 Node_Updator(r_other),
99 m_p_head(s_node_allocator.allocate(1)),
106 m_size = r_other.m_size;
108 PB_ASSOC_DBG_ONLY(r_other.assert_valid(true, true);)
112 m_p_head->m_p_parent =
113 recursive_copy_node(r_other.m_p_head->m_p_parent);
115 if (m_p_head->m_p_parent != NULL)
116 m_p_head->m_p_parent->m_p_parent = m_p_head;
118 m_size = r_other.m_size;
120 initialize_min_max();
124 PB_ASSOC_DBG_ONLY(my_map_debug_base::clear();)
126 s_node_allocator.deallocate(m_p_head, 1);
131 PB_ASSOC_DBG_ONLY(assert_valid(true, true);)
136 PB_ASSOC_CLASS_C_DEC::
137 swap(PB_ASSOC_CLASS_C_DEC& r_other)
139 PB_ASSOC_DBG_ONLY(assert_valid(true, true);)
140 PB_ASSOC_DBG_ONLY(r_other.assert_valid(true, true);)
142 PB_ASSOC_DBG_ONLY(my_map_debug_base::swap(r_other);)
144 std::swap(m_p_head, r_other.m_p_head);
146 std::swap(m_size, r_other.m_size);
148 std::swap(m_end_it, r_other.m_end_it);
150 std::swap(m_rend_it, r_other.m_rend_it);
152 std::swap((Cmp_Fn& )(*this), (Cmp_Fn& )r_other);
154 Node_Updator::swap(r_other);
156 PB_ASSOC_DBG_ONLY(assert_valid(true, true);)
157 PB_ASSOC_DBG_ONLY(r_other.assert_valid(true, true);)
161 PB_ASSOC_CLASS_C_DEC::
162 ~PB_ASSOC_CLASS_NAME()
166 s_node_allocator.deallocate(m_p_head, 1);
171 PB_ASSOC_CLASS_C_DEC::
174 m_p_head->m_p_parent = NULL;
175 m_p_head->m_p_left = m_p_head;
176 m_p_head->m_p_right = m_p_head;
182 typename PB_ASSOC_CLASS_C_DEC::node_pointer
183 PB_ASSOC_CLASS_C_DEC::
184 recursive_copy_node(const node_pointer p_nd)
189 node_pointer p_ret = s_node_allocator.allocate(1);
193 new (p_ret) node(*p_nd);
197 s_node_allocator.deallocate(p_ret, 1);
202 p_ret->m_p_left = p_ret->m_p_right = NULL;
206 p_ret->m_p_left = recursive_copy_node(p_nd->m_p_left);
208 p_ret->m_p_right = recursive_copy_node(p_nd->m_p_right);
217 if (p_ret->m_p_left != NULL)
218 p_ret->m_p_left->m_p_parent = p_ret;
220 if (p_ret->m_p_right != NULL)
221 p_ret->m_p_right->m_p_parent = p_ret;
223 PB_ASSOC_DBG_ONLY(assert_node_consistent(p_ret);)
230 PB_ASSOC_CLASS_C_DEC::
233 if (m_p_head->m_p_parent == NULL)
235 m_p_head->m_p_left = m_p_head->m_p_right = m_p_head;
241 node_pointer p_min = m_p_head->m_p_parent;
243 while (p_min->m_p_left != NULL)
244 p_min = p_min->m_p_left;
246 m_p_head->m_p_left = p_min;
250 node_pointer p_max = m_p_head->m_p_parent;
252 while (p_max->m_p_right != NULL)
253 p_max = p_max->m_p_right;
255 m_p_head->m_p_right = p_max;