Skip to main content

ChangeLog

Struct ChangeLog 

Source
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 = 0 and gets DataDelta::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) produces Full; 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

Source

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);
Source

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);
Source

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 }));
Source

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);
Source

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 }));

Trait Implementations§

Source§

impl Clone for ChangeLog

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ChangeLog

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ChangeLog

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.