50 SparseSet& operator= (
SparseSet&& other)
noexcept { ranges = std::move (other.ranges);
return *
this; }
54 void clear() { ranges.clear(); }
59 bool isEmpty() const noexcept {
return ranges.isEmpty(); }
71 for (
auto& r : ranges)
72 total += r.getLength();
86 for (
auto& r : ranges)
88 auto end = total + r.getLength();
91 return r.getStart() + (index - total);
102 for (
auto& r : ranges)
104 if (r.getStart() > valueToLookFor)
107 if (r.getEnd() > valueToLookFor)
132 if (ranges.isEmpty())
135 return { ranges.getFirst().getStart(),
136 ranges.getLast().getEnd() };
162 for (
int i = ranges.size(); --i >= 0;)
164 auto& r = ranges.getReference (i);
166 if (r.getEnd() <= rangeToRemove.
getStart())
169 if (r.getStart() >= rangeToRemove.
getEnd())
176 else if (r.contains (rangeToRemove))
178 auto r1 = r.withEnd (rangeToRemove.
getStart());
179 auto r2 = r.withStart (rangeToRemove.
getEnd());
182 jassert (! r1.isEmpty() || ! r2.isEmpty());
189 if (! r1.isEmpty() && ! r2.isEmpty())
190 ranges.insert (i + 1, r2);
192 else if (rangeToRemove.
getEnd() > r.getEnd())
194 r.setEnd (rangeToRemove.
getStart());
198 r.setStart (rangeToRemove.
getEnd());
210 for (
auto& r : ranges)
215 for (
auto& r : newItems.ranges)
222 if (! range.isEmpty())
223 for (
auto& r : ranges)
224 if (r.intersects (range))
233 if (! range.isEmpty())
234 for (
auto& r : ranges)
235 if (r.contains (range))
245 bool operator== (
const SparseSet& other)
const noexcept {
return ranges == other.ranges; }
246 bool operator!= (
const SparseSet& other)
const noexcept {
return ranges != other.ranges; }
250 Array<Range<Type>> ranges;
254 for (
int i = ranges.size(); --i > 0;)
256 auto& r1 = ranges.getReference (i - 1);
257 auto& r2 = ranges.getReference (i);
259 if (r1.getEnd() == r2.getStart())
261 r1.setEnd (r2.getEnd());
Holds a resizable array of primitive or copy-by-value objects.
A general-purpose range object, that simply represents any linear range with a start and end point.
constexpr ValueType getStart() const noexcept
Returns the start of the range.
constexpr bool isEmpty() const noexcept
Returns true if the range has a length of zero.
constexpr ValueType getEnd() const noexcept
Returns the end of the range.
constexpr bool contains(const ValueType position) const noexcept
Returns true if the given position lies inside this range.
Holds a set of primitive values, storing them as a set of ranges.
Range< Type > getRange(int rangeIndex) const noexcept
Returns one of the contiguous ranges of values stored.
void invertRange(Range< Type > range)
Does an XOR of the values in a given range.
void clear()
Clears the set.
bool overlapsRange(Range< Type > range) const noexcept
Checks whether any part of a given range overlaps any part of this set.
Type size() const noexcept
Returns the number of values in the set.
void addRange(Range< Type > range)
Adds a range of contiguous values to the set.
bool isEmpty() const noexcept
Checks whether the set is empty.
Type operator[](Type index) const noexcept
Returns one of the values in the set.
bool contains(Type valueToLookFor) const noexcept
Checks whether a particular value is in the set.
int getNumRanges() const noexcept
Returns the number of contiguous blocks of values.
const Array< Range< Type > > & getRanges() const noexcept
Returns the set as a list of ranges, which you may want to iterate over.
Range< Type > getTotalRange() const noexcept
Returns the range between the lowest and highest values in the set.
bool containsRange(Range< Type > range) const noexcept
Checks whether the whole of a given range is contained within this one.
void removeRange(Range< Type > rangeToRemove)
Removes a range of values from the set.
RangedDirectoryIterator end(const RangedDirectoryIterator &)
Returns a default-constructed sentinel value.