26#ifndef WATER_SORTEDSET_H_INCLUDED
27#define WATER_SORTEDSET_H_INCLUDED
55template <
class ElementType>
94 return data == other.data;
152 inline ElementType
operator[] (
const int index)
const noexcept
167 return data.getUnchecked (index);
180 return data.getReference (index);
188 return data.getFirst();
196 return data.getLast();
225 int indexOf (
const ElementType& elementToLookFor)
const noexcept
235 if (elementToLookFor ==
data.getReference (
s))
238 const int halfway = (
s +
e) / 2;
243 if (elementToLookFor <
data.getReference (halfway))
255 bool contains (
const ElementType& elementToLookFor)
const noexcept
257 return indexOf (elementToLookFor) >= 0;
272 bool add (
const ElementType& newElement)
noexcept
279 ElementType& elem =
data.getReference (
s);
280 if (newElement == elem)
286 const int halfway = (
s +
e) / 2;
287 const bool isBeforeHalfway = (newElement <
data.getReference (halfway));
291 if (! isBeforeHalfway)
303 data.insert (
s, newElement);
314 int numElementsToAdd)
noexcept
316 while (--numElementsToAdd >= 0)
317 add (*elementsToAdd++);
329 template <
class OtherSetType>
330 void addSet (
const OtherSetType& setToAddFrom,
334 wassert (
this != &setToAddFrom);
336 if (
this != &setToAddFrom)
344 if (numElementsToAdd < 0 || startIndex + numElementsToAdd > setToAddFrom.size())
345 numElementsToAdd = setToAddFrom.size() - startIndex;
347 if (numElementsToAdd > 0)
348 addArray (&setToAddFrom.data.getReference (startIndex), numElementsToAdd);
362 ElementType
remove (
const int indexToRemove)
noexcept
364 return data.removeAndReturn (indexToRemove);
384 template <
class OtherSetType>
387 if (
this == &otherSet)
391 else if (otherSet.size() > 0)
393 for (
int i =
data.size(); --
i >= 0;)
394 if (otherSet.contains (
data.getReference (
i)))
406 template <
class OtherSetType>
409 if (
this != &otherSet)
411 if (otherSet.size() <= 0)
417 for (
int i =
data.size(); --
i >= 0;)
418 if (! otherSet.contains (
data.getReference (
i)))
429 template <
class OtherSetType>
432 data.swapWith (otherSet.data);
444 data.minimiseStorageOverheads();
455 data.ensureStorageAllocated (minNumElements);
#define noexcept
Definition DistrhoDefines.h:72
bool contains(const ElementType &elementToLookFor) const noexcept
Definition SortedSet.h:255
ElementType getUnchecked(const int index) const noexcept
Definition SortedSet.h:165
~SortedSet() noexcept
Definition SortedSet.h:74
void removeValuesIn(const OtherSetType &otherSet) noexcept
Definition SortedSet.h:385
void swapWith(OtherSetType &otherSet) noexcept
Definition SortedSet.h:430
void ensureStorageAllocated(const int minNumElements)
Definition SortedSet.h:453
ElementType remove(const int indexToRemove) noexcept
Definition SortedSet.h:362
ElementType * begin() const noexcept
Definition SortedSet.h:203
ElementType operator[](const int index) const noexcept
Definition SortedSet.h:152
void clear() noexcept
Definition SortedSet.h:115
ElementType getLast() const noexcept
Definition SortedSet.h:194
void clearQuick() noexcept
Definition SortedSet.h:123
void removeValue(const ElementType valueToRemove) noexcept
Definition SortedSet.h:374
ElementType * end() const noexcept
Definition SortedSet.h:211
bool operator==(const SortedSet< ElementType > &other) const noexcept
Definition SortedSet.h:92
SortedSet() noexcept
Definition SortedSet.h:61
bool operator!=(const SortedSet< ElementType > &other) const noexcept
Definition SortedSet.h:101
bool add(const ElementType &newElement) noexcept
Definition SortedSet.h:272
int size() const noexcept
Definition SortedSet.h:130
void minimiseStorageOverheads() noexcept
Definition SortedSet.h:442
SortedSet & operator=(const SortedSet &other) noexcept
Definition SortedSet.h:81
Array< ElementType > data
Definition SortedSet.h:461
int indexOf(const ElementType &elementToLookFor) const noexcept
Definition SortedSet.h:225
void removeValuesNotIn(const OtherSetType &otherSet) noexcept
Definition SortedSet.h:407
ElementType & getReference(const int index) const noexcept
Definition SortedSet.h:178
bool isEmpty() const noexcept
Definition SortedSet.h:136
ElementType getFirst() const noexcept
Definition SortedSet.h:186
void addSet(const OtherSetType &setToAddFrom, int startIndex=0, int numElementsToAdd=-1) noexcept
Definition SortedSet.h:330
SortedSet(const SortedSet &other)
Definition SortedSet.h:68
void addArray(const ElementType *elementsToAdd, int numElementsToAdd) noexcept
Definition SortedSet.h:313
* e
Definition inflate.c:1404
register unsigned i
Definition inflate.c:1575
unsigned s
Definition inflate.c:1555
#define wassert(expression)
Definition AudioSampleBuffer.h:33
#define const
Definition zconf.h:137