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