pub struct ChangeLog { /* private fields */ }Expand description
Generation counter plus a fixed-size log of changed logical index spans.
- Generations start at 1, so a consumer that has never synced asks with
since_gen = 0and getsDataDelta::Full. - A change whose span intersects or touches the newest entry is folded into it, so a stream of ticks and appends at the end of a series occupies one entry.
- When all 64 entries are used, the two oldest are merged into their hull. Results only get more conservative, never wrong.
- Only a
Replace(or never having synced) producesFull; staying away for a long time does not.
Recording and querying never allocate (the log is a fixed array), so this is
safe on the update_last hot path.
§Examples
use ferrochart_core::data::{ChangeLog, DataDelta, IdxSpan};
let mut log = ChangeLog::new();
let renderer_a = log.generation();
log.record(IdxSpan { start: 100, end: 101 }); // tick on the last bar
let renderer_b = log.generation();
log.record(IdxSpan { start: 101, end: 103 }); // two bars appended
assert_eq!(log.changes_since(renderer_a), DataDelta::Range(IdxSpan { start: 100, end: 103 }));
assert_eq!(log.changes_since(0), DataDelta::Full); // never synced
log.replace();
assert_eq!(log.changes_since(renderer_b), DataDelta::Full);Implementations§
Source§impl ChangeLog
impl ChangeLog
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates a log at generation 1 with no recorded changes.
§Examples
use ferrochart_core::data::ChangeLog;
assert_eq!(ChangeLog::new().generation(), 1);Sourcepub fn generation(&self) -> u64
pub fn generation(&self) -> u64
Current generation. Increases by one on every recorded change.
§Examples
use ferrochart_core::data::{ChangeLog, IdxSpan};
let mut log = ChangeLog::new();
log.record(IdxSpan { start: 0, end: 1 });
assert_eq!(log.generation(), 2);Sourcepub fn record(&mut self, span: IdxSpan) -> u64
pub fn record(&mut self, span: IdxSpan) -> u64
Records that the slots in span changed (Append, UpdateLast,
Prepend) and returns the new generation. An empty span still advances
the generation but logs nothing.
§Examples
use ferrochart_core::data::{ChangeLog, DataDelta, IdxSpan};
let mut log = ChangeLog::new();
for _ in 0..1000 {
log.record(IdxSpan { start: 41, end: 42 }); // 1000 ticks on one bar
}
assert_eq!(log.changes_since(1), DataDelta::Range(IdxSpan { start: 41, end: 42 }));Sourcepub fn replace(&mut self) -> u64
pub fn replace(&mut self) -> u64
Records a Replace: everything changed. Consumers synced to an earlier
generation get DataDelta::Full. Returns the new generation.
§Examples
use ferrochart_core::data::{ChangeLog, DataDelta};
let mut log = ChangeLog::new();
let synced = log.replace();
assert_eq!(log.changes_since(synced), DataDelta::None);
assert_eq!(log.changes_since(synced - 1), DataDelta::Full);Sourcepub fn changes_since(&self, since_gen: u64) -> DataDelta
pub fn changes_since(&self, since_gen: u64) -> DataDelta
What changed after generation since_gen. O(64), no allocation.
Returns DataDelta::Full if since_gen is older than the last Replace
(or the creation), or newer than the current generation (an invalid value,
treated conservatively).
§Examples
use ferrochart_core::data::{ChangeLog, DataDelta, IdxSpan};
let mut log = ChangeLog::new();
log.record(IdxSpan { start: 0, end: 10 });
log.record(IdxSpan { start: 50, end: 60 });
assert_eq!(log.changes_since(1), DataDelta::Range(IdxSpan { start: 0, end: 60 }));
assert_eq!(log.changes_since(2), DataDelta::Range(IdxSpan { start: 50, end: 60 }));