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