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)
139 return { ranges.
getFirst().getStart(),
153 std::sort (ranges.
begin(), ranges.
end(),
166 for (
int i = ranges.
size(); --i >= 0;)
214 for (
auto& r : 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))
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;)
263 if (r1.getEnd() == r2.getStart())
265 r1.setEnd (r2.getEnd());
Holds a resizable array of primitive or copy-by-value objects.
bool isEmpty() const noexcept
Returns true if the array is empty, false otherwise.
int size() const noexcept
Returns the current number of elements in the array.
void removeRange(int startIndex, int numberToRemove)
Removes a range of elements from the array.
ElementType * begin() const noexcept
Returns a pointer to the first element in the array.
void remove(int indexToRemove)
Removes an element from the array.
void insert(int indexToInsertAt, ParameterType newElement)
Inserts a new element into the array at a given position.
ElementType getFirst() const noexcept
Returns the first element in the array, or a default value if the array is empty.
void add(const ElementType &newElement)
Appends a new element at the end of the array.
ElementType & getReference(int index) const noexcept
Returns a direct reference to one of the elements in the array, without checking the index passed in.
bool contains(ParameterType elementToLookFor) const
Returns true if the array contains at least one occurrence of an object.
void clear()
Removes all elements from the array.
ElementType getLast() const noexcept
Returns the last element in the array, or a default value if the array is empty.
ElementType * end() const noexcept
Returns a pointer to the element which follows the last element in the array.
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.