OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_LIST_INL_H_ | 5 #ifndef V8_LIST_INL_H_ |
6 #define V8_LIST_INL_H_ | 6 #define V8_LIST_INL_H_ |
7 | 7 |
8 #include "src/list.h" | 8 #include "src/list.h" |
9 | 9 |
10 #include "src/base/macros.h" | 10 #include "src/base/macros.h" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 int result = 0; | 188 int result = 0; |
189 for (int i = start; i <= end; i++) { | 189 for (int i = start; i <= end; i++) { |
190 if (data_[i] == elm) ++result; | 190 if (data_[i] == elm) ++result; |
191 } | 191 } |
192 return result; | 192 return result; |
193 } | 193 } |
194 | 194 |
195 | 195 |
196 template<typename T, class P> | 196 template<typename T, class P> |
197 void List<T, P>::Sort(int (*cmp)(const T* x, const T* y)) { | 197 void List<T, P>::Sort(int (*cmp)(const T* x, const T* y)) { |
198 Sort(cmp, 0, length_); | 198 ToVector().Sort(cmp); |
199 } | |
200 | |
201 | |
202 template <typename T, class P> | |
203 void List<T, P>::Sort(int (*cmp)(const T* x, const T* y), size_t s, size_t l) { | |
204 ToVector().Sort(cmp, s, l); | |
205 #ifdef DEBUG | 199 #ifdef DEBUG |
206 for (size_t i = s + 1; i < l; i++) DCHECK(cmp(&data_[i - 1], &data_[i]) <= 0); | 200 for (int i = 1; i < length_; i++) |
| 201 DCHECK(cmp(&data_[i - 1], &data_[i]) <= 0); |
207 #endif | 202 #endif |
208 } | 203 } |
209 | 204 |
210 | 205 |
211 template<typename T, class P> | 206 template<typename T, class P> |
212 void List<T, P>::Sort() { | 207 void List<T, P>::Sort() { |
213 ToVector().Sort(); | 208 ToVector().Sort(); |
214 } | 209 } |
215 | 210 |
216 | 211 |
217 template <typename T, class P> | 212 template<typename T, class P> |
218 void List<T, P>::StableSort(int (*cmp)(const T* x, const T* y)) { | |
219 StableSort(cmp, 0, length_); | |
220 } | |
221 | |
222 | |
223 template <typename T, class P> | |
224 void List<T, P>::StableSort(int (*cmp)(const T* x, const T* y), size_t s, | |
225 size_t l) { | |
226 ToVector().StableSort(cmp, s, l); | |
227 #ifdef DEBUG | |
228 for (size_t i = s + 1; i < l; i++) DCHECK(cmp(&data_[i - 1], &data_[i]) <= 0); | |
229 #endif | |
230 } | |
231 | |
232 | |
233 template <typename T, class P> | |
234 void List<T, P>::StableSort() { | |
235 ToVector().StableSort(); | |
236 } | |
237 | |
238 | |
239 template <typename T, class P> | |
240 void List<T, P>::Initialize(int capacity, P allocator) { | 213 void List<T, P>::Initialize(int capacity, P allocator) { |
241 DCHECK(capacity >= 0); | 214 DCHECK(capacity >= 0); |
242 data_ = (capacity > 0) ? NewData(capacity, allocator) : NULL; | 215 data_ = (capacity > 0) ? NewData(capacity, allocator) : NULL; |
243 capacity_ = capacity; | 216 capacity_ = capacity; |
244 length_ = 0; | 217 length_ = 0; |
245 } | 218 } |
246 | 219 |
247 | 220 |
248 template <typename T, typename P> | 221 template <typename T, typename P> |
249 int SortedListBSearch(const List<T>& list, P cmp) { | 222 int SortedListBSearch(const List<T>& list, P cmp) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 | 255 |
283 template <typename T> | 256 template <typename T> |
284 int SortedListBSearch(const List<T>& list, T elem) { | 257 int SortedListBSearch(const List<T>& list, T elem) { |
285 return SortedListBSearch<T, ElementCmp<T> > (list, ElementCmp<T>(elem)); | 258 return SortedListBSearch<T, ElementCmp<T> > (list, ElementCmp<T>(elem)); |
286 } | 259 } |
287 | 260 |
288 | 261 |
289 } } // namespace v8::internal | 262 } } // namespace v8::internal |
290 | 263 |
291 #endif // V8_LIST_INL_H_ | 264 #endif // V8_LIST_INL_H_ |
OLD | NEW |