@dirtytalk/ranges
v0.0.2
Published
A canonical, disjoint, half-open interval set (`[start, end)`) for describing changed byte ranges, row spans or time windows, plus an `IntervalSpace` adapter that plugs it into `@dirtytalk/engine`'s `DirtyChannel`.
Maintainers
Readme
@dirtytalk/ranges
A canonical, disjoint, half-open interval set ([start, end)) for describing changed byte ranges, row spans or time windows, plus an IntervalSpace adapter that plugs it into @dirtytalk/engine's DirtyChannel.
Unlike a single bounding range, it keeps the gaps between changes: edits at bytes [0, 4) and [9999996, 10000000) stay two spans, so uploads, repaints and writes scale with what changed. Use it for partial GPU buffer or texture uploads, changed rows in virtualized lists and tables, edited timeline windows, or dirty chunks of a large buffer.
import { IntervalSet, IntervalSpace } from '@dirtytalk/ranges';
import { DirtyChannel, MicrotaskScheduler } from '@dirtytalk/engine';
const channel = new DirtyChannel(IntervalSpace, new MicrotaskScheduler());
channel.subscribe(
() => IntervalSet.from([{ start: 0, end: 1024 }]),
(dirty) => upload(dirty.spans()),
);
channel.mark(IntervalSet.from([{ start: 100, end: 104 }]));
channel.mark(IntervalSet.from([{ start: 900, end: 904 }]));
// flush: upload([{ start: 100, end: 104 }, { start: 900, end: 904 }])A burst of N marks in one flush window costs O(N log N). It is a dirty-tracking primitive, not an edit history: shifts caused by inserts or deletes are the producer's concern, and alignment or gap bridging before doing the work is the consumer's.
