snippets 0.1.0
Loading...
Searching...
No Matches
hsc_snippets::IntervalSet< T > Class Template Reference

#include <interval.hpp>

Public Member Functions

 IntervalSet ()=default
 
void update (T left, T right)
 
bool query (T index) const
 
bool query (const Interval< T > &interval) const
 
std::vector< std::pair< T, T > > getIntervals () const
 
void defragment ()
 

Constructor & Destructor Documentation

◆ IntervalSet()

template<std::integral T>
hsc_snippets::IntervalSet< T >::IntervalSet ( )
explicitdefault

Member Function Documentation

◆ defragment()

template<std::integral T>
void hsc_snippets::IntervalSet< T >::defragment ( )
inline

Merges adjacent intervals to reduce fragmentation.

◆ getIntervals()

template<std::integral T>
std::vector< std::pair< T, T > > hsc_snippets::IntervalSet< T >::getIntervals ( ) const
inline

Retrieves all intervals in the set.

Returns
A vector of pairs representing intervals [left, right).

◆ query() [1/2]

template<std::integral T>
bool hsc_snippets::IntervalSet< T >::query ( const Interval< T > & interval) const
inline

Checks if a given interval intersects with any intervals in the set.

Parameters
intervalThe interval to check for intersection.
Returns
True if the interval intersects with any existing intervals; otherwise, false.

◆ query() [2/2]

template<std::integral T>
bool hsc_snippets::IntervalSet< T >::query ( T index) const
inline

Checks if a given index is within any of the intervals in the set.

Parameters
indexThe index to query.
Returns
True if the index is within an interval; otherwise, false.

◆ update()

template<std::integral T>
void hsc_snippets::IntervalSet< T >::update ( T left,
T right )
inline

Updates the interval set by adding a new interval specified by left (inclusive) and right (exclusive) boundaries. If the new interval overlaps with existing intervals, they will be merged into a single interval. But there might be fragmentation!

Parameters
leftThe starting boundary of the interval to add, inclusive.
rightThe ending boundary of the interval to add, exclusive. Must be greater than left.

this is non-trivial


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