Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libstdc++-v3 / include / ext / pb_assoc / detail / ov_tree_map_ / split_join_fn_imps.hpp
blobb93084bf386d0bd2c3b9e4fb6473cc0283958300
1 // -*- C++ -*-
3 // Copyright (C) 2005 Free Software Foundation, Inc.
4 //
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)
9 // any later version.
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,
19 // USA.
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.
40 /**
41 * @file split_join_fn_imps.hpp
42 * Contains an implementation class for ov_tree_.
45 PB_ASSOC_CLASS_T_DEC
46 void
47 PB_ASSOC_CLASS_C_DEC::
48 split(const_key_reference r_key, PB_ASSOC_CLASS_C_DEC& r_other)
50 PB_ASSOC_DBG_ONLY(assert_valid();)
51 PB_ASSOC_DBG_ONLY(r_other.assert_valid();)
53 if (m_size == 0)
55 r_other.clear();
57 PB_ASSOC_DBG_ONLY(assert_valid();)
58 PB_ASSOC_DBG_ONLY(r_other.assert_valid();)
60 return;
63 if (Cmp_Fn::operator()(r_key, PB_ASSOC_V2F(*begin())))
65 swap(r_other);
67 PB_ASSOC_DBG_ONLY(assert_valid();)
68 PB_ASSOC_DBG_ONLY(r_other.assert_valid();)
70 return;
73 if (!Cmp_Fn::operator()(
74 r_key,
75 PB_ASSOC_V2F(*(end() - 1))))
77 PB_ASSOC_DBG_ONLY(assert_valid();)
78 PB_ASSOC_DBG_ONLY(r_other.assert_valid();)
80 return;
83 if (m_size == 1)
85 swap(r_other);
87 PB_ASSOC_DBG_ONLY(assert_valid();)
88 PB_ASSOC_DBG_ONLY(r_other.assert_valid();)
90 return;
93 #ifdef PB_ASSOC_BIN_SEARCH_TREE_DEBUG_
94 for (const_iterator it = begin(); it != end(); ++it)
95 if (Cmp_Fn::operator()(
96 r_key,
97 PB_ASSOC_V2F(*it)))
99 my_map_debug_base::erase_existing(PB_ASSOC_V2F(*it));
100 r_other.my_map_debug_base::insert_new(PB_ASSOC_V2F(*it));
102 #endif // PB_ASSOC_BIN_SEARCH_TREE_DEBUG_
104 iterator it = upper_bound(r_key);
106 PB_ASSOC_CLASS_C_DEC new_other(r_other, r_other);
108 new_other.copy_from_ordered_range(it, end());
110 PB_ASSOC_CLASS_C_DEC new_this(*this, * this);
112 new_this.copy_from_ordered_range(begin(), it);
114 // No exceptions from this point.
116 r_other.update(r_other.node_begin(), (Node_Updator* )(&r_other));
118 update(node_begin(), (Node_Updator* )this);
120 r_other.swap(new_other);
122 swap(new_this);
124 PB_ASSOC_DBG_ONLY(assert_valid();)
125 PB_ASSOC_DBG_ONLY(r_other.assert_valid();)
128 PB_ASSOC_CLASS_T_DEC
129 void
130 PB_ASSOC_CLASS_C_DEC::
131 join(PB_ASSOC_CLASS_C_DEC& r_other)
133 PB_ASSOC_DBG_ONLY(assert_valid();)
134 PB_ASSOC_DBG_ONLY(r_other.assert_valid();)
136 if (r_other.m_size == 0)
137 return;
139 if (m_size == 0)
141 swap(r_other);
143 return;
146 const bool greater = Cmp_Fn::operator()(
147 PB_ASSOC_V2F(*(end() - 1)),
148 PB_ASSOC_V2F(*r_other.begin()));
150 const bool lesser = Cmp_Fn::operator()(
151 PB_ASSOC_V2F(*(r_other.end() - 1)),
152 PB_ASSOC_V2F(*begin()));
154 if (!greater&& !lesser)
155 throw cannot_join();
157 #ifdef PB_ASSOC_BIN_SEARCH_TREE_DEBUG_
158 for (const_iterator other_it = r_other.begin(); other_it != r_other.end();
159 ++other_it)
161 my_map_debug_base::insert_new(PB_ASSOC_V2F(*other_it));
162 r_other.my_map_debug_base::erase_existing(PB_ASSOC_V2F(*other_it));
164 #endif // PB_ASSOC_BIN_SEARCH_TREE_DEBUG_
166 PB_ASSOC_CLASS_C_DEC new_this(*this, * this);
168 if (greater)
169 new_this.copy_from_ordered_range(
170 begin(),
171 end(),
172 r_other.begin(),
173 r_other.end());
174 else
175 new_this.copy_from_ordered_range(
176 r_other.begin(),
177 r_other.end(),
178 begin(),
179 end());
181 // No exceptions from this point.
183 swap(new_this);
185 r_other.clear();
187 PB_ASSOC_DBG_ONLY(assert_valid();)
188 PB_ASSOC_DBG_ONLY(r_other.assert_valid();)