]> gcc.gnu.org Git - gcc.git/blame - libstdc++-v3/include/ext/pb_ds/detail/pat_trie_/constructors_destructor_fn_imps.hpp
Update Copyright years for files modified in 2010.
[gcc.git] / libstdc++-v3 / include / ext / pb_ds / detail / pat_trie_ / constructors_destructor_fn_imps.hpp
CommitLineData
4569a895
AT
1// -*- C++ -*-
2
d652f226
JJ
3// Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010
4// Free Software Foundation, Inc.
4569a895
AT
5//
6// This file is part of the GNU ISO C++ Library. This library is free
7// software; you can redistribute it and/or modify it under the terms
8// of the GNU General Public License as published by the Free Software
748086b7 9// Foundation; either version 3, or (at your option) any later
4569a895
AT
10// version.
11
12// This library is distributed in the hope that it will be useful, but
13// WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15// General Public License for more details.
16
748086b7
JJ
17// Under Section 7 of GPL version 3, you are granted additional
18// permissions described in the GCC Runtime Library Exception, version
19// 3.1, as published by the Free Software Foundation.
20
21// You should have received a copy of the GNU General Public License and
22// a copy of the GCC Runtime Library Exception along with this program;
23// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24// <http://www.gnu.org/licenses/>.
4569a895
AT
25
26// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
27
28// Permission to use, copy, modify, sell, and distribute this software
29// is hereby granted without fee, provided that the above copyright
30// notice appears in all copies, and that both that copyright notice
31// and this permission notice appear in supporting documentation. None
32// of the above authors, nor IBM Haifa Research Laboratories, make any
33// representation about the suitability of this software for any
34// purpose. It is provided "as is" without express or implied
35// warranty.
36
37/**
38 * @file constructors_destructor_fn_imps.hpp
39 * Contains an implementation class for bin_search_tree_.
40 */
41
42PB_DS_CLASS_T_DEC
43typename PB_DS_CLASS_C_DEC::head_allocator
44PB_DS_CLASS_C_DEC::s_head_allocator;
45
46PB_DS_CLASS_T_DEC
47typename PB_DS_CLASS_C_DEC::internal_node_allocator
48PB_DS_CLASS_C_DEC::s_internal_node_allocator;
49
50PB_DS_CLASS_T_DEC
51typename PB_DS_CLASS_C_DEC::leaf_allocator
52PB_DS_CLASS_C_DEC::s_leaf_allocator;
53
54PB_DS_CLASS_T_DEC
55PB_DS_CLASS_C_DEC::
56PB_DS_CLASS_NAME() :
57 m_p_head(s_head_allocator.allocate(1)),
58 m_size(0)
59{
60 initialize();
47bea7b8
BK
61 _GLIBCXX_DEBUG_ONLY(assert_valid();)
62}
4569a895
AT
63
64PB_DS_CLASS_T_DEC
65PB_DS_CLASS_C_DEC::
66PB_DS_CLASS_NAME(const e_access_traits& r_e_access_traits) :
67 synth_e_access_traits(r_e_access_traits),
68 m_p_head(s_head_allocator.allocate(1)),
69 m_size(0)
70{
71 initialize();
47bea7b8
BK
72 _GLIBCXX_DEBUG_ONLY(assert_valid();)
73}
4569a895
AT
74
75PB_DS_CLASS_T_DEC
76PB_DS_CLASS_C_DEC::
77PB_DS_CLASS_NAME(const PB_DS_CLASS_C_DEC& other) :
47bea7b8 78#ifdef _GLIBCXX_DEBUG
551fe1a2 79 debug_base(other),
47bea7b8 80#endif
4569a895
AT
81 synth_e_access_traits(other),
82 node_update(other),
83 m_p_head(s_head_allocator.allocate(1)),
84 m_size(0)
85{
86 initialize();
4569a895 87 m_size = other.m_size;
47bea7b8 88 _GLIBCXX_DEBUG_ONLY(other.assert_valid();)
8fc81078 89 if (other.m_p_head->m_p_parent == 0)
4569a895 90 {
47bea7b8
BK
91 _GLIBCXX_DEBUG_ONLY(assert_valid();)
92 return;
4569a895 93 }
bc2631e0 94 __try
4569a895 95 {
47bea7b8 96 m_p_head->m_p_parent = recursive_copy_node(other.m_p_head->m_p_parent);
4569a895 97 }
bc2631e0 98 __catch(...)
4569a895
AT
99 {
100 s_head_allocator.deallocate(m_p_head, 1);
8fafc2d3 101 __throw_exception_again;
4569a895
AT
102 }
103
104 m_p_head->m_p_min = leftmost_descendant(m_p_head->m_p_parent);
105 m_p_head->m_p_max = rightmost_descendant(m_p_head->m_p_parent);
4569a895 106 m_p_head->m_p_parent->m_p_parent = m_p_head;
47bea7b8
BK
107 _GLIBCXX_DEBUG_ONLY(assert_valid();)
108}
4569a895
AT
109
110PB_DS_CLASS_T_DEC
111void
112PB_DS_CLASS_C_DEC::
113swap(PB_DS_CLASS_C_DEC& other)
114{
47bea7b8
BK
115 _GLIBCXX_DEBUG_ONLY(assert_valid();)
116 _GLIBCXX_DEBUG_ONLY(other.assert_valid();)
117 value_swap(other);
4569a895 118 std::swap((e_access_traits& )(*this), (e_access_traits& )other);
47bea7b8
BK
119 _GLIBCXX_DEBUG_ONLY(assert_valid();)
120 _GLIBCXX_DEBUG_ONLY(other.assert_valid();)
121}
4569a895
AT
122
123PB_DS_CLASS_T_DEC
124void
125PB_DS_CLASS_C_DEC::
126value_swap(PB_DS_CLASS_C_DEC& other)
127{
551fe1a2 128 _GLIBCXX_DEBUG_ONLY(debug_base::swap(other);)
47bea7b8 129 std::swap(m_p_head, other.m_p_head);
4569a895
AT
130 std::swap(m_size, other.m_size);
131}
132
133PB_DS_CLASS_T_DEC
134PB_DS_CLASS_C_DEC::
135~PB_DS_CLASS_NAME()
136{
137 clear();
4569a895
AT
138 s_head_allocator.deallocate(m_p_head, 1);
139}
140
141PB_DS_CLASS_T_DEC
142void
143PB_DS_CLASS_C_DEC::
144initialize()
145{
146 new (m_p_head) head();
8fc81078 147 m_p_head->m_p_parent = 0;
4569a895
AT
148 m_p_head->m_p_min = m_p_head;
149 m_p_head->m_p_max = m_p_head;
4569a895
AT
150 m_size = 0;
151}
152
153PB_DS_CLASS_T_DEC
154template<typename It>
155void
156PB_DS_CLASS_C_DEC::
157copy_from_range(It first_it, It last_it)
158{
159 while (first_it != last_it)
160 insert(*(first_it++));
161}
162
163PB_DS_CLASS_T_DEC
164typename PB_DS_CLASS_C_DEC::node_pointer
165PB_DS_CLASS_C_DEC::
166recursive_copy_node(const_node_pointer p_other_nd)
167{
8fc81078 168 _GLIBCXX_DEBUG_ASSERT(p_other_nd != 0);
4569a895
AT
169 if (p_other_nd->m_type == pat_trie_leaf_node_type)
170 {
47bea7b8 171 const_leaf_pointer p_other_leaf = static_cast<const_leaf_pointer>(p_other_nd);
4569a895
AT
172
173 leaf_pointer p_new_lf = s_leaf_allocator.allocate(1);
4569a895 174 cond_dealtor cond(p_new_lf);
4569a895 175 new (p_new_lf) leaf(p_other_leaf->value());
4569a895 176 apply_update(p_new_lf, (node_update* )this);
4569a895 177 cond.set_no_action_dtor();
4569a895
AT
178 return (p_new_lf);
179 }
180
47bea7b8 181 _GLIBCXX_DEBUG_ASSERT(p_other_nd->m_type == pat_trie_internal_node_type);
4569a895 182 node_pointer a_p_children[internal_node::arr_size];
4569a895 183 size_type child_i = 0;
4569a895
AT
184 const_internal_node_pointer p_other_internal_nd =
185 static_cast<const_internal_node_pointer>(p_other_nd);
186
187 typename internal_node::const_iterator child_it =
188 p_other_internal_nd->begin();
189
190 internal_node_pointer p_ret;
bc2631e0 191 __try
4569a895
AT
192 {
193 while (child_it != p_other_internal_nd->end())
194 a_p_children[child_i++] = recursive_copy_node(*(child_it++));
4569a895
AT
195 p_ret = s_internal_node_allocator.allocate(1);
196 }
bc2631e0 197 __catch(...)
4569a895
AT
198 {
199 while (child_i-- > 0)
200 clear_imp(a_p_children[child_i]);
8fafc2d3 201 __throw_exception_again;
4569a895
AT
202 }
203
47bea7b8 204 new (p_ret) internal_node(p_other_internal_nd->get_e_ind(),
4569a895
AT
205 pref_begin(a_p_children[0]));
206
207 --child_i;
47bea7b8 208 _GLIBCXX_DEBUG_ASSERT(child_i > 1);
4569a895 209 do
47bea7b8
BK
210 p_ret->add_child(a_p_children[child_i], pref_begin(a_p_children[child_i]),
211 pref_end(a_p_children[child_i]), this);
4569a895 212 while (child_i-- > 0);
4569a895 213 apply_update(p_ret, (node_update* )this);
47bea7b8 214 return p_ret;
4569a895 215}
This page took 0.478763 seconds and 5 git commands to generate.