JUCE  v5.1.1-3-g1a0b28c73
JUCE API
SparseSet< Type > Class Template Reference

Holds a set of primitive values, storing them as a set of ranges. More...

#include <juce_SparseSet.h>

Inheritance diagram for SparseSet< Type >:
Collaboration diagram for SparseSet< Type >:

Public Member Functions

 SparseSet ()
 Creates a new empty set. More...
 
 SparseSet (const SparseSet< Type > &other)
 Creates a copy of another SparseSet. More...
 
void addRange (const Range< Type > range)
 Adds a range of contiguous values to the set. More...
 
void clear ()
 Clears the set. More...
 
bool contains (const Type valueToLookFor) const
 Checks whether a particular value is in the set. More...
 
bool containsRange (const Range< Type > range)
 Checks whether the whole of a given range is contained within this one. More...
 
int getNumRanges () const noexcept
 Returns the number of contiguous blocks of values. More...
 
const Range< Type > getRange (const int rangeIndex) const
 Returns one of the contiguous ranges of values stored. More...
 
Range< Type > getTotalRange () const
 Returns the range between the lowest and highest values in the set. More...
 
void invertRange (const Range< Type > range)
 Does an XOR of the values in a given range. More...
 
bool isEmpty () const noexcept
 Checks whether the set is empty. More...
 
bool operator!= (const SparseSet< Type > &other) noexcept
 
bool operator== (const SparseSet< Type > &other) noexcept
 
Type operator[] (Type index) const
 Returns one of the values in the set. More...
 
bool overlapsRange (const Range< Type > range)
 Checks whether any part of a given range overlaps any part of this set. More...
 
void removeRange (const Range< Type > rangeToRemove)
 Removes a range of values from the set. More...
 
Type size () const
 Returns the number of values in the set. More...
 

Private Member Functions

void simplify ()
 

Private Attributes

Array< Type, DummyCriticalSectionvalues
 

Detailed Description

template<class Type>
class SparseSet< Type >

Holds a set of primitive values, storing them as a set of ranges.

This container acts like an array, but can efficiently hold large contiguous ranges of values. It's quite a specialised class, mostly useful for things like keeping the set of selected rows in a listbox.

The type used as a template parameter must be an integer type, such as int, short, int64, etc.

Constructor & Destructor Documentation

◆ SparseSet() [1/2]

template<class Type>
SparseSet< Type >::SparseSet ( )
inline

Creates a new empty set.

◆ SparseSet() [2/2]

template<class Type>
SparseSet< Type >::SparseSet ( const SparseSet< Type > &  other)
inline

Creates a copy of another SparseSet.

Member Function Documentation

◆ addRange()

template<class Type>
void SparseSet< Type >::addRange ( const Range< Type >  range)
inline

Adds a range of contiguous values to the set.

e.g. addRange (Range <int> (10, 14)) will add (10, 11, 12, 13) to the set.

Referenced by SparseSet< int >::invertRange().

◆ clear()

template<class Type>
void SparseSet< Type >::clear ( )
inline

Clears the set.

◆ contains()

template<class Type>
bool SparseSet< Type >::contains ( const Type  valueToLookFor) const
inline

Checks whether a particular value is in the set.

Referenced by SparseSet< int >::removeRange().

◆ containsRange()

template<class Type>
bool SparseSet< Type >::containsRange ( const Range< Type >  range)
inline

Checks whether the whole of a given range is contained within this one.

◆ getNumRanges()

template<class Type>
int SparseSet< Type >::getNumRanges ( ) const
inlinenoexcept

◆ getRange()

template<class Type>
const Range<Type> SparseSet< Type >::getRange ( const int  rangeIndex) const
inline

Returns one of the contiguous ranges of values stored.

Parameters
rangeIndexthe index of the range to look up, between 0 and (getNumRanges() - 1)
See also
getTotalRange

Referenced by SparseSet< int >::invertRange().

◆ getTotalRange()

template<class Type>
Range<Type> SparseSet< Type >::getTotalRange ( ) const
inline

Returns the range between the lowest and highest values in the set.

See also
getRange

◆ invertRange()

template<class Type>
void SparseSet< Type >::invertRange ( const Range< Type >  range)
inline

Does an XOR of the values in a given range.

◆ isEmpty()

template<class Type>
bool SparseSet< Type >::isEmpty ( ) const
inlinenoexcept

Checks whether the set is empty.

This is much quicker than using (size() == 0).

◆ operator!=()

template<class Type>
bool SparseSet< Type >::operator!= ( const SparseSet< Type > &  other)
inlinenoexcept

◆ operator==()

template<class Type>
bool SparseSet< Type >::operator== ( const SparseSet< Type > &  other)
inlinenoexcept

◆ operator[]()

template<class Type>
Type SparseSet< Type >::operator[] ( Type  index) const
inline

Returns one of the values in the set.

Parameters
indexthe index of the value to retrieve, in the range 0 to (size() - 1).
Returns
the value at this index, or 0 if it's out-of-range

◆ overlapsRange()

template<class Type>
bool SparseSet< Type >::overlapsRange ( const Range< Type >  range)
inline

Checks whether any part of a given range overlaps any part of this set.

◆ removeRange()

template<class Type>
void SparseSet< Type >::removeRange ( const Range< Type >  rangeToRemove)
inline

Removes a range of values from the set.

e.g. removeRange (Range<int> (10, 14)) will remove (10, 11, 12, 13) from the set.

Referenced by SparseSet< int >::addRange(), and SparseSet< int >::invertRange().

◆ simplify()

template<class Type>
void SparseSet< Type >::simplify ( )
inlineprivate

◆ size()

template<class Type>
Type SparseSet< Type >::size ( ) const
inline

Returns the number of values in the set.

Because of the way the data is stored, this method can take longer if there are a lot of items in the set. Use isEmpty() for a quick test of whether there are any items.

Member Data Documentation

◆ values


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