| 6278 | */ |
| 6279 | template <class ElementType, class ElementComparator> |
| 6280 | static int findInsertIndexInSortedArray (ElementComparator& comparator, |
| 6281 | ElementType* const array, |
| 6282 | const ElementType newElement, |
| 6283 | int firstElement, |
| 6284 | int lastElement) |
| 6285 | { |
| 6286 | jassert (firstElement <= lastElement); |
| 6287 | |
| 6288 | (void) comparator; // if you pass in an object with a static compareElements() method, this |
| 6289 | // avoids getting warning messages about the parameter being unused |
| 6290 | |
| 6291 | while (firstElement < lastElement) |
| 6292 | { |
| 6293 | if (comparator.compareElements (newElement, array [firstElement]) == 0) |
| 6294 | { |
| 6295 | ++firstElement; |
| 6296 | break; |
| 6297 | } |
| 6298 | else |
| 6299 | { |
| 6300 | const int halfway = (firstElement + lastElement) >> 1; |
| 6301 | |
| 6302 | if (halfway == firstElement) |
| 6303 | { |
| 6304 | if (comparator.compareElements (newElement, array [halfway]) >= 0) |
| 6305 | ++firstElement; |
| 6306 | |
| 6307 | break; |
| 6308 | } |
| 6309 | else if (comparator.compareElements (newElement, array [halfway]) >= 0) |
| 6310 | { |
| 6311 | firstElement = halfway; |
| 6312 | } |
| 6313 | else |
| 6314 | { |
| 6315 | lastElement = halfway; |
| 6316 | } |
| 6317 | } |
| 6318 | } |
| 6319 | |
| 6320 | return firstElement; |
| 6321 | } |
| 6322 | |
| 6323 | /** |
| 6324 | A simple ElementComparator class that can be used to sort an array of |
no test coverage detected