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 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 | 200 |
201 template<typename T, class P> | 201 template<typename T, class P> |
202 void List<T, P>::Initialize(int capacity) { | 202 void List<T, P>::Initialize(int capacity) { |
203 ASSERT(capacity >= 0); | 203 ASSERT(capacity >= 0); |
204 data_ = (capacity > 0) ? NewData(capacity) : NULL; | 204 data_ = (capacity > 0) ? NewData(capacity) : NULL; |
205 capacity_ = capacity; | 205 capacity_ = capacity; |
206 length_ = 0; | 206 length_ = 0; |
207 } | 207 } |
208 | 208 |
209 | 209 |
| 210 template <typename T> |
| 211 int SortedListBSearch( |
| 212 const List<T>& list, T elem, int (*cmp)(const T* x, const T* y)) { |
| 213 int low = 0; |
| 214 int high = list.length() - 1; |
| 215 while (low <= high) { |
| 216 int mid = (low + high) / 2; |
| 217 T mid_elem = list[mid]; |
| 218 |
| 219 if (mid_elem > elem) { |
| 220 high = mid - 1; |
| 221 continue; |
| 222 } |
| 223 if (mid_elem < elem) { |
| 224 low = mid + 1; |
| 225 continue; |
| 226 } |
| 227 // Found the elememt. |
| 228 return mid; |
| 229 } |
| 230 return -1; |
| 231 } |
| 232 |
| 233 |
| 234 template <typename T> |
| 235 int SortedListBSearch(const List<T>& list, T elem) { |
| 236 return SortedListBSearch<T>(list, elem, PointerValueCompare<T>); |
| 237 } |
| 238 |
210 } } // namespace v8::internal | 239 } } // namespace v8::internal |
211 | 240 |
212 #endif // V8_LIST_INL_H_ | 241 #endif // V8_LIST_INL_H_ |
OLD | NEW |