54 SparseSet& operator= (
SparseSet&& other) noexcept { ranges = std::move (other.ranges);
return *
this; }
58 void clear() { ranges.clear(); }
63 bool isEmpty() const noexcept {
return ranges.isEmpty(); }
75 for (
auto& r : ranges)
76 total += r.getLength();
90 for (
auto& r : ranges)
92 auto end = total + r.getLength();
95 return r.getStart() + (index - total);
106 for (
auto& r : ranges)
108 if (r.getStart() > valueToLookFor)
111 if (r.getEnd() > valueToLookFor)
136 if (ranges.isEmpty())
139 return { ranges.getFirst().getStart(),
140 ranges.getLast().getEnd() };
153 std::sort (ranges.begin(), ranges.end(),
166 for (
int i = ranges.size(); --i >= 0;)
168 auto& r = ranges.getReference(i);
170 if (r.getEnd() <= rangeToRemove.
getStart())
173 if (r.getStart() >= rangeToRemove.
getEnd())
180 else if (r.contains (rangeToRemove))
182 auto r1 = r.withEnd (rangeToRemove.
getStart());
183 auto r2 = r.withStart (rangeToRemove.
getEnd());
186 jassert (! r1.isEmpty() || ! r2.isEmpty());
193 if (! r1.isEmpty() && ! r2.isEmpty())
194 ranges.insert (i + 1, r2);
196 else if (rangeToRemove.
getEnd() > r.getEnd())
198 r.setEnd (rangeToRemove.
getStart());
202 r.setStart (rangeToRemove.
getEnd());
214 for (
auto& r : ranges)
219 for (
auto& r : newItems.ranges)
226 if (! range.isEmpty())
227 for (
auto& r : ranges)
228 if (r.intersects (range))
237 if (! range.isEmpty())
238 for (
auto& r : ranges)
239 if (r.contains (range))
249 bool operator== (
const SparseSet& other)
const noexcept {
return ranges == other.ranges; }
250 bool operator!= (
const SparseSet& other)
const noexcept {
return ranges != other.ranges; }
254 Array<Range<Type>> ranges;
258 for (
int i = ranges.size(); --i > 0;)
260 auto& r1 = ranges.getReference (i - 1);
261 auto& r2 = ranges.getReference (i);
263 if (r1.getEnd() == r2.getStart())
265 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.
JUCE_CONSTEXPR ValueType getStart() const noexcept
Returns the start of the range.
JUCE_CONSTEXPR bool contains(const ValueType position) const noexcept
Returns true if the given position lies inside this range.
JUCE_CONSTEXPR bool isEmpty() const noexcept
Returns true if the range has a length of zero.
JUCE_CONSTEXPR ValueType getEnd() const noexcept
Returns the end of the 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.
Range< Type > getTotalRange() const noexcept
Returns the range between the lowest and highest values in the 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.
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.