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 split_join_fn_imps.hpp
42 * Contains an implementation class for bin_search_tree_.
47 PB_ASSOC_CLASS_C_DEC::
48 join_prep(PB_ASSOC_CLASS_C_DEC& r_other)
50 PB_ASSOC_DBG_ONLY(assert_valid(true, true);)
51 PB_ASSOC_DBG_ONLY(r_other.assert_valid(true, true);)
53 if (r_other.m_size == 0)
63 const bool greater = Cmp_Fn::operator()(
64 PB_ASSOC_V2F(m_p_head->m_p_right->m_value),
65 PB_ASSOC_V2F(r_other.m_p_head->m_p_left->m_value));
67 const bool lesser = Cmp_Fn::operator()(
68 PB_ASSOC_V2F(r_other.m_p_head->m_p_right->m_value),
69 PB_ASSOC_V2F(m_p_head->m_p_left->m_value));
71 if (!greater&& !lesser)
77 m_size += r_other.m_size;
79 #ifdef PB_ASSOC_BIN_SEARCH_TREE_DEBUG_
80 for (const_iterator other_it = r_other.begin(); other_it != r_other.end();
83 my_map_debug_base::insert_new(PB_ASSOC_V2F(*other_it));
84 r_other.my_map_debug_base::erase_existing(PB_ASSOC_V2F(*other_it));
86 #endif // PB_ASSOC_BIN_SEARCH_TREE_DEBUG_
93 PB_ASSOC_CLASS_C_DEC::
94 join_finish(PB_ASSOC_CLASS_C_DEC& r_other)
103 PB_ASSOC_CLASS_C_DEC::
104 split_prep(const_key_reference r_key, PB_ASSOC_CLASS_C_DEC& r_other)
106 PB_ASSOC_DBG_ONLY(assert_valid(true, true);)
107 PB_ASSOC_DBG_ONLY(r_other.assert_valid(true, true);)
113 PB_ASSOC_DBG_ONLY(assert_valid(true, true);)
114 PB_ASSOC_DBG_ONLY(r_other.assert_valid(true, true);)
119 if (Cmp_Fn::operator()(r_key, PB_ASSOC_V2F(m_p_head->m_p_left->m_value)))
123 PB_ASSOC_DBG_ONLY(assert_valid(true, true);)
124 PB_ASSOC_DBG_ONLY(r_other.assert_valid(true, true);)
129 if (!Cmp_Fn::operator()(
131 PB_ASSOC_V2F(m_p_head->m_p_right->m_value)))
133 PB_ASSOC_DBG_ONLY(assert_valid(true, true);)
134 PB_ASSOC_DBG_ONLY(r_other.assert_valid(true, true);)
143 PB_ASSOC_DBG_ONLY(assert_valid(true, true);)
144 PB_ASSOC_DBG_ONLY(r_other.assert_valid(true, true);)
149 #ifdef PB_ASSOC_BIN_SEARCH_TREE_DEBUG_
150 for (const_iterator it = begin(); it != end(); ++it)
151 if (Cmp_Fn::operator()(
155 my_map_debug_base::erase_existing(PB_ASSOC_V2F(*it));
156 r_other.my_map_debug_base::insert_new(PB_ASSOC_V2F(*it));
158 #endif // PB_ASSOC_BIN_SEARCH_TREE_DEBUG_
165 PB_ASSOC_CLASS_C_DEC::
166 split_finish(PB_ASSOC_CLASS_C_DEC& r_other)
168 r_other.m_size = r_other.recursive_count(r_other.m_p_head->m_p_parent);
170 r_other.initialize_min_max();
172 m_size -= r_other.m_size;
174 initialize_min_max();
176 PB_ASSOC_DBG_ONLY(assert_valid(true, true);)
177 PB_ASSOC_DBG_ONLY(r_other.assert_valid(true, true);)
181 typename PB_ASSOC_CLASS_C_DEC::size_type
182 PB_ASSOC_CLASS_C_DEC::
183 recursive_count(node_pointer p_nd) const
189 recursive_count(p_nd->m_p_left) +
190 recursive_count(p_nd->m_p_right));