| 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 template<typename T, class P> | 186 template<typename T, class P> |
| 187 int List<T, P>::CountOccurrences(const T& elm, int start, int end) const { | 187 int List<T, P>::CountOccurrences(const T& elm, int start, int end) const { |
| 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 template <typename CompareFunction> |
| 198 void List<T, P>::Sort(CompareFunction cmp) { |
| 198 Sort(cmp, 0, length_); | 199 Sort(cmp, 0, length_); |
| 199 } | 200 } |
| 200 | 201 |
| 201 | 202 |
| 202 template <typename T, class P> | 203 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 template <typename CompareFunction> |
| 205 void List<T, P>::Sort(CompareFunction cmp, size_t s, size_t l) { |
| 204 ToVector().Sort(cmp, s, l); | 206 ToVector().Sort(cmp, s, l); |
| 205 #ifdef DEBUG | 207 #ifdef DEBUG |
| 206 for (size_t i = s + 1; i < l; i++) DCHECK(cmp(&data_[i - 1], &data_[i]) <= 0); | 208 for (size_t i = s + 1; i < l; i++) DCHECK(cmp(&data_[i - 1], &data_[i]) <= 0); |
| 207 #endif | 209 #endif |
| 208 } | 210 } |
| 209 | 211 |
| 210 | 212 |
| 211 template<typename T, class P> | 213 template<typename T, class P> |
| 212 void List<T, P>::Sort() { | 214 void List<T, P>::Sort() { |
| 213 ToVector().Sort(); | 215 ToVector().Sort(); |
| 214 } | 216 } |
| 215 | 217 |
| 216 | 218 |
| 217 template <typename T, class P> | 219 template <typename T, class P> |
| 218 void List<T, P>::StableSort(int (*cmp)(const T* x, const T* y)) { | 220 template <typename CompareFunction> |
| 221 void List<T, P>::StableSort(CompareFunction cmp) { |
| 219 StableSort(cmp, 0, length_); | 222 StableSort(cmp, 0, length_); |
| 220 } | 223 } |
| 221 | 224 |
| 222 | 225 |
| 223 template <typename T, class P> | 226 template <typename T, class P> |
| 224 void List<T, P>::StableSort(int (*cmp)(const T* x, const T* y), size_t s, | 227 template <typename CompareFunction> |
| 225 size_t l) { | 228 void List<T, P>::StableSort(CompareFunction cmp, size_t s, size_t l) { |
| 226 ToVector().StableSort(cmp, s, l); | 229 ToVector().StableSort(cmp, s, l); |
| 227 #ifdef DEBUG | 230 #ifdef DEBUG |
| 228 for (size_t i = s + 1; i < l; i++) DCHECK(cmp(&data_[i - 1], &data_[i]) <= 0); | 231 for (size_t i = s + 1; i < l; i++) DCHECK(cmp(&data_[i - 1], &data_[i]) <= 0); |
| 229 #endif | 232 #endif |
| 230 } | 233 } |
| 231 | 234 |
| 232 | 235 |
| 233 template <typename T, class P> | 236 template <typename T, class P> |
| 234 void List<T, P>::StableSort() { | 237 void List<T, P>::StableSort() { |
| 235 ToVector().StableSort(); | 238 ToVector().StableSort(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 | 285 |
| 283 template <typename T> | 286 template <typename T> |
| 284 int SortedListBSearch(const List<T>& list, T elem) { | 287 int SortedListBSearch(const List<T>& list, T elem) { |
| 285 return SortedListBSearch<T, ElementCmp<T> > (list, ElementCmp<T>(elem)); | 288 return SortedListBSearch<T, ElementCmp<T> > (list, ElementCmp<T>(elem)); |
| 286 } | 289 } |
| 287 | 290 |
| 288 | 291 |
| 289 } } // namespace v8::internal | 292 } } // namespace v8::internal |
| 290 | 293 |
| 291 #endif // V8_LIST_INL_H_ | 294 #endif // V8_LIST_INL_H_ |
| OLD | NEW |