IndexSet.hpp
Collection of indices, ideally optimized for memory size.
Note
Status: ALPHA
-
class IndexRange
- #include <IndexSet.hpp>
Index range is a simple pair of values indicating the start and end of a series of indices.
Public Functions
-
IndexRange() = default
-
inline IndexRange(size_t val)
-
inline IndexRange(size_t _start, size_t _end)
-
IndexRange(const IndexRange&) = default
-
IndexRange &operator=(const IndexRange&) = default
- auto operator (const IndexRange &) const =default
-
inline size_t GetStart() const
-
inline size_t GetEnd() const
-
inline size_t GetSize() const
-
inline void SetStart(size_t in)
-
inline void SetEnd(size_t in)
-
inline bool Has(size_t val) const
-
inline bool Has(IndexRange in) const
-
inline bool IsConnected(IndexRange in) const
Will identify if two ranges are next to each other or overlapping.
-
inline void Grow(size_t count = 1)
Grow this range (default, by one)
-
inline bool Insert(size_t val)
Insert a value into a range if valid; return false if not.
-
inline bool Append(IndexRange in)
Extend the current range with a new one. Must be perfectly adjacent!
-
inline bool Expand(size_t val)
Expand this range to encompass a provided value.
- Parameters:
val – Value to expand through.
- Returns:
Whether the range has changed due to this expansion.
-
template<typename ...Ts>
inline bool Expand(size_t val1, size_t val2, Ts... args) Expand this range to encompass all provided values.
- Parameters:
vals – Values to expand through
- Returns:
Whether the range has changed due to this expansion.
-
inline bool Merge(IndexRange in)
Merge this range with another. Must be adjacent or overlap!
-
IndexRange() = default
-
class IndexRangeSet
- #include <IndexSet.hpp>
IndexRanges is a class to maintain a series of ranges of indexes. The ranges will always be kept sorted and non-adjacent (i.e., there will always be at least one index missing between two ranges).
Public Functions
-
IndexRangeSet() = default
-
IndexRangeSet(const IndexRangeSet&) = default
-
IndexRangeSet(IndexRangeSet&&) = default
-
IndexRangeSet &operator=(const IndexRangeSet&) = default
-
IndexRangeSet &operator=(IndexRangeSet&&) = default
-
inline bool Has(size_t val) const
-
inline size_t GetStart() const
-
inline size_t GetEnd() const
-
inline size_t GetNumRanges() const
-
inline size_t GetSize() const
Calculate the total combined size of all ranges.
-
inline const vector<IndexRange> &GetRanges() &
-
inline bool Append(size_t val)
Add a new value that belongs at the end of the sets.
- Parameters:
val – Value to add
- Returns:
Did the append work? If it’s not at the end, returns false.
-
inline bool Append(IndexRange in)
Add an entire range that belongs at the end of the sets.
- Parameters:
val – Range to add
- Returns:
Did the append work? If it’s not at the end, returns false.
-
inline bool Insert(size_t val)
Insert a value into this range set.
- Parameters:
val – Value to insert.
- Returns:
Was there a change due to this insertion (or was it already there?)
-
inline bool Insert(IndexRange in)
Insert a whole range into this set, merging other ranges as needed.
- Parameters:
in – New range to include.
- Returns:
Was there a change due to this insertion (or were they already there?)
-
inline bool Remove(size_t val)
Remove a single value from this index range.
- Parameters:
val – Value to remove
- Returns:
Did the range change due to this removal?
Private Members
-
vector<IndexRange> range_set
-
IndexRangeSet() = default
-
class IndexBits
- #include <IndexSet.hpp>
A class to maintain a set of indices with a bit vector to represent them.
Public Functions
-
IndexBits() = default
-
inline IndexBits(size_t min_val, size_t max_val)
-
inline bool Has(size_t val) const
-
inline size_t GetStart() const
-
inline size_t GetEnd() const
-
inline size_t GetNumRanges() const
-
inline size_t GetSize() const
-
inline bool Insert(size_t val)
-
inline bool Insert(IndexRange in)
-
inline bool Remove(size_t val)
-
IndexBits() = default
-
class IndexSet
- #include <IndexSet.hpp>
IndexSet maintains a collection of indices that can be easily manipulated. It will try to adjust representation to maintain speed and memory efficiency.
Public Functions
-
IndexSet() = default
-
inline ~IndexSet()
-
inline size_t GetSize() const
-
inline bool Has(size_t id) const
-
inline size_t GetMin() const
-
inline size_t GetMax() const
-
inline bool IsConsecutive() const
-
inline void Set(size_t id)
Public Static Attributes
-
static constexpr const size_t npos = static_cast<size_t>(-1)
Private Types
Private Functions
-
inline void _ReleaseUnion()
Free whatever type we currently have.
-
inline void _ToBits()
Convert the internal representation to use bits.
-
inline void _ToRanges()
Convert the internal representation to use a ranges.
-
struct _Index_Vals
-
IndexSet() = default