snippets 0.1.0
Loading...
Searching...
No Matches
hsc_snippets::IntervalMap< T, V, update_policy_t > Class Template Reference

#include <interval.hpp>

Public Member Functions

 IntervalMap ()=default
 
void update (T left, T right, V value)
 
std::optional< V > query (T index)
 
void defragment ()
 
std::vector< std::tuple< T, T, V > > getIntervals () const
 

Detailed Description

template<std::integral T, std::integral V, typename update_policy_t = Override<T>>
class hsc_snippets::IntervalMap< T, V, update_policy_t >

Manages intervals with associated values, allowing efficient updates and queries.

Template Parameters:

  • T: Integral type for interval endpoints.
  • V: Integral type for values associated with intervals.
  • update_policy_t: Callable that resolves value conflicts during updates.

Uses std::map to store non-overlapping intervals. Supports adding intervals, querying values at points, and defragmenting adjacent intervals with identical values.

Constructor & Destructor Documentation

◆ IntervalMap()

template<std::integral T, std::integral V, typename update_policy_t = Override<T>>
hsc_snippets::IntervalMap< T, V, update_policy_t >::IntervalMap ( )
explicitdefault

Member Function Documentation

◆ defragment()

template<std::integral T, std::integral V, typename update_policy_t = Override<T>>
void hsc_snippets::IntervalMap< T, V, update_policy_t >::defragment ( )
inline

Merges adjacent intervals with identical values to reduce fragmentation.

◆ getIntervals()

template<std::integral T, std::integral V, typename update_policy_t = Override<T>>
std::vector< std::tuple< T, T, V > > hsc_snippets::IntervalMap< T, V, update_policy_t >::getIntervals ( ) const
inline

Retrieves a list of all intervals and their associated values.

Returns
A std::vector of std::tuple<T, T, V> elements, where each tuple represents an interval with its left and right boundaries and its associated value.

◆ query()

template<std::integral T, std::integral V, typename update_policy_t = Override<T>>
std::optional< V > hsc_snippets::IntervalMap< T, V, update_policy_t >::query ( T index)
inline

Retrieves the value associated with a specific index.

Parameters
indexThe index to query.
Returns
Optional value if the index is within an interval; otherwise, nullopt.

◆ update()

template<std::integral T, std::integral V, typename update_policy_t = Override<T>>
void hsc_snippets::IntervalMap< T, V, update_policy_t >::update ( T left,
T right,
V value )
inline

Adds or updates an interval [left, right) with the specified value. Merges overlapping intervals using the update policy.

Parameters
leftInclusive start of the interval.
rightExclusive end of the interval (must be greater than left).
valueValue to associate with the interval.

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