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/platform/platform.h" | 10 #include "src/base/platform/platform.h" |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 capacity_ = capacity; | 213 capacity_ = capacity; |
214 length_ = 0; | 214 length_ = 0; |
215 } | 215 } |
216 | 216 |
217 | 217 |
218 template <typename T, typename P> | 218 template <typename T, typename P> |
219 int SortedListBSearch(const List<T>& list, P cmp) { | 219 int SortedListBSearch(const List<T>& list, P cmp) { |
220 int low = 0; | 220 int low = 0; |
221 int high = list.length() - 1; | 221 int high = list.length() - 1; |
222 while (low <= high) { | 222 while (low <= high) { |
223 int mid = low + (high - low) / 2; | 223 int mid = (low + high) / 2; |
224 T mid_elem = list[mid]; | 224 T mid_elem = list[mid]; |
225 | 225 |
226 if (cmp(&mid_elem) > 0) { | 226 if (cmp(&mid_elem) > 0) { |
227 high = mid - 1; | 227 high = mid - 1; |
228 continue; | 228 continue; |
229 } | 229 } |
230 if (cmp(&mid_elem) < 0) { | 230 if (cmp(&mid_elem) < 0) { |
231 low = mid + 1; | 231 low = mid + 1; |
232 continue; | 232 continue; |
233 } | 233 } |
(...skipping 18 matching lines...) Expand all Loading... |
252 | 252 |
253 template <typename T> | 253 template <typename T> |
254 int SortedListBSearch(const List<T>& list, T elem) { | 254 int SortedListBSearch(const List<T>& list, T elem) { |
255 return SortedListBSearch<T, ElementCmp<T> > (list, ElementCmp<T>(elem)); | 255 return SortedListBSearch<T, ElementCmp<T> > (list, ElementCmp<T>(elem)); |
256 } | 256 } |
257 | 257 |
258 | 258 |
259 } } // namespace v8::internal | 259 } } // namespace v8::internal |
260 | 260 |
261 #endif // V8_LIST_INL_H_ | 261 #endif // V8_LIST_INL_H_ |
OLD | NEW |