]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/libstdc++/include/ext/pb_ds/detail/cc_hash_table_map_/constructor_destructor_fn_imps.hpp
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / libstdc++ / include / ext / pb_ds / detail / cc_hash_table_map_ / constructor_destructor_fn_imps.hpp
1 // -*- C++ -*-
2
3 // Copyright (C) 2005, 2006 Free Software Foundation, Inc.
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
8 // Foundation; either version 2, or (at your option) any later
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
16 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING.  If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19 // MA 02111-1307, USA.
20
21 // As a special exception, you may use this file as part of a free
22 // software library without restriction.  Specifically, if other files
23 // instantiate templates or use macros or inline functions from this
24 // file, or you compile this file and link it with other files to
25 // produce an executable, this file does not by itself cause the
26 // resulting executable to be covered by the GNU General Public
27 // License.  This exception does not however invalidate any other
28 // reasons why the executable file might be covered by the GNU General
29 // Public License.
30
31 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
32
33 // Permission to use, copy, modify, sell, and distribute this software
34 // is hereby granted without fee, provided that the above copyright
35 // notice appears in all copies, and that both that copyright notice
36 // and this permission notice appear in supporting documentation. None
37 // of the above authors, nor IBM Haifa Research Laboratories, make any
38 // representation about the suitability of this software for any
39 // purpose. It is provided "as is" without express or implied
40 // warranty.
41
42 /**
43  * @file constructor_destructor_fn_imps.hpp
44  * Contains implementations of cc_ht_map_'s constructors, destructor,
45  *    and related functions.
46  */
47
48 PB_DS_CLASS_T_DEC
49 typename PB_DS_CLASS_C_DEC::entry_allocator
50 PB_DS_CLASS_C_DEC::s_entry_allocator;
51
52 PB_DS_CLASS_T_DEC
53 typename PB_DS_CLASS_C_DEC::entry_pointer_allocator
54 PB_DS_CLASS_C_DEC::s_entry_pointer_allocator;
55
56 PB_DS_CLASS_T_DEC
57 template<typename It>
58 void
59 PB_DS_CLASS_C_DEC::
60 copy_from_range(It first_it, It last_it)
61 {
62   while (first_it != last_it)
63     insert(*(first_it++));
64 }
65
66 PB_DS_CLASS_T_DEC
67 PB_DS_CLASS_C_DEC::
68 PB_DS_CLASS_NAME() :
69   ranged_hash_fn_base(resize_base::get_nearest_larger_size(1)),
70   m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0),
71   m_entries(s_entry_pointer_allocator.allocate(m_num_e))
72 {
73   initialize();
74   _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
75 }
76
77 PB_DS_CLASS_T_DEC
78 PB_DS_CLASS_C_DEC::
79 PB_DS_CLASS_NAME(const Hash_Fn& r_hash_fn) :
80   ranged_hash_fn_base(resize_base::get_nearest_larger_size(1), r_hash_fn),
81   m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0),
82   m_entries(s_entry_pointer_allocator.allocate(m_num_e))
83 {
84   initialize();
85   _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
86 }
87
88 PB_DS_CLASS_T_DEC
89 PB_DS_CLASS_C_DEC::
90 PB_DS_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn) :
91   PB_DS_HASH_EQ_FN_C_DEC(r_eq_fn),
92   ranged_hash_fn_base(resize_base::get_nearest_larger_size(1), r_hash_fn),
93   m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0),
94   m_entries(s_entry_pointer_allocator.allocate(m_num_e))
95 {
96   std::fill(m_entries, m_entries + m_num_e, (entry_pointer)NULL);
97   Resize_Policy::notify_cleared();
98   ranged_hash_fn_base::notify_resized(m_num_e);
99   _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
100 }
101
102 PB_DS_CLASS_T_DEC
103 PB_DS_CLASS_C_DEC::
104 PB_DS_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, const Comb_Hash_Fn& r_comb_hash_fn) :
105   PB_DS_HASH_EQ_FN_C_DEC(r_eq_fn),
106   ranged_hash_fn_base(resize_base::get_nearest_larger_size(1),
107                       r_hash_fn, r_comb_hash_fn),
108   m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0),
109   m_entries(s_entry_pointer_allocator.allocate(m_num_e))
110 {
111   initialize();
112   _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
113 }
114
115 PB_DS_CLASS_T_DEC
116 PB_DS_CLASS_C_DEC::
117 PB_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) :
118   PB_DS_HASH_EQ_FN_C_DEC(r_eq_fn),
119   Resize_Policy(r_resize_policy),
120   ranged_hash_fn_base(resize_base::get_nearest_larger_size(1),
121                       r_hash_fn, r_comb_hash_fn),
122   m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0),
123   m_entries(s_entry_pointer_allocator.allocate(m_num_e))
124 {
125   initialize();
126   _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
127 }
128
129 PB_DS_CLASS_T_DEC
130 PB_DS_CLASS_C_DEC::
131 PB_DS_CLASS_NAME(const PB_DS_CLASS_C_DEC& other) :
132 #ifdef _GLIBCXX_DEBUG
133   map_debug_base(other),
134 #endif 
135   PB_DS_HASH_EQ_FN_C_DEC(other),
136   resize_base(other), ranged_hash_fn_base(other),
137   m_num_e(resize_base::get_nearest_larger_size(1)), m_num_used_e(0),
138   m_entries(m_entries = s_entry_pointer_allocator.allocate(m_num_e))
139 {
140   initialize();
141   _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
142     try
143       {
144         copy_from_range(other.begin(), other.end());
145       }
146     catch(...)
147       {
148         deallocate_all();
149         __throw_exception_again;
150       }
151   _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
152 }
153
154 PB_DS_CLASS_T_DEC
155 PB_DS_CLASS_C_DEC::
156 ~PB_DS_CLASS_NAME()
157 { deallocate_all(); }
158
159 PB_DS_CLASS_T_DEC
160 void
161 PB_DS_CLASS_C_DEC::
162 swap(PB_DS_CLASS_C_DEC& other)
163 {
164   _GLIBCXX_DEBUG_ONLY(assert_valid());
165   _GLIBCXX_DEBUG_ONLY(other.assert_valid());
166
167   std::swap(m_entries, other.m_entries);
168   std::swap(m_num_e, other.m_num_e);
169   std::swap(m_num_used_e, other.m_num_used_e);
170   ranged_hash_fn_base::swap(other);
171   hash_eq_fn_base::swap(other);
172   resize_base::swap(other);
173
174   _GLIBCXX_DEBUG_ONLY(map_debug_base::swap(other));
175   _GLIBCXX_DEBUG_ONLY(assert_valid());
176   _GLIBCXX_DEBUG_ONLY(other.assert_valid());
177 }
178
179 PB_DS_CLASS_T_DEC
180 void
181 PB_DS_CLASS_C_DEC::
182 deallocate_all()
183 {
184   clear();
185   s_entry_pointer_allocator.deallocate(m_entries, m_num_e);
186 }
187
188 PB_DS_CLASS_T_DEC
189 void
190 PB_DS_CLASS_C_DEC::
191 initialize()
192 {
193   std::fill(m_entries, m_entries + m_num_e, entry_pointer(NULL));
194   Resize_Policy::notify_resized(m_num_e);
195   Resize_Policy::notify_cleared();
196   ranged_hash_fn_base::notify_resized(m_num_e);
197 }