TimeLane
- class caqtus.types.timelane.TimeLane(values: Iterable)
Bases:
MutableSequence,ABC,GenericRepresents a sequence of values covering some steps in time.
A time lane is a sequence of values that are associated with some time steps. The time steps are not explicitly stored in the lane. Instead, for a given lane, lane[i] is the value of the lane at the i-th step.
Consecutive identical values in a lane can be grouped in a single block spanning multiple steps.
TimeLane is an abstract class, generic over the type of values it contains. It provides common methods such as value access, insertion, and deletion.
- spanned_values() Sequence[tuple[T, Span]]
Returns the spanned values of the lane.
For each block in the lane, returns a tuple of two elements: the value of the block and the number of steps spanned by the block.
Examples
>>> from caqtus.types.timelane import DigitalTimeLane >>> lane = DigitalTimeLane([True, True, False, True]) >>> lane.spanned_values() [(True, 2), (False, 1), (True, 1)]
- get_bounds(
- step: Step,
Returns the bounds of the block containing the given step.
- block_values() Iterator
Returns an iterator over the block values.
The length of the iterator is the number of blocks in the lane, not the number of steps.
- block_bounds() Iterator[tuple[Step, Step]]
Iterates over the bounds of the blocks.
- Returns:
An iterator over the bounds of the blocks.
Its elements are tuples of two elements: the step (inclusive) at which the block starts and the step (exclusive) at which the block ends.
The length of the iterator is the number of blocks in the lane.
- get_block_bounds(
- block: Block,
Returns the bounds of the given block.
- Returns:
the step (inclusive) at which the block starts and the step (exclusive) at which the block ends.
- Return type:
A tuple of two elements
- Raises:
IndexError – If the block index is out of bounds.
- get_block_value(block: Block) T
Returns the value of the given block.
- delete_step(step: Step) None
Delete a single step from the lane.
The length of the lane is always exactly one less after this operation.
- insert(*args, **kwargs)
S.insert(index, value) – insert value before index