OpenShot Audio Library | OpenShotAudio 0.3.2
Loading...
Searching...
No Matches
juce::SortedSet< ElementType, TypeOfCriticalSectionToUse > Class Template Reference

#include <juce_SortedSet.h>

Public Types

using ScopedLockType = typename TypeOfCriticalSectionToUse::ScopedLockType
 

Public Member Functions

 SortedSet ()=default
 
 SortedSet (const SortedSet &)=default
 
 SortedSet (SortedSet &&) noexcept=default
 
SortedSetoperator= (const SortedSet &)=default
 
SortedSetoperator= (SortedSet &&) noexcept=default
 
 ~SortedSet ()=default
 
bool operator== (const SortedSet< ElementType > &other) const noexcept
 
bool operator!= (const SortedSet< ElementType > &other) const noexcept
 
void clear () noexcept
 
void clearQuick () noexcept
 
int size () const noexcept
 
bool isEmpty () const noexcept
 
ElementType operator[] (const int index) const noexcept
 
ElementType getUnchecked (const int index) const noexcept
 
ElementType & getReference (const int index) noexcept
 
const ElementType & getReference (const int index) const noexcept
 
ElementType getFirst () const noexcept
 
ElementType getLast () const noexcept
 
const ElementType * begin () const noexcept
 
const ElementType * end () const noexcept
 
int indexOf (const ElementType &elementToLookFor) const noexcept
 
bool contains (const ElementType &elementToLookFor) const noexcept
 
bool add (const ElementType &newElement) noexcept
 
void addArray (const ElementType *elementsToAdd, int numElementsToAdd) noexcept
 
template<class OtherSetType >
void addSet (const OtherSetType &setToAddFrom, int startIndex=0, int numElementsToAdd=-1) noexcept
 
ElementType remove (const int indexToRemove) noexcept
 
void removeValue (const ElementType valueToRemove) noexcept
 
template<class OtherSetType >
void removeValuesIn (const OtherSetType &otherSet) noexcept
 
template<class OtherSetType >
void removeValuesNotIn (const OtherSetType &otherSet) noexcept
 
template<class OtherSetType >
void swapWith (OtherSetType &otherSet) noexcept
 
void minimiseStorageOverheads () noexcept
 
void ensureStorageAllocated (const int minNumElements)
 
const TypeOfCriticalSectionToUse & getLock () const noexcept
 

Detailed Description

template<class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection>
class juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >

Holds a set of unique primitive objects, such as ints or doubles.

A set can only hold one item with a given value, so if for example it's a set of integers, attempting to add the same integer twice will do nothing the second time.

Internally, the list of items is kept sorted (which means that whatever kind of primitive type is used must support the ==, <, >, <= and >= operators to determine the order), and searching the set for known values is very fast because it uses a binary-chop method.

Note that if you're using a class or struct as the element type, it must be capable of being copied or moved with a straightforward memcpy, rather than needing construction and destruction code.

To make all the set's methods thread-safe, pass in "CriticalSection" as the templated TypeOfCriticalSectionToUse parameter, instead of the default DummyCriticalSection.

See also
Array, OwnedArray, ReferenceCountedArray, StringArray, CriticalSection

Definition at line 56 of file juce_SortedSet.h.

Member Typedef Documentation

◆ ScopedLockType

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
using juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::ScopedLockType = typename TypeOfCriticalSectionToUse::ScopedLockType

Returns the type of scoped lock to use for locking this array

Definition at line 482 of file juce_SortedSet.h.

Constructor & Destructor Documentation

◆ SortedSet() [1/3]

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::SortedSet ( )
default

Creates an empty set.

◆ SortedSet() [2/3]

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::SortedSet ( const SortedSet< ElementType, TypeOfCriticalSectionToUse > &  )
default

Creates a copy of another set.

◆ SortedSet() [3/3]

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::SortedSet ( SortedSet< ElementType, TypeOfCriticalSectionToUse > &&  )
defaultnoexcept

Creates a copy of another set.

◆ ~SortedSet()

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::~SortedSet ( )
default

Destructor.

Member Function Documentation

◆ add()

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
bool juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::add ( const ElementType &  newElement)
inlinenoexcept

Adds a new element to the set, (as long as it's not already in there).

Note that if a matching element already exists, the new value will be assigned to the existing one using operator=, so that if there are any differences between the objects which were not recognised by the object's operator==, then the set will always contain a copy of the most recently added one.

Parameters
newElementthe new object to add to the set
Returns
true if the value was added, or false if it already existed
See also
set, insert, addIfNotAlreadyThere, addSorted, addSet, addArray

Definition at line 274 of file juce_SortedSet.h.

Referenced by juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::addArray().

◆ addArray()

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
void juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::addArray ( const ElementType *  elementsToAdd,
int  numElementsToAdd 
)
inlinenoexcept

Adds elements from an array to this set.

Parameters
elementsToAddthe array of elements to add
numElementsToAddhow many elements are in this other array
See also
add

Definition at line 318 of file juce_SortedSet.h.

Referenced by juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::addSet().

◆ addSet()

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
template<class OtherSetType >
void juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::addSet ( const OtherSetType setToAddFrom,
int  startIndex = 0,
int  numElementsToAdd = -1 
)
inlinenoexcept

Adds elements from another set to this one.

Parameters
setToAddFromthe set from which to copy the elements
startIndexthe first element of the other set to start copying from
numElementsToAddhow many elements to add from the other set. If this value is negative or greater than the number of available elements, all available elements will be copied.
See also
add

Definition at line 337 of file juce_SortedSet.h.

◆ begin()

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
const ElementType * juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::begin ( ) const
inlinenoexcept

Returns a pointer to the first element in the set. This method is provided for compatibility with standard C++ iteration mechanisms.

Definition at line 203 of file juce_SortedSet.h.

◆ clear()

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
void juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::clear ( )
inlinenoexcept

Removes all elements from the set.

This will remove all the elements, and free any storage that the set is using. To clear it without freeing the storage, use the clearQuick() method instead.

See also
clearQuick

Definition at line 106 of file juce_SortedSet.h.

Referenced by juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::removeValuesIn(), and juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::removeValuesNotIn().

◆ clearQuick()

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
void juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::clearQuick ( )
inlinenoexcept

Removes all elements from the set without freeing the array's allocated storage.

See also
clear

Definition at line 114 of file juce_SortedSet.h.

◆ contains()

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
bool juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::contains ( const ElementType &  elementToLookFor) const
inlinenoexcept

Returns true if the set contains at least one occurrence of an object.

Parameters
elementToLookForthe value or object to look for
Returns
true if the item is found

Definition at line 257 of file juce_SortedSet.h.

◆ end()

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
const ElementType * juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::end ( ) const
inlinenoexcept

Returns a pointer to the element which follows the last element in the set. This method is provided for compatibility with standard C++ iteration mechanisms.

Definition at line 211 of file juce_SortedSet.h.

◆ ensureStorageAllocated()

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
void juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::ensureStorageAllocated ( const int  minNumElements)
inline

Increases the set's internal storage to hold a minimum number of elements.

Calling this before adding a large known number of elements means that the set won't have to keep dynamically resizing itself as the elements are added, and it'll therefore be more efficient.

Definition at line 469 of file juce_SortedSet.h.

◆ getFirst()

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
ElementType juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::getFirst ( ) const
inlinenoexcept

Returns the first element in the set, or 0 if the set is empty.

See also
operator[], getUnchecked, getLast

Definition at line 186 of file juce_SortedSet.h.

◆ getLast()

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
ElementType juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::getLast ( ) const
inlinenoexcept

Returns the last element in the set, or 0 if the set is empty.

See also
operator[], getUnchecked, getFirst

Definition at line 194 of file juce_SortedSet.h.

◆ getLock()

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
const TypeOfCriticalSectionToUse & juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::getLock ( ) const
inlinenoexcept

◆ getReference() [1/2]

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
const ElementType & juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::getReference ( const int  index) const
inlinenoexcept

Returns a direct reference to one of the elements in the set, without checking the index passed in.

Parameters
indexthe index of the element being requested (0 is the first element in the array)

Definition at line 178 of file juce_SortedSet.h.

◆ getReference() [2/2]

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
ElementType & juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::getReference ( const int  index)
inlinenoexcept

Returns a direct reference to one of the elements in the set, without checking the index passed in.

This is like getUnchecked, but returns a direct reference to the element, so that you can alter it directly. Obviously this can be dangerous, so only use it when absolutely necessary.

Parameters
indexthe index of the element being requested (0 is the first element in the array)

Definition at line 169 of file juce_SortedSet.h.

◆ getUnchecked()

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
ElementType juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::getUnchecked ( const int  index) const
inlinenoexcept

Returns one of the elements in the set, without checking the index passed in. Unlike the operator[] method, this will try to return an element without checking that the index is within the bounds of the set, so should only be used when you're confident that it will always be a valid index.

Parameters
indexthe index of the element being requested (0 is the first element in the set)
See also
operator[], getFirst, getLast

Definition at line 156 of file juce_SortedSet.h.

◆ indexOf()

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
int juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::indexOf ( const ElementType &  elementToLookFor) const
inlinenoexcept

Finds the index of the first element which matches the value passed in.

This will search the set for the given object, and return the index of its first occurrence. If the object isn't found, the method will return -1.

Parameters
elementToLookForthe value or object to look for
Returns
the index of the object, or -1 if it's not found

Definition at line 225 of file juce_SortedSet.h.

Referenced by juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::contains(), and juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::removeValue().

◆ isEmpty()

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
bool juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::isEmpty ( ) const
inlinenoexcept

Returns true if the set is empty, false otherwise.

Definition at line 127 of file juce_SortedSet.h.

◆ minimiseStorageOverheads()

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
void juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::minimiseStorageOverheads ( )
inlinenoexcept

Reduces the amount of storage being used by the set.

Sets typically allocate slightly more storage than they need, and after removing elements, they may have quite a lot of unused space allocated. This method will reduce the amount of allocated storage to a minimum.

Definition at line 458 of file juce_SortedSet.h.

◆ operator!=()

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
bool juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::operator!= ( const SortedSet< ElementType > &  other) const
inlinenoexcept

Compares this set to another one. Two sets are considered equal if they both contain the same set of elements.

Parameters
otherthe other set to compare with

Definition at line 92 of file juce_SortedSet.h.

◆ operator=() [1/2]

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
SortedSet & juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::operator= ( const SortedSet< ElementType, TypeOfCriticalSectionToUse > &  )
default

Makes a copy of another set.

◆ operator=() [2/2]

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
SortedSet & juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::operator= ( SortedSet< ElementType, TypeOfCriticalSectionToUse > &&  )
defaultnoexcept

Makes a copy of another set.

◆ operator==()

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
bool juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::operator== ( const SortedSet< ElementType > &  other) const
inlinenoexcept

Compares this set to another one. Two sets are considered equal if they both contain the same set of elements.

Parameters
otherthe other set to compare with

Definition at line 83 of file juce_SortedSet.h.

Referenced by juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::operator!=().

◆ operator[]()

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
ElementType juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::operator[] ( const int  index) const
inlinenoexcept

Returns one of the elements in the set.

If the index passed in is beyond the range of valid elements, this will return zero.

If you're certain that the index will always be a valid element, you can call getUnchecked() instead, which is faster.

Parameters
indexthe index of the element being requested (0 is the first element in the set)
See also
getUnchecked, getFirst, getLast

Definition at line 143 of file juce_SortedSet.h.

◆ remove()

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
ElementType juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::remove ( const int  indexToRemove)
inlinenoexcept

Removes an element from the set.

This will remove the element at a given index. If the index passed in is out-of-range, nothing will happen.

Parameters
indexToRemovethe index of the element to remove
Returns
the element that has been removed
See also
removeValue, removeRange

Definition at line 371 of file juce_SortedSet.h.

Referenced by juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::removeValuesIn(), and juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::removeValuesNotIn().

◆ removeValue()

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
void juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::removeValue ( const ElementType  valueToRemove)
inlinenoexcept

Removes an item from the set.

This will remove the given element from the set, if it's there.

Parameters
valueToRemovethe object to try to remove
See also
remove, removeRange

Definition at line 383 of file juce_SortedSet.h.

◆ removeValuesIn()

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
template<class OtherSetType >
void juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::removeValuesIn ( const OtherSetType otherSet)
inlinenoexcept

Removes any elements which are also in another set.

Parameters
otherSetthe other set in which to look for elements to remove
See also
removeValuesNotIn, remove, removeValue, removeRange

Definition at line 395 of file juce_SortedSet.h.

◆ removeValuesNotIn()

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
template<class OtherSetType >
void juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::removeValuesNotIn ( const OtherSetType otherSet)
inlinenoexcept

Removes any elements which are not found in another set.

Only elements which occur in this other set will be retained.

Parameters
otherSetthe set in which to look for elements NOT to remove
See also
removeValuesIn, remove, removeValue, removeRange

Definition at line 420 of file juce_SortedSet.h.

◆ size()

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
int juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::size ( ) const
inlinenoexcept

Returns the current number of elements in the set.

Definition at line 121 of file juce_SortedSet.h.

Referenced by juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::isEmpty().

◆ swapWith()

template<class ElementType , class TypeOfCriticalSectionToUse = DummyCriticalSection>
template<class OtherSetType >
void juce::SortedSet< ElementType, TypeOfCriticalSectionToUse >::swapWith ( OtherSetType otherSet)
inlinenoexcept

This swaps the contents of this array with those of another array.

If you need to exchange two arrays, this is vastly quicker than using copy-by-value because it just swaps their internal pointers.

Definition at line 446 of file juce_SortedSet.h.


The documentation for this class was generated from the following file: