]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/ext/pb_ds/detail/cc_hash_table_map_/constructor_destructor_fn_imps.hpp
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / include / ext / pb_ds / detail / cc_hash_table_map_ / constructor_destructor_fn_imps.hpp
CommitLineData
4569a895
AT
1// -*- C++ -*-
2
99dee823 3// Copyright (C) 2005-2021 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 37 * @file cc_hash_table_map_/constructor_destructor_fn_imps.hpp
4569a895 38 * Contains implementations of cc_ht_map_'s constructors, destructor,
a345e45d 39 * and related functions.
4569a895
AT
40 */
41
574dfb67
JW
42#ifdef PB_DS_CLASS_C_DEC
43
4569a895
AT
44PB_DS_CLASS_T_DEC
45typename PB_DS_CLASS_C_DEC::entry_allocator
46PB_DS_CLASS_C_DEC::s_entry_allocator;
47
48PB_DS_CLASS_T_DEC
49typename PB_DS_CLASS_C_DEC::entry_pointer_allocator
50PB_DS_CLASS_C_DEC::s_entry_pointer_allocator;
51
52PB_DS_CLASS_T_DEC
53template<typename It>
54void
55PB_DS_CLASS_C_DEC::
56copy_from_range(It first_it, It last_it)
57{
58 while (first_it != last_it)
59 insert(*(first_it++));
60}
61
62PB_DS_CLASS_T_DEC
63PB_DS_CLASS_C_DEC::
a345e45d 64PB_DS_CC_HASH_NAME() :
4569a895 65 ranged_hash_fn_base(resize_base::get_nearest_larger_size(1)),
3441f106
BK
66 m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0),
67 m_entries(s_entry_pointer_allocator.allocate(m_num_e))
4569a895
AT
68{
69 initialize();
f5886803 70 PB_DS_ASSERT_VALID((*this))
47bea7b8 71}
4569a895
AT
72
73PB_DS_CLASS_T_DEC
74PB_DS_CLASS_C_DEC::
a345e45d 75PB_DS_CC_HASH_NAME(const Hash_Fn& r_hash_fn) :
47bea7b8 76 ranged_hash_fn_base(resize_base::get_nearest_larger_size(1), r_hash_fn),
3441f106
BK
77 m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0),
78 m_entries(s_entry_pointer_allocator.allocate(m_num_e))
4569a895
AT
79{
80 initialize();
f5886803 81 PB_DS_ASSERT_VALID((*this))
47bea7b8 82}
4569a895
AT
83
84PB_DS_CLASS_T_DEC
85PB_DS_CLASS_C_DEC::
a345e45d 86PB_DS_CC_HASH_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn) :
4569a895 87 PB_DS_HASH_EQ_FN_C_DEC(r_eq_fn),
47bea7b8 88 ranged_hash_fn_base(resize_base::get_nearest_larger_size(1), r_hash_fn),
3441f106
BK
89 m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0),
90 m_entries(s_entry_pointer_allocator.allocate(m_num_e))
4569a895 91{
8fc81078 92 std::fill(m_entries, m_entries + m_num_e, (entry_pointer)0);
4569a895 93 Resize_Policy::notify_cleared();
3441f106 94 ranged_hash_fn_base::notify_resized(m_num_e);
f5886803 95 PB_DS_ASSERT_VALID((*this))
47bea7b8 96}
4569a895
AT
97
98PB_DS_CLASS_T_DEC
99PB_DS_CLASS_C_DEC::
a345e45d
BK
100PB_DS_CC_HASH_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn,
101 const Comb_Hash_Fn& r_comb_hash_fn) :
4569a895 102 PB_DS_HASH_EQ_FN_C_DEC(r_eq_fn),
47bea7b8 103 ranged_hash_fn_base(resize_base::get_nearest_larger_size(1),
3441f106
BK
104 r_hash_fn, r_comb_hash_fn),
105 m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0),
106 m_entries(s_entry_pointer_allocator.allocate(m_num_e))
4569a895
AT
107{
108 initialize();
f5886803 109 PB_DS_ASSERT_VALID((*this))
47bea7b8 110}
4569a895
AT
111
112PB_DS_CLASS_T_DEC
113PB_DS_CLASS_C_DEC::
a345e45d
BK
114PB_DS_CC_HASH_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn,
115 const Comb_Hash_Fn& r_comb_hash_fn,
116 const Resize_Policy& r_resize_policy) :
4569a895
AT
117 PB_DS_HASH_EQ_FN_C_DEC(r_eq_fn),
118 Resize_Policy(r_resize_policy),
47bea7b8 119 ranged_hash_fn_base(resize_base::get_nearest_larger_size(1),
3441f106
BK
120 r_hash_fn, r_comb_hash_fn),
121 m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0),
122 m_entries(s_entry_pointer_allocator.allocate(m_num_e))
4569a895
AT
123{
124 initialize();
f5886803 125 PB_DS_ASSERT_VALID((*this))
47bea7b8 126}
4569a895
AT
127
128PB_DS_CLASS_T_DEC
129PB_DS_CLASS_C_DEC::
a345e45d 130PB_DS_CC_HASH_NAME(const PB_DS_CLASS_C_DEC& other) :
4569a895 131 PB_DS_HASH_EQ_FN_C_DEC(other),
3441f106
BK
132 resize_base(other), ranged_hash_fn_base(other),
133 m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0),
790ad3b5 134 m_entries(s_entry_pointer_allocator.allocate(m_num_e))
4569a895
AT
135{
136 initialize();
f5886803 137 PB_DS_ASSERT_VALID((*this))
bc2631e0 138 __try
4569a895 139 {
a345e45d 140 copy_from_range(other.begin(), other.end());
4569a895 141 }
bc2631e0 142 __catch(...)
4569a895 143 {
a345e45d
BK
144 deallocate_all();
145 __throw_exception_again;
4569a895 146 }
f5886803 147 PB_DS_ASSERT_VALID((*this))
47bea7b8 148}
4569a895
AT
149
150PB_DS_CLASS_T_DEC
151PB_DS_CLASS_C_DEC::
a345e45d 152~PB_DS_CC_HASH_NAME()
47bea7b8 153{ deallocate_all(); }
4569a895
AT
154
155PB_DS_CLASS_T_DEC
156void
157PB_DS_CLASS_C_DEC::
158swap(PB_DS_CLASS_C_DEC& other)
159{
f5886803
FD
160 PB_DS_ASSERT_VALID((*this))
161 PB_DS_ASSERT_VALID(other)
4569a895 162
3441f106
BK
163 std::swap(m_entries, other.m_entries);
164 std::swap(m_num_e, other.m_num_e);
4569a895 165 std::swap(m_num_used_e, other.m_num_used_e);
4569a895 166 ranged_hash_fn_base::swap(other);
4569a895 167 hash_eq_fn_base::swap(other);
4569a895
AT
168 resize_base::swap(other);
169
551fe1a2 170 _GLIBCXX_DEBUG_ONLY(debug_base::swap(other));
f5886803
FD
171 PB_DS_ASSERT_VALID((*this))
172 PB_DS_ASSERT_VALID(other)
4569a895
AT
173}
174
175PB_DS_CLASS_T_DEC
176void
177PB_DS_CLASS_C_DEC::
178deallocate_all()
179{
180 clear();
3441f106 181 s_entry_pointer_allocator.deallocate(m_entries, m_num_e);
4569a895
AT
182}
183
184PB_DS_CLASS_T_DEC
185void
186PB_DS_CLASS_C_DEC::
187initialize()
188{
8fc81078 189 std::fill(m_entries, m_entries + m_num_e, entry_pointer(0));
3441f106 190 Resize_Policy::notify_resized(m_num_e);
4569a895 191 Resize_Policy::notify_cleared();
3441f106 192 ranged_hash_fn_base::notify_resized(m_num_e);
4569a895 193}
574dfb67 194#endif