34 template <
typename ElementComparator>
39 template <
typename Type>
40 bool operator() (Type a, Type b) {
return comparator.compareElements (a, b) < 0; }
43 ElementComparator& comparator;
78 template <
class ElementType,
class ElementComparator>
79 static void sortArray (ElementComparator& comparator,
80 ElementType*
const array,
83 const bool retainOrderOfEquivalentItems)
85 jassert (firstElement >= 0);
87 if (lastElement > firstElement)
91 if (retainOrderOfEquivalentItems)
92 std::stable_sort (array + firstElement, array + lastElement + 1, converter);
94 std::sort (array + firstElement, array + lastElement + 1, converter);
123 template <
class ElementType,
class ElementComparator>
124 static int findInsertIndexInSortedArray (ElementComparator& comparator,
125 ElementType*
const array,
126 const ElementType newElement,
130 jassert (firstElement <= lastElement);
132 ignoreUnused (comparator);
135 while (firstElement < lastElement)
137 if (comparator.compareElements (newElement, array [firstElement]) == 0)
144 const int halfway = (firstElement + lastElement) >> 1;
146 if (halfway == firstElement)
148 if (comparator.compareElements (newElement, array [halfway]) >= 0)
153 else if (comparator.compareElements (newElement, array [halfway]) >= 0)
155 firstElement = halfway;
159 lastElement = halfway;
184 template <
class ElementType>
188 using ParameterType =
typename TypeHelpers::ParameterType<ElementType>::type;
191 static int compareElements (ParameterType first, ParameterType second)
193 return (first < second) ? -1 : ((second < first) ? 1 : 0);