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 ToVector().Sort(cmp); | 198 Sort(cmp, 0, length_); |
| 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); |
199 #ifdef DEBUG | 205 #ifdef DEBUG |
200 for (int i = 1; i < length_; i++) | 206 for (size_t i = s + 1; i < l; i++) DCHECK(cmp(&data_[i - 1], &data_[i]) <= 0); |
201 DCHECK(cmp(&data_[i - 1], &data_[i]) <= 0); | |
202 #endif | 207 #endif |
203 } | 208 } |
204 | 209 |
205 | 210 |
206 template<typename T, class P> | 211 template<typename T, class P> |
207 void List<T, P>::Sort() { | 212 void List<T, P>::Sort() { |
208 ToVector().Sort(); | 213 ToVector().Sort(); |
209 } | 214 } |
210 | 215 |
211 | 216 |
212 template<typename T, class P> | 217 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> |
213 void List<T, P>::Initialize(int capacity, P allocator) { | 240 void List<T, P>::Initialize(int capacity, P allocator) { |
214 DCHECK(capacity >= 0); | 241 DCHECK(capacity >= 0); |
215 data_ = (capacity > 0) ? NewData(capacity, allocator) : NULL; | 242 data_ = (capacity > 0) ? NewData(capacity, allocator) : NULL; |
216 capacity_ = capacity; | 243 capacity_ = capacity; |
217 length_ = 0; | 244 length_ = 0; |
218 } | 245 } |
219 | 246 |
220 | 247 |
221 template <typename T, typename P> | 248 template <typename T, typename P> |
222 int SortedListBSearch(const List<T>& list, P cmp) { | 249 int SortedListBSearch(const List<T>& list, P cmp) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 | 282 |
256 template <typename T> | 283 template <typename T> |
257 int SortedListBSearch(const List<T>& list, T elem) { | 284 int SortedListBSearch(const List<T>& list, T elem) { |
258 return SortedListBSearch<T, ElementCmp<T> > (list, ElementCmp<T>(elem)); | 285 return SortedListBSearch<T, ElementCmp<T> > (list, ElementCmp<T>(elem)); |
259 } | 286 } |
260 | 287 |
261 | 288 |
262 } } // namespace v8::internal | 289 } } // namespace v8::internal |
263 | 290 |
264 #endif // V8_LIST_INL_H_ | 291 #endif // V8_LIST_INL_H_ |
OLD | NEW |