Install gcc-4.4.0-tdm-1-core-2.tar.gz
[msysgit.git] / mingw / lib / gcc / mingw32 / 4.3.3 / include / c++ / ext / pb_ds / detail / cc_hash_table_map_ / constructor_destructor_fn_imps.hpp
blobe767bbec51fb94b9ef543793c8cec85bb87e87f5
1 // -*- C++ -*-
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.
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.
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.
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.
31 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
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.
42 /**
43 * @file constructor_destructor_fn_imps.hpp
44 * Contains implementations of cc_ht_map_'s constructors, destructor,
45 * and related functions.
48 PB_DS_CLASS_T_DEC
49 typename PB_DS_CLASS_C_DEC::entry_allocator
50 PB_DS_CLASS_C_DEC::s_entry_allocator;
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;
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)
62 while (first_it != last_it)
63 insert(*(first_it++));
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))
73 initialize();
74 _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
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))
84 initialize();
85 _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
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))
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();)
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))
111 initialize();
112 _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
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))
125 initialize();
126 _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
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 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))
140 initialize();
141 _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
144 copy_from_range(other.begin(), other.end());
146 catch(...)
148 deallocate_all();
149 __throw_exception_again;
151 _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
154 PB_DS_CLASS_T_DEC
155 PB_DS_CLASS_C_DEC::
156 ~PB_DS_CLASS_NAME()
157 { deallocate_all(); }
159 PB_DS_CLASS_T_DEC
160 void
161 PB_DS_CLASS_C_DEC::
162 swap(PB_DS_CLASS_C_DEC& other)
164 _GLIBCXX_DEBUG_ONLY(assert_valid());
165 _GLIBCXX_DEBUG_ONLY(other.assert_valid());
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);
174 _GLIBCXX_DEBUG_ONLY(debug_base::swap(other));
175 _GLIBCXX_DEBUG_ONLY(assert_valid());
176 _GLIBCXX_DEBUG_ONLY(other.assert_valid());
179 PB_DS_CLASS_T_DEC
180 void
181 PB_DS_CLASS_C_DEC::
182 deallocate_all()
184 clear();
185 s_entry_pointer_allocator.deallocate(m_entries, m_num_e);
188 PB_DS_CLASS_T_DEC
189 void
190 PB_DS_CLASS_C_DEC::
191 initialize()
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);