]> 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
4f4a327e 1 // -*- C++ -*-
36fed23c 2
fbd26352 3// Copyright (C) 2005-2019 Free Software Foundation, Inc.
36fed23c 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
6bc9506f 8// Foundation; either version 3, or (at your option) any later
36fed23c 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
6bc9506f 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/>.
36fed23c 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/**
4f4a327e 37 * @file pat_trie_/constructors_destructor_fn_imps.hpp
38 * Contains an implementation class for pat_trie.
36fed23c 39 */
40
41PB_DS_CLASS_T_DEC
42typename PB_DS_CLASS_C_DEC::head_allocator
43PB_DS_CLASS_C_DEC::s_head_allocator;
44
45PB_DS_CLASS_T_DEC
4f4a327e 46typename PB_DS_CLASS_C_DEC::inode_allocator
47PB_DS_CLASS_C_DEC::s_inode_allocator;
36fed23c 48
49PB_DS_CLASS_T_DEC
50typename PB_DS_CLASS_C_DEC::leaf_allocator
51PB_DS_CLASS_C_DEC::s_leaf_allocator;
52
53PB_DS_CLASS_T_DEC
54PB_DS_CLASS_C_DEC::
4f4a327e 55PB_DS_PAT_TRIE_NAME() :
36fed23c 56 m_p_head(s_head_allocator.allocate(1)),
57 m_size(0)
58{
59 initialize();
2548203e 60 PB_DS_ASSERT_VALID((*this))
2b31bec4 61}
36fed23c 62
63PB_DS_CLASS_T_DEC
64PB_DS_CLASS_C_DEC::
4f4a327e 65PB_DS_PAT_TRIE_NAME(const access_traits& r_access_traits) :
66 synth_access_traits(r_access_traits),
36fed23c 67 m_p_head(s_head_allocator.allocate(1)),
68 m_size(0)
69{
70 initialize();
2548203e 71 PB_DS_ASSERT_VALID((*this))
2b31bec4 72}
36fed23c 73
74PB_DS_CLASS_T_DEC
75PB_DS_CLASS_C_DEC::
4f4a327e 76PB_DS_PAT_TRIE_NAME(const PB_DS_CLASS_C_DEC& other) :
2b31bec4 77#ifdef _GLIBCXX_DEBUG
6c9bd031 78 debug_base(other),
5a2b9207 79#endif
4f4a327e 80 synth_access_traits(other),
36fed23c 81 node_update(other),
82 m_p_head(s_head_allocator.allocate(1)),
83 m_size(0)
84{
85 initialize();
36fed23c 86 m_size = other.m_size;
2548203e 87 PB_DS_ASSERT_VALID(other)
e4bb1925 88 if (other.m_p_head->m_p_parent == 0)
36fed23c 89 {
2548203e 90 PB_DS_ASSERT_VALID((*this))
5a2b9207 91 return;
36fed23c 92 }
b1a09c64 93 __try
36fed23c 94 {
2b31bec4 95 m_p_head->m_p_parent = recursive_copy_node(other.m_p_head->m_p_parent);
36fed23c 96 }
b1a09c64 97 __catch(...)
36fed23c 98 {
99 s_head_allocator.deallocate(m_p_head, 1);
c4f08cc0 100 __throw_exception_again;
36fed23c 101 }
102
103 m_p_head->m_p_min = leftmost_descendant(m_p_head->m_p_parent);
104 m_p_head->m_p_max = rightmost_descendant(m_p_head->m_p_parent);
36fed23c 105 m_p_head->m_p_parent->m_p_parent = m_p_head;
2548203e 106 PB_DS_ASSERT_VALID((*this))
2b31bec4 107}
36fed23c 108
109PB_DS_CLASS_T_DEC
110void
111PB_DS_CLASS_C_DEC::
112swap(PB_DS_CLASS_C_DEC& other)
113{
2548203e 114 PB_DS_ASSERT_VALID((*this))
115 PB_DS_ASSERT_VALID(other)
2b31bec4 116 value_swap(other);
4f4a327e 117 std::swap((access_traits& )(*this), (access_traits& )other);
2548203e 118 PB_DS_ASSERT_VALID((*this))
119 PB_DS_ASSERT_VALID(other)
2b31bec4 120}
36fed23c 121
122PB_DS_CLASS_T_DEC
123void
124PB_DS_CLASS_C_DEC::
125value_swap(PB_DS_CLASS_C_DEC& other)
126{
6c9bd031 127 _GLIBCXX_DEBUG_ONLY(debug_base::swap(other);)
2b31bec4 128 std::swap(m_p_head, other.m_p_head);
36fed23c 129 std::swap(m_size, other.m_size);
130}
131
132PB_DS_CLASS_T_DEC
133PB_DS_CLASS_C_DEC::
4f4a327e 134~PB_DS_PAT_TRIE_NAME()
36fed23c 135{
136 clear();
36fed23c 137 s_head_allocator.deallocate(m_p_head, 1);
138}
139
140PB_DS_CLASS_T_DEC
141void
142PB_DS_CLASS_C_DEC::
143initialize()
144{
145 new (m_p_head) head();
e4bb1925 146 m_p_head->m_p_parent = 0;
36fed23c 147 m_p_head->m_p_min = m_p_head;
148 m_p_head->m_p_max = m_p_head;
36fed23c 149 m_size = 0;
150}
151
152PB_DS_CLASS_T_DEC
153template<typename It>
154void
155PB_DS_CLASS_C_DEC::
156copy_from_range(It first_it, It last_it)
157{
158 while (first_it != last_it)
159 insert(*(first_it++));
160}
161
162PB_DS_CLASS_T_DEC
163typename PB_DS_CLASS_C_DEC::node_pointer
164PB_DS_CLASS_C_DEC::
4f4a327e 165recursive_copy_node(node_const_pointer p_ncp)
36fed23c 166{
4f4a327e 167 _GLIBCXX_DEBUG_ASSERT(p_ncp != 0);
168 if (p_ncp->m_type == leaf_node)
36fed23c 169 {
4f4a327e 170 leaf_const_pointer p_other_lf = static_cast<leaf_const_pointer>(p_ncp);
36fed23c 171 leaf_pointer p_new_lf = s_leaf_allocator.allocate(1);
36fed23c 172 cond_dealtor cond(p_new_lf);
4f4a327e 173 new (p_new_lf) leaf(p_other_lf->value());
174 apply_update(p_new_lf, (node_update*)this);
36fed23c 175 cond.set_no_action_dtor();
36fed23c 176 return (p_new_lf);
177 }
178
4f4a327e 179 _GLIBCXX_DEBUG_ASSERT(p_ncp->m_type == i_node);
180 node_pointer a_p_children[inode::arr_size];
36fed23c 181 size_type child_i = 0;
4f4a327e 182 inode_const_pointer p_icp = static_cast<inode_const_pointer>(p_ncp);
36fed23c 183
4f4a327e 184 typename inode::const_iterator child_it = p_icp->begin();
36fed23c 185
4f4a327e 186 inode_pointer p_ret;
b1a09c64 187 __try
36fed23c 188 {
4f4a327e 189 while (child_it != p_icp->end())
abcd1339 190 {
191 a_p_children[child_i] = recursive_copy_node(*(child_it));
192 child_i++;
193 child_it++;
194 }
4f4a327e 195 p_ret = s_inode_allocator.allocate(1);
36fed23c 196 }
b1a09c64 197 __catch(...)
36fed23c 198 {
199 while (child_i-- > 0)
200 clear_imp(a_p_children[child_i]);
c4f08cc0 201 __throw_exception_again;
36fed23c 202 }
203
4f4a327e 204 new (p_ret) inode(p_icp->get_e_ind(), pref_begin(a_p_children[0]));
36fed23c 205
206 --child_i;
5a2b9207 207 _GLIBCXX_DEBUG_ASSERT(child_i >= 1);
36fed23c 208 do
2b31bec4 209 p_ret->add_child(a_p_children[child_i], pref_begin(a_p_children[child_i]),
210 pref_end(a_p_children[child_i]), this);
36fed23c 211 while (child_i-- > 0);
4f4a327e 212 apply_update(p_ret, (node_update*)this);
2b31bec4 213 return p_ret;
36fed23c 214}