JUCE  v6.1.6 (6.0.8-1114)
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::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 juce::SparseSet< Type >:
Collaboration diagram for juce::SparseSet< Type >:

Public Member Functions

 SparseSet ()=default
 
 SparseSet (const SparseSet &)=default
 
 SparseSet (SparseSet &&other) noexcept
 
void addRange (Range< Type > range)
 Adds a range of contiguous values to the set. More...
 
void clear ()
 Clears the set. More...
 
bool contains (Type valueToLookFor) const noexcept
 Checks whether a particular value is in the set. More...
 
bool containsRange (Range< Type > range) const noexcept
 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...
 
Range< Type > getRange (int rangeIndex) const noexcept
 Returns one of the contiguous ranges of values stored. More...
 
const Array< Range< Type > > & getRanges () const noexcept
 Returns the set as a list of ranges, which you may want to iterate over. More...
 
Range< Type > getTotalRange () const noexcept
 Returns the range between the lowest and highest values in the set. More...
 
void invertRange (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 &other) const noexcept
 
SparseSetoperator= (const SparseSet &)=default
 
SparseSetoperator= (SparseSet &&other) noexcept
 
bool operator== (const SparseSet &other) const noexcept
 
Type operator[] (Type index) const noexcept
 Returns one of the values in the set. More...
 
bool overlapsRange (Range< Type > range) const noexcept
 Checks whether any part of a given range overlaps any part of this set. More...
 
void removeRange (Range< Type > rangeToRemove)
 Removes a range of values from the set. More...
 
Type size () const noexcept
 Returns the number of values in the set. More...
 

Private Member Functions

void simplify ()
 

Private Attributes

Array< Range< Type > > ranges
 

Detailed Description

template<class Type>
class juce::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.

@tags{Core}

Constructor & Destructor Documentation

◆ SparseSet() [1/3]

template<class Type >
juce::SparseSet< Type >::SparseSet ( )
default

◆ SparseSet() [2/3]

template<class Type >
juce::SparseSet< Type >::SparseSet ( const SparseSet< Type > &  )
default

◆ SparseSet() [3/3]

template<class Type >
juce::SparseSet< Type >::SparseSet ( SparseSet< Type > &&  other)
inlinenoexcept

Member Function Documentation

◆ addRange()

template<class Type >
void juce::SparseSet< Type >::addRange ( 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 juce::SparseSet< int >::invertRange().

◆ clear()

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

Clears the set.

◆ contains()

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

Checks whether a particular value is in the set.

◆ containsRange()

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

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

◆ getNumRanges()

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

Returns the number of contiguous blocks of values.

See also
getRange

◆ getRange()

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

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

◆ getRanges()

template<class Type >
const Array<Range<Type> >& juce::SparseSet< Type >::getRanges ( ) const
inlinenoexcept

Returns the set as a list of ranges, which you may want to iterate over.

◆ getTotalRange()

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

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

See also
getRange

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

◆ invertRange()

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

Does an XOR of the values in a given range.

◆ isEmpty()

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

Checks whether the set is empty.

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

◆ operator!=()

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

◆ operator=() [1/2]

template<class Type >
SparseSet& juce::SparseSet< Type >::operator= ( const SparseSet< Type > &  )
default

◆ operator=() [2/2]

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

◆ operator==()

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

◆ operator[]()

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

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 juce::SparseSet< Type >::overlapsRange ( Range< Type >  range) const
inlinenoexcept

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

◆ removeRange()

template<class Type >
void juce::SparseSet< Type >::removeRange ( 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 juce::SparseSet< int >::addRange(), and juce::SparseSet< int >::invertRange().

◆ simplify()

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

◆ size()

template<class Type >
Type juce::SparseSet< Type >::size ( ) const
inlinenoexcept

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

◆ ranges


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