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