3 // Copyright (C) 2005, 2006 Free Software Foundation, Inc.
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
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
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
43 * @file constructor_destructor_fn_imps.hpp
44 * Contains implementations of cc_ht_map_'s constructors, destructor,
45 * and related functions.
49 typename
PB_DS_CLASS_C_DEC::entry_allocator
50 PB_DS_CLASS_C_DEC::s_entry_allocator
;
53 typename
PB_DS_CLASS_C_DEC::entry_pointer_allocator
54 PB_DS_CLASS_C_DEC::s_entry_pointer_allocator
;
60 copy_from_range(It first_it
, It last_it
)
62 while (first_it
!= last_it
)
63 insert(*(first_it
++));
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
))
74 _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
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
))
85 _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
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();)
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
))
112 _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
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
))
126 _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
131 PB_DS_CLASS_NAME(const PB_DS_CLASS_C_DEC
& other
) :
132 #ifdef _GLIBCXX_DEBUG
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
))
141 _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
144 copy_from_range(other
.begin(), other
.end());
149 __throw_exception_again
;
151 _GLIBCXX_DEBUG_ONLY(PB_DS_CLASS_C_DEC::assert_valid();)
157 { deallocate_all(); }
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());
185 s_entry_pointer_allocator
.deallocate(m_entries
, m_num_e
);
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
);