Skip to main content

DigitalIntervalSeries

DigitalIntervalSeries

A sorted collection of time intervals with entity tracking. More…

#include <Digital_Interval_Series.hpp>

Inherits from ObserverData

Public Classes

Name
struct DataTraits

Public Types

Name
enum class RangeMode { CONTAINED, OVERLAPPING, CLIP}
Controls how intervals at range boundaries are handled.

Public Functions

Name
DigitalIntervalSeries() =default
Default constructor.
DigitalIntervalSeries(std::vector< TimeFrameInterval > digital_vector)
Constructor for DigitalIntervalSeries from a vector of intervals.
DigitalIntervalSeries(std::vector< std::pair< float, float > > const & digital_vector)
Constructor from float pairs (legacy support).
auto view() const
Get a std::ranges compatible view of the series in absolute clock-tick time.
TimeFrameInterval getStoredInterval(size_t index) const
Get the stored interval at a flat storage index in TimeFrameIndex space.
auto viewInRange(TimeFrameIndex start_index, TimeFrameIndex stop_index, TimeFrame const & source_time_frame) const
Get intervals in a time range as a lazy view of IntervalWithId objects.
auto viewIntervalsInRange(TimeFrameIndex start_index, TimeFrameIndex stop_index, TimeFrame const & source_time_frame) const
Get overlapping intervals in a range as a lazy view of clock-tick intervals.
bool hasIntervalAtTime(TimeFrameIndex time, TimeFrame const & source_time_frame) const
Check if any interval contains the specified time.
void addEvent(TimeFrameInterval new_interval)
void addEvent(TimeFrameIndex start, TimeFrameIndex end)
void setEventAtTime(TimeFrameIndex time, bool event)
bool removeInterval(TimeFrameInterval const & interval)
Remove an interval from the series.
size_t removeIntervals(std::vector< TimeFrameInterval > const & intervals)
Remove multiple intervals from the series.
template <typename T ,typename B >
void
setEventsAtTimes(std::vector< T > times, std::vector< B > events)
std::size_t copyByEntityIds(DigitalIntervalSeries & target, std::unordered_set< EntityId > const & entity_ids, NotifyObservers notify)
Copy intervals with specific EntityIds to another DigitalIntervalSeries.
size_t size() const
IntervalLayout layout() const
Get the interval layout fixed at construction.
template
auto
getIntervalsInRange(TimeFrameIndex start_time, TimeFrameIndex stop_time, TimeFrame const & source_timeframe) const
Get intervals in a time range with TimeFrame conversion.
void setTimeFrame(std::shared_ptr< TimeFrame > time_frame)
Set the time frame.
std::shared_ptr< TimeFrame > getTimeFrame() const
Get the time frame.
void setIdentityContext(std::string const & data_key, EntityRegistry * registry)
void rebuildAllEntityIds()
std::optional< ClockTicksInterval > getIntervalByEntityId(EntityId entity_id) const
Find the interval data associated with a specific EntityId.
std::vector< std::pair< EntityId, ClockTicksInterval > > getIntervalsByEntityIds(std::vector< EntityId > const & entity_ids) const
Get all intervals that match the given EntityIds.
bool isView() const
Check if this series uses view storage (doesn’t own data).
bool isLazy() const
Check if this series uses lazy storage.
DigitalIntervalStorageType getStorageType() const
Get the storage type of this series.
std::shared_ptr< DigitalIntervalSeries > materialize() const
Materialize this series into a new owning series.
DigitalIntervalStorageCache getStorageCache() const
Get the storage cache for fast-path iteration.
std::shared_ptr< DigitalIntervalSeries > createOverlapping(std::vector< TimeFrameInterval > intervals, std::shared_ptr< TimeFrame > time_frame =[nullptr])
Create a series that preserves overlapping intervals on insert.
std::shared_ptr< DigitalIntervalSeries > createView(std::shared_ptr< DigitalIntervalSeries const > const & source, TimeFrameIndex start, TimeFrameIndex end)
Create a view of this series filtered by time range.
std::shared_ptr< DigitalIntervalSeries > createView(std::shared_ptr< DigitalIntervalSeries const > const & source, std::unordered_set< EntityId > const & entity_ids)
Create a view of this series filtered by EntityIds.
template <typename ViewType >
std::shared_ptr< DigitalIntervalSeries >
createFromView(ViewType view, size_t num_elements, std::shared_ptr< TimeFrame > time_frame =[nullptr], IntervalLayout layout =IntervalLayout::Overlapping)

Additional inherited members

Public Classes inherited from ObserverData

Name
struct ObserverEntry
Entry in the observer map.

Public Types inherited from ObserverData

Name
using std::function< void()> ObserverCallback
Type alias for observer callback functions.
using int CallbackID
Type alias for callback identifiers.

Public Functions inherited from ObserverData

Name
ObserverData(std::string name =“UnnamedObservable”)
CallbackID addObserver(ObserverCallback callback, std::string name =“Anonymous”)
Register a new observer callback.
void notifyObservers()
Notify all registered observers.
void removeObserver(CallbackID id)
Remove a previously registered observer.

Detailed Description

class DigitalIntervalSeries;

A sorted collection of time intervals with entity tracking.

DigitalIntervalSeries stores intervals as (start, end, EntityId) tuples, maintaining intervals in sorted order by start time. Each interval represents a time range (compare to DigitalEventSeries for discrete time points).

Primary Interface

Storage Backends

The class supports three storage backends (Owning, View, Lazy) that provide different performance tradeoffs. See Digital_Interval_Series.hpp for details.

Example Usage


// Create and populate a series
DigitalIntervalSeries series;
series.setTimeFrame(my_time_frame);
series.addEvent(Interval{100, 200});
series.addEvent(Interval{300, 400});

// Iterate all intervals
for (auto interval : series.view()) {
    std::cout << "Interval [" << interval.interval.start 
              << ", " << interval.interval.end << "] with id " 
              << interval.entity_id.getValue() << "\n";
}

// Query range with timeframe
for (auto interval : series.viewInRange(start, end, source_timeframe)) {
    process(interval);
}

// Create filtered view
auto filtered = DigitalIntervalSeries::createView(
    std::make_shared<DigitalIntervalSeries>(series),
    50, 250);  // Intervals overlapping [50, 250]

Intervals are always sorted by start time.

View and Lazy storage will auto-materialize on mutation.

ClockTicksIntervalWithId for view() element accessors (time(), id(), value())

DigitalEventSeries for discrete event data

Public Types Documentation

enum RangeMode

Enumerator Value Description
CONTAINED Only intervals fully contained within range.
OVERLAPPING Any interval that overlaps with range.
CLIP Clip intervals at range boundaries.

Controls how intervals at range boundaries are handled.

Public Functions Documentation

function DigitalIntervalSeries

DigitalIntervalSeries() =default

Default constructor.

This constructor creates an empty DigitalIntervalSeries with owning storage.

function DigitalIntervalSeries

explicit DigitalIntervalSeries(
    std::vector< TimeFrameInterval > digital_vector
)

Constructor for DigitalIntervalSeries from a vector of intervals.

Parameters:

  • digital_vector Vector of intervals (will be sorted)

Intervals are sorted during construction. EntityIds are initialized to 0.

function DigitalIntervalSeries

explicit DigitalIntervalSeries(
    std::vector< std::pair< float, float > > const & digital_vector
)

Constructor from float pairs (legacy support).

Parameters:

  • digital_vector Vector of (start, end) pairs as floats

function view

inline auto view() const

Get a std::ranges compatible view of the series in absolute clock-tick time.

See: getStoredInterval for index-space access (save/export)

Precondition: series time frame must be set (getTimeFrame() non-null)

Returns a random-access view that synthesizes ClockTicksIntervalWithId objects on demand.

function getStoredInterval

inline TimeFrameInterval getStoredInterval(
    size_t index
) const

Get the stored interval at a flat storage index in TimeFrameIndex space.

Parameters:

  • index Flat index in [0, size())

Return: TimeFrameInterval from internal storage

Use for save/export and other persistence paths that must write index coordinates.

function viewInRange

inline auto viewInRange(
    TimeFrameIndex start_index,
    TimeFrameIndex stop_index,
    TimeFrame const & source_time_frame
) const

Get intervals in a time range as a lazy view of IntervalWithId objects.

Parameters:

  • start_index Start time index (inclusive)
  • stop_index Stop time index (inclusive)
  • source_time_frame The time frame that start_index/stop_index are expressed in

Return: Lazy view of ClockTicksIntervalWithId objects overlapping the range

Precondition: series time frame must be set (getTimeFrame() non-null)

This is the primary range query interface. It requires a source TimeFrame parameter to enable proper time conversion when the query time base differs from the series’ internal time base.

Returns intervals that overlap with the given range [start_index, stop_index].

function viewIntervalsInRange

inline auto viewIntervalsInRange(
    TimeFrameIndex start_index,
    TimeFrameIndex stop_index,
    TimeFrame const & source_time_frame
) const

Get overlapping intervals in a range as a lazy view of clock-tick intervals.

Parameters:

  • start_index Start time index (inclusive)
  • stop_index Stop time index (inclusive)
  • source_time_frame The time frame that start_index/stop_index are expressed in

Return: Lazy view of ClockTicksInterval values overlapping the range

Precondition: series time frame must be set (getTimeFrame() non-null)

function hasIntervalAtTime

inline bool hasIntervalAtTime(
    TimeFrameIndex time,
    TimeFrame const & source_time_frame
) const

Check if any interval contains the specified time.

Parameters:

  • time The time index to check
  • source_time_frame The time frame that the time index is expressed in

Return: true if any interval contains the time, false otherwise

function addEvent

void addEvent(
    TimeFrameInterval new_interval
)

function addEvent

void addEvent(
    TimeFrameIndex start,
    TimeFrameIndex end
)

function setEventAtTime

void setEventAtTime(
    TimeFrameIndex time,
    bool event
)

function removeInterval

bool removeInterval(
    TimeFrameInterval const & interval
)

Remove an interval from the series.

Parameters:

  • interval The interval to remove

Return: True if the interval was found and removed, false otherwise

function removeIntervals

size_t removeIntervals(
    std::vector< TimeFrameInterval > const & intervals
)

Remove multiple intervals from the series.

Parameters:

  • intervals The intervals to remove

Return: The number of intervals that were successfully removed

function setEventsAtTimes

template <typename T ,
typename B >
inline void setEventsAtTimes(
    std::vector< T > times,
    std::vector< B > events
)

function copyByEntityIds

std::size_t copyByEntityIds(
    DigitalIntervalSeries & target,
    std::unordered_set< EntityId > const & entity_ids,
    NotifyObservers notify
)

Copy intervals with specific EntityIds to another DigitalIntervalSeries.

Parameters:

  • target The target series to copy intervals to
  • entity_ids Set of EntityIds to copy
  • notify If Yes, the target notifies observers after the operation

Return: The number of intervals actually copied (before any merging)

Note: When the target layout is Disjoint, addEvent merges overlapping intervals and the number of intervals added may be fewer than the number of EntityIds matched.

Copies all intervals matching the given EntityIds to the target series. Copied intervals get new EntityIds in the target based on the target’s identity context (via addEvent which auto-assigns EntityIds).

function size

inline size_t size() const

function layout

inline IntervalLayout layout() const

Get the interval layout fixed at construction.

Return: IntervalLayout::Disjoint (default) or IntervalLayout::Overlapping

function getIntervalsInRange

template <RangeMode mode =RangeMode::CONTAINED>
inline auto getIntervalsInRange(
    TimeFrameIndex start_time,
    TimeFrameIndex stop_time,
    TimeFrame const & source_timeframe
) const

Get intervals in a time range with TimeFrame conversion.

Parameters:

  • start_time Start time index in source_timeframe
  • stop_time Stop time index in source_timeframe
  • source_timeframe TimeFrame the indices are expressed in

Template Parameters:

Deprecated:

For OVERLAPPING mode, prefer viewInRange() or viewIntervalsInRange() which provide lazy evaluation.

See: viewIntervalsInRange for preferred alternative

Return: Lazy view of ClockTicksInterval objects (or vector for CLIP mode)

Precondition: series time frame must be set (getTimeFrame() non-null)

function setTimeFrame

inline void setTimeFrame(
    std::shared_ptr< TimeFrame > time_frame
)

Set the time frame.

Parameters:

  • time_frame The time frame to set

function getTimeFrame

inline std::shared_ptr< TimeFrame > getTimeFrame() const

Get the time frame.

Return: The time frame (may be nullptr)

function setIdentityContext

inline void setIdentityContext(
    std::string const & data_key,
    EntityRegistry * registry
)

function rebuildAllEntityIds

void rebuildAllEntityIds()

function getIntervalByEntityId

std::optional< ClockTicksInterval > getIntervalByEntityId(
    EntityId entity_id
) const

Find the interval data associated with a specific EntityId.

Parameters:

Return: Optional containing the interval data if found, std::nullopt otherwise

This method provides reverse lookup from EntityId to the actual interval data, supporting group-based visualization workflows.

function getIntervalsByEntityIds

std::vector< std::pair< EntityId, ClockTicksInterval > > getIntervalsByEntityIds(
    std::vector< EntityId > const & entity_ids
) const

Get all intervals that match the given EntityIds.

Parameters:

  • entity_ids Vector of EntityIds to look up

Return: Vector of pairs containing {EntityId, Interval} for found entities

This method is optimized for batch lookup of multiple EntityIds, useful for group-based operations.

function isView

inline bool isView() const

Check if this series uses view storage (doesn’t own data).

Return: true if storage is a view, false otherwise

function isLazy

inline bool isLazy() const

Check if this series uses lazy storage.

Return: true if storage is lazy-evaluated, false otherwise

function getStorageType

inline DigitalIntervalStorageType getStorageType() const

Get the storage type of this series.

Return: The storage type enum value

function materialize

std::shared_ptr< DigitalIntervalSeries > materialize() const

Materialize this series into a new owning series.

Return: Shared pointer to new owning series

If this series uses view or lazy storage, creates a new series with owning storage containing copies of all data.

function getStorageCache

inline DigitalIntervalStorageCache getStorageCache() const

Get the storage cache for fast-path iteration.

Return: DigitalIntervalStorageCache with valid pointers if contiguous

Returns a cache structure with pointers to contiguous data if available.

function createOverlapping

static std::shared_ptr< DigitalIntervalSeries > createOverlapping(
    std::vector< TimeFrameInterval > intervals,
    std::shared_ptr< TimeFrame > time_frame =nullptr
)

Create a series that preserves overlapping intervals on insert.

Parameters:

  • intervals Initial intervals (sorted during construction)
  • time_frame Optional time frame for the series

Return: Shared pointer to new owning series with Overlapping layout

Intervals are sorted and stored without merging. Intended for transform pipeline intermediates rather than interactive annotation.

function createView

static std::shared_ptr< DigitalIntervalSeries > createView(
    std::shared_ptr< DigitalIntervalSeries const > const & source,
    TimeFrameIndex start,
    TimeFrameIndex end
)

Create a view of this series filtered by time range.

Parameters:

  • start Start time (inclusive)
  • end End time (inclusive)

Return: Shared pointer to new view-based series

Returns a new DigitalIntervalSeries that references this series’ data without copying. The view includes intervals overlapping with [start, end].

function createView

static std::shared_ptr< DigitalIntervalSeries > createView(
    std::shared_ptr< DigitalIntervalSeries const > const & source,
    std::unordered_set< EntityId > const & entity_ids
)

Create a view of this series filtered by EntityIds.

Parameters:

  • source Source series to create view from
  • entity_ids Set of EntityIds to include in the view

Return: Shared pointer to new view-based series

function createFromView

template <typename ViewType >
static std::shared_ptr< DigitalIntervalSeries > createFromView(
    ViewType view,
    size_t num_elements,
    std::shared_ptr< TimeFrame > time_frame =nullptr,
    IntervalLayout layout =IntervalLayout::Overlapping
)

Updated on 2026-11-13 at 20:25:41 +0000