OpenShot Library | libopenshot-audio
0.2.0
|
31 #pragma warning (push)
32 #pragma warning (disable: 4512)
59 template <
class ElementType,
class TypeOfCriticalSectionToUse = DummyCriticalSection>
92 return data == other.data;
128 inline int size() const noexcept
150 inline ElementType
operator[] (
const int index)
const noexcept
165 return data.getUnchecked (index);
178 return data.getReference (index);
186 return data.getFirst();
194 return data.getLast();
201 inline ElementType*
begin() const noexcept
209 inline ElementType*
end() const noexcept
223 int indexOf (
const ElementType& elementToLookFor)
const noexcept
235 if (elementToLookFor == data.getReference (s))
238 auto 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
281 auto& elem = data.getReference (s);
283 if (newElement == elem)
289 auto halfway = (s + e) / 2;
290 bool isBeforeHalfway = (newElement < data.getReference (halfway));
294 if (! isBeforeHalfway)
306 data.insert (s, newElement);
317 int numElementsToAdd) noexcept
321 while (--numElementsToAdd >= 0)
322 add (*elementsToAdd++);
334 template <
class OtherSetType>
335 void addSet (
const OtherSetType& setToAddFrom,
337 int numElementsToAdd = -1) noexcept
339 const typename OtherSetType::ScopedLockType lock1 (setToAddFrom.getLock());
341 jassert (
this != &setToAddFrom);
343 if (
this != &setToAddFrom)
351 if (numElementsToAdd < 0 || startIndex + numElementsToAdd > setToAddFrom.size())
352 numElementsToAdd = setToAddFrom.size() - startIndex;
354 if (numElementsToAdd > 0)
355 addArray (&setToAddFrom.data.getReference (startIndex), numElementsToAdd);
369 ElementType
remove (
const int indexToRemove) noexcept
371 return data.removeAndReturn (indexToRemove);
384 data.remove (
indexOf (valueToRemove));
392 template <
class OtherSetType>
395 const typename OtherSetType::ScopedLockType lock1 (otherSet.getLock());
398 if (
this == &otherSet)
402 else if (! otherSet.isEmpty())
404 for (
int i = data.size(); --i >= 0;)
405 if (otherSet.contains (data.getReference (i)))
417 template <
class OtherSetType>
420 const typename OtherSetType::ScopedLockType lock1 (otherSet.getLock());
423 if (
this != &otherSet)
425 if (otherSet.isEmpty())
431 for (
int i = data.size(); --i >= 0;)
432 if (! otherSet.contains (data.getReference (i)))
443 template <
class OtherSetType>
446 data.swapWith (otherSet.data);
458 data.minimiseStorageOverheads();
469 data.ensureStorageAllocated (minNumElements);
477 inline const TypeOfCriticalSectionToUse&
getLock() const noexcept {
return data.getLock(); }
489 #pragma warning (pop)
ElementType * begin() const noexcept
Returns a pointer to the first element in the set.
void clear() noexcept
Removes all elements from the set.
ElementType getFirst() const noexcept
Returns the first element in the set, or 0 if the set is empty.
SortedSet(SortedSet &&other) noexcept
Creates a copy of another set.
void clearQuick() noexcept
Removes all elements from the set without freeing the array's allocated storage.
void addArray(const ElementType *elementsToAdd, int numElementsToAdd) noexcept
Adds elements from an array to this set.
void removeValue(const ElementType valueToRemove) noexcept
Removes an item from the set.
bool add(const ElementType &newElement) noexcept
Adds a new element to the set, (as long as it's not already in there).
const TypeOfCriticalSectionToUse & getLock() const noexcept
Returns the CriticalSection that locks this array.
void ensureStorageAllocated(const int minNumElements)
Increases the set's internal storage to hold a minimum number of elements.
bool isEmpty() const noexcept
Returns true if the set is empty, false otherwise.
ElementType remove(const int indexToRemove) noexcept
Removes an element from the set.
void swapWith(OtherSetType &otherSet) noexcept
This swaps the contents of this array with those of another array.
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.
Holds a resizable array of primitive or copy-by-value objects.
SortedSet()=default
Creates an empty set.
typename DummyCriticalSection ::ScopedLockType ScopedLockType
Returns the type of scoped lock to use for locking this array.
int indexOf(const ElementType &elementToLookFor) const noexcept
Finds the index of the first element which matches the value passed in.
~SortedSet()=default
Destructor.
ElementType getLast() const noexcept
Returns the last element in the set, or 0 if the set is empty.
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.
bool contains(const ElementType &elementToLookFor) const noexcept
Returns true if the set contains at least one occurrence of an object.
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.
bool operator==(const SortedSet< ElementType > &other) const noexcept
Compares this set to another one.
SortedSet & operator=(const SortedSet &)=default
Makes a copy of 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 removeValuesNotIn(const OtherSetType &otherSet) noexcept
Removes any elements which are not found in another set.
ElementType * end() const noexcept
Returns a pointer to the element which follows the last element in the set.
void minimiseStorageOverheads() noexcept
Reduces the amount of storage being used by the set.
bool operator!=(const SortedSet< ElementType > &other) const noexcept
Compares this set to another one.