31 #pragma warning (push) 32 #pragma warning (disable: 4512) 59 template <
class ElementType,
class TypeOfCriticalSectionToUse = DummyCriticalSection>
89 return data == other.
data;
125 inline int size() const noexcept
147 inline ElementType
operator[] (
const int index)
const noexcept
182 inline const ElementType&
getReference (
const int index)
const noexcept
207 inline const ElementType*
begin() const noexcept
215 inline const ElementType*
end() const noexcept
229 int indexOf (
const ElementType& elementToLookFor)
const noexcept
244 auto halfway = (s + e) / 2;
261 bool contains (
const ElementType& elementToLookFor)
const noexcept
263 return indexOf (elementToLookFor) >= 0;
278 bool add (
const ElementType& newElement) noexcept
289 if (newElement == elem)
295 auto halfway = (s + e) / 2;
296 bool isBeforeHalfway = (newElement < data.
getReference (halfway));
300 if (! isBeforeHalfway)
312 data.
insert (s, newElement);
323 int numElementsToAdd) noexcept
327 while (--numElementsToAdd >= 0)
328 add (*elementsToAdd++);
340 template <
class OtherSetType>
341 void addSet (
const OtherSetType& setToAddFrom,
343 int numElementsToAdd = -1) noexcept
345 const typename OtherSetType::ScopedLockType lock1 (setToAddFrom.getLock());
347 jassert (
this != &setToAddFrom);
349 if (
this != &setToAddFrom)
357 if (numElementsToAdd < 0 || startIndex + numElementsToAdd > setToAddFrom.size())
358 numElementsToAdd = setToAddFrom.size() - startIndex;
360 if (numElementsToAdd > 0)
361 addArray (&setToAddFrom.data.getReference (startIndex), numElementsToAdd);
375 ElementType
remove (
const int indexToRemove) noexcept
398 template <
class OtherSetType>
401 const typename OtherSetType::ScopedLockType lock1 (otherSet.getLock());
404 if (
this == &otherSet)
408 else if (! otherSet.isEmpty())
410 for (
int i = data.
size(); --i >= 0;)
423 template <
class OtherSetType>
426 const typename OtherSetType::ScopedLockType lock1 (otherSet.getLock());
429 if (
this != &otherSet)
431 if (otherSet.isEmpty())
437 for (
int i = data.
size(); --i >= 0;)
449 template <
class OtherSetType>
483 inline const TypeOfCriticalSectionToUse&
getLock() const noexcept {
return data.
getLock(); }
495 #pragma warning (pop) ElementType operator[](const int index) const noexcept
Returns one of the elements in the set.
int size() const noexcept
Returns the current number of elements in the set.
ElementType & getReference(const int index) noexcept
Returns a direct reference to one of the elements in the set, without checking the index passed in...
ElementType * end() noexcept
Returns a pointer to the element which follows the last element in the array.
void minimiseStorageOverheads()
Reduces the amount of storage being used by the array.
void swapWith(OtherArrayType &otherArray) noexcept
This swaps the contents of this array with those of another array.
void clearQuick()
Removes all elements from the array without freeing the array's allocated storage.
~SortedSet()=default
Destructor.
void ensureStorageAllocated(int minNumElements)
Increases the array's internal storage to hold a minimum number of elements.
bool add(const ElementType &newElement) noexcept
Adds a new element to the set, (as long as it's not already in there).
bool operator!=(const SortedSet< ElementType > &other) const noexcept
Compares this set to another one.
ElementType getLast() const noexcept
Returns the last element in the array, or a default value if the array is empty.
ElementType * data() noexcept
Returns a pointer to the first element in the array.
const TypeOfCriticalSectionToUse & getLock() const noexcept
Returns the CriticalSection that locks this array.
void removeValuesNotIn(const OtherSetType &otherSet) noexcept
Removes any elements which are not found in another set.
void addSet(const OtherSetType &setToAddFrom, int startIndex=0, int numElementsToAdd=-1) noexcept
Adds elements from another set to this one.
void removeValuesIn(const OtherSetType &otherSet) noexcept
Removes any elements which are also in another set.
void insert(int indexToInsertAt, ParameterType newElement)
Inserts a new element into the array at a given position.
ElementType getUnchecked(int index) const
Returns one of the elements in the array, without checking the index passed in.
bool contains(const ElementType &elementToLookFor) const noexcept
Returns true if the set contains at least one occurrence of an object.
const ElementType & getReference(const int index) const noexcept
Returns a direct reference to one of the elements in the set, without checking the index passed in...
ElementType * begin() noexcept
Returns a pointer to the first element in the array.
const ElementType * end() const noexcept
Returns a pointer to the element which follows the last element in the set.
void clearQuick() noexcept
Removes all elements from the set without freeing the array's allocated storage.
const ElementType * begin() const noexcept
Returns a pointer to the first element in the set.
SortedSet & operator=(const SortedSet &)=default
Makes a copy of another set.
void minimiseStorageOverheads() noexcept
Reduces the amount of storage being used by the set.
Holds a set of unique primitive objects, such as ints or doubles.
ElementType getUnchecked(const int index) const noexcept
Returns one of the elements in the set, without checking the index passed in.
void clear()
Removes all elements from the array.
int size() const noexcept
Returns the current number of elements in the array.
ElementType getFirst() const noexcept
Returns the first element in the set, or 0 if the set is empty.
void clear() noexcept
Removes all elements from the set.
ElementType removeAndReturn(int indexToRemove)
Removes an element from the array.
const TypeOfCriticalSectionToUse & getLock() const noexcept
Returns the CriticalSection that locks this array.
bool isEmpty() const noexcept
Returns true if the set is empty, false otherwise.
ElementType getFirst() const noexcept
Returns the first element in the array, or a default value if the array is empty. ...
void ensureStorageAllocated(const int minNumElements)
Increases the set's internal storage to hold a minimum number of elements.
ElementType & getReference(int index) noexcept
Returns a direct reference to one of the elements in the array, without checking the index passed in...
bool operator==(const SortedSet< ElementType > &other) const noexcept
Compares this set to another one.
void swapWith(OtherSetType &otherSet) noexcept
This swaps the contents of this array with those of another array.
void addArray(const ElementType *elementsToAdd, int numElementsToAdd) noexcept
Adds elements from an array to this set.
int indexOf(const ElementType &elementToLookFor) const noexcept
Finds the index of the first element which matches the value passed in.
void removeValue(const ElementType valueToRemove) noexcept
Removes an item from the set.
SortedSet()=default
Creates an empty set.
void remove(int indexToRemove)
Removes an element from the array.
typename DummyCriticalSection ::ScopedLockType ScopedLockType
Returns the type of scoped lock to use for locking this array.
ElementType getLast() const noexcept
Returns the last element in the set, or 0 if the set is empty.