libstdc++: erase_fn_imps.hpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41#ifdef PB_DS_CLASS_C_DEC
42
43PB_DS_CLASS_T_DEC
44void
45PB_DS_CLASS_C_DEC::
46clear()
47{
48 for (size_type i = 0; i < m_size; ++i)
49 erase_at(m_a_entries, i, s_no_throw_copies_ind);
50
51 __try
52 {
53 const size_type new_size = resize_policy::get_new_size_for_arbitrary(0);
54 entry_pointer new_entries = s_entry_allocator.allocate(new_size);
55 resize_policy::notify_arbitrary(new_size);
56 s_entry_allocator.deallocate(m_a_entries, m_actual_size);
57 m_actual_size = new_size;
58 m_a_entries = new_entries;
59 }
60 __catch(...)
61 { }
62
63 m_size = 0;
64 PB_DS_ASSERT_VALID((*this))
65}
66
67PB_DS_CLASS_T_DEC
68void
69PB_DS_CLASS_C_DEC::
70erase_at(entry_pointer a_entries, size_type i, false_type)
71{
72 a_entries[i]->~value_type();
73 s_value_allocator.deallocate(a_entries[i], 1);
74}
75
76PB_DS_CLASS_T_DEC
77void
78PB_DS_CLASS_C_DEC::
79erase_at(entry_pointer, size_type, true_type)
80{ }
81
82PB_DS_CLASS_T_DEC
83inline void
84PB_DS_CLASS_C_DEC::
85pop()
86{
87 PB_DS_ASSERT_VALID((*this))
88 _GLIBCXX_DEBUG_ASSERT(!empty());
89
90 pop_heap();
91 erase_at(m_a_entries, m_size - 1, s_no_throw_copies_ind);
92 resize_for_erase_if_needed();
93 _GLIBCXX_DEBUG_ASSERT(m_size > 0);
94 --m_size;
95
96 PB_DS_ASSERT_VALID((*this))
97}
98
99PB_DS_CLASS_T_DEC
100template
101typename PB_DS_CLASS_C_DEC::size_type
102PB_DS_CLASS_C_DEC::
103erase_if(Pred pred)
104{
105 PB_DS_ASSERT_VALID((*this))
106
107 typedef typename entry_pred<value_type, Pred, _Alloc, simple_value>::type
108 pred_t;
109
110 const size_type left = partition(pred_t(pred));
111 _GLIBCXX_DEBUG_ASSERT(m_size >= left);
112 const size_type ersd = m_size - left;
113 for (size_type i = left; i < m_size; ++i)
114 erase_at(m_a_entries, i, s_no_throw_copies_ind);
115
116 __try
117 {
118 const size_type new_size =
119 resize_policy::get_new_size_for_arbitrary(left);
120
121 entry_pointer new_entries = s_entry_allocator.allocate(new_size);
122 std::copy(m_a_entries, m_a_entries + left, new_entries);
123 s_entry_allocator.deallocate(m_a_entries, m_actual_size);
124 m_actual_size = new_size;
125 resize_policy::notify_arbitrary(m_actual_size);
126 }
127 __catch(...)
128 { };
129
130 m_size = left;
131 make_heap();
132 PB_DS_ASSERT_VALID((*this))
133 return ersd;
134}
135
136PB_DS_CLASS_T_DEC
137inline void
138PB_DS_CLASS_C_DEC::
139erase(point_iterator it)
140{
141 PB_DS_ASSERT_VALID((*this))
142 _GLIBCXX_DEBUG_ASSERT(!empty());
143
144 const size_type fix_pos = it.m_p_e - m_a_entries;
145 std::swap(*it.m_p_e, m_a_entries[m_size - 1]);
146 erase_at(m_a_entries, m_size - 1, s_no_throw_copies_ind);
147 resize_for_erase_if_needed();
148
149 _GLIBCXX_DEBUG_ASSERT(m_size > 0);
150 --m_size;
151 _GLIBCXX_DEBUG_ASSERT(fix_pos <= m_size);
152
153 if (fix_pos != m_size)
154 fix(m_a_entries + fix_pos);
155
156 PB_DS_ASSERT_VALID((*this))
157}
158
159PB_DS_CLASS_T_DEC
160inline void
161PB_DS_CLASS_C_DEC::
162resize_for_erase_if_needed()
163{
164 if (!resize_policy::resize_needed_for_shrink(m_size))
165 return;
166
167 __try
168 {
169 const size_type new_size = resize_policy::get_new_size_for_shrink();
170 entry_pointer new_entries = s_entry_allocator.allocate(new_size);
171 resize_policy::notify_shrink_resize();
172
173 _GLIBCXX_DEBUG_ASSERT(m_size > 0);
174 std::copy(m_a_entries, m_a_entries + m_size - 1, new_entries);
175 s_entry_allocator.deallocate(m_a_entries, m_actual_size);
176 m_actual_size = new_size;
177 m_a_entries = new_entries;
178 }
179 __catch(...)
180 { }
181}
182
183PB_DS_CLASS_T_DEC
184template
185typename PB_DS_CLASS_C_DEC::size_type
186PB_DS_CLASS_C_DEC::
187partition(Pred pred)
188{
189 size_type left = 0;
190 size_type right = m_size - 1;
191
192 while (right + 1 != left)
193 {
194 _GLIBCXX_DEBUG_ASSERT(left <= m_size);
195
196 if (!pred(m_a_entries[left]))
198 else if (pred(m_a_entries[right]))
200 else
201 {
202 _GLIBCXX_DEBUG_ASSERT(left < right);
203 std::swap(m_a_entries[left], m_a_entries[right]);
206 }
207 }
208
210}
211#endif
ISO C++ entities toplevel namespace is std.
ios_base & left(ios_base &__base)
Calls base.setf(ios_base::left, ios_base::adjustfield).
ios_base & right(ios_base &__base)
Calls base.setf(ios_base::right, ios_base::adjustfield).