27 #pragma warning (push)
28 #pragma warning (disable: 4512)
55 template <
class ElementType,
class TypeOfCriticalSectionToUse = DummyCriticalSection>
83 bool operator== (const
SortedSet<ElementType>& other) const noexcept
85 return data == other.data;
121 inline int size() const noexcept
143 inline ElementType
operator[] (
const int index)
const noexcept
158 return data.getUnchecked (index);
171 return data.getReference (index);
178 inline const ElementType&
getReference (
const int index)
const noexcept
180 return data.getReference (index);
188 return data.getFirst();
196 return data.getLast();
203 inline const ElementType*
begin() const noexcept
211 inline const ElementType*
end() const noexcept
225 int indexOf (
const ElementType& elementToLookFor)
const noexcept
237 if (elementToLookFor == data.getReference (s))
240 auto halfway = (s + e) / 2;
245 if (elementToLookFor < data.getReference (halfway))
257 bool contains (
const ElementType& elementToLookFor)
const noexcept
259 return indexOf (elementToLookFor) >= 0;
274 bool add (
const ElementType& newElement) noexcept
283 auto& elem = data.getReference (s);
285 if (newElement == elem)
291 auto halfway = (s + e) / 2;
292 bool isBeforeHalfway = (newElement < data.getReference (halfway));
296 if (! isBeforeHalfway)
308 data.insert (s, newElement);
319 int numElementsToAdd) noexcept
323 while (--numElementsToAdd >= 0)
324 add (*elementsToAdd++);
336 template <
class OtherSetType>
337 void addSet (
const OtherSetType& setToAddFrom,
339 int numElementsToAdd = -1) noexcept
341 const typename OtherSetType::ScopedLockType lock1 (setToAddFrom.getLock());
343 jassert (
this != &setToAddFrom);
345 if (
this != &setToAddFrom)
353 if (numElementsToAdd < 0 || startIndex + numElementsToAdd > setToAddFrom.size())
354 numElementsToAdd = setToAddFrom.size() - startIndex;
356 if (numElementsToAdd > 0)
357 addArray (&setToAddFrom.data.getReference (startIndex), numElementsToAdd);
371 ElementType
remove (
const int indexToRemove) noexcept
373 return data.removeAndReturn (indexToRemove);
386 data.remove (
indexOf (valueToRemove));
394 template <
class OtherSetType>
397 const typename OtherSetType::ScopedLockType lock1 (otherSet.getLock());
400 if (
this == &otherSet)
404 else if (! otherSet.isEmpty())
406 for (
int i = data.size(); --i >= 0;)
407 if (otherSet.contains (data.getReference (i)))
419 template <
class OtherSetType>
422 const typename OtherSetType::ScopedLockType lock1 (otherSet.getLock());
425 if (
this != &otherSet)
427 if (otherSet.isEmpty())
433 for (
int i = data.size(); --i >= 0;)
434 if (! otherSet.contains (data.getReference (i)))
445 template <
class OtherSetType>
448 data.swapWith (otherSet.data);
460 data.minimiseStorageOverheads();
471 data.ensureStorageAllocated (minNumElements);
479 inline const TypeOfCriticalSectionToUse&
getLock() const noexcept {
return data.getLock(); }
491 #pragma warning (pop)
int size() const noexcept
ElementType remove(const int indexToRemove) noexcept
bool isEmpty() const noexcept
int indexOf(const ElementType &elementToLookFor) const noexcept
ElementType operator[](const int index) const noexcept
void removeValue(const ElementType valueToRemove) noexcept
void addSet(const OtherSetType &setToAddFrom, int startIndex=0, int numElementsToAdd=-1) noexcept
void addArray(const ElementType *elementsToAdd, int numElementsToAdd) noexcept
ElementType getFirst() const noexcept
void removeValuesIn(const OtherSetType &otherSet) noexcept
bool add(const ElementType &newElement) noexcept
void clearQuick() noexcept
ElementType getUnchecked(const int index) const noexcept
const TypeOfCriticalSectionToUse & getLock() const noexcept
SortedSet(SortedSet &&) noexcept=default
SortedSet(const SortedSet &)=default
bool operator!=(const SortedSet< ElementType > &other) const noexcept
const ElementType * begin() const noexcept
void swapWith(OtherSetType &otherSet) noexcept
void minimiseStorageOverheads() noexcept
ElementType & getReference(const int index) noexcept
ElementType getLast() const noexcept
const ElementType * end() const noexcept
void ensureStorageAllocated(const int minNumElements)
bool operator==(const SortedSet< ElementType > &other) const noexcept
bool contains(const ElementType &elementToLookFor) const noexcept
const ElementType & getReference(const int index) const noexcept
void removeValuesNotIn(const OtherSetType &otherSet) noexcept
typename TypeOfCriticalSectionToUse::ScopedLockType ScopedLockType