| 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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 | 209 |
| 210 template <typename T> | 210 template <typename T> |
| 211 int SortedListBSearch( | 211 int SortedListBSearch( |
| 212 const List<T>& list, T elem, int (*cmp)(const T* x, const T* y)) { | 212 const List<T>& list, T elem, int (*cmp)(const T* x, const T* y)) { |
| 213 int low = 0; | 213 int low = 0; |
| 214 int high = list.length() - 1; | 214 int high = list.length() - 1; |
| 215 while (low <= high) { | 215 while (low <= high) { |
| 216 int mid = (low + high) / 2; | 216 int mid = (low + high) / 2; |
| 217 T mid_elem = list[mid]; | 217 T mid_elem = list[mid]; |
| 218 | 218 |
| 219 if (mid_elem > elem) { | 219 if (cmp(&mid_elem, &elem) > 0) { |
| 220 high = mid - 1; | 220 high = mid - 1; |
| 221 continue; | 221 continue; |
| 222 } | 222 } |
| 223 if (mid_elem < elem) { | 223 if (cmp(&mid_elem, &elem) < 0) { |
| 224 low = mid + 1; | 224 low = mid + 1; |
| 225 continue; | 225 continue; |
| 226 } | 226 } |
| 227 // Found the elememt. | 227 // Found the elememt. |
| 228 return mid; | 228 return mid; |
| 229 } | 229 } |
| 230 return -1; | 230 return -1; |
| 231 } | 231 } |
| 232 | 232 |
| 233 | 233 |
| 234 template <typename T> | 234 template <typename T> |
| 235 int SortedListBSearch(const List<T>& list, T elem) { | 235 int SortedListBSearch(const List<T>& list, T elem) { |
| 236 return SortedListBSearch<T>(list, elem, PointerValueCompare<T>); | 236 return SortedListBSearch<T>(list, elem, PointerValueCompare<T>); |
| 237 } | 237 } |
| 238 | 238 |
| 239 } } // namespace v8::internal | 239 } } // namespace v8::internal |
| 240 | 240 |
| 241 #endif // V8_LIST_INL_H_ | 241 #endif // V8_LIST_INL_H_ |
| OLD | NEW |