~dkellner/chronofold

b086ae94c083f3e85ba07fd58d0d00973fb62be6 — Dominik Kellner 9 months ago f22a412
Add `Chronofold::empty` to create chronofolds with empty logs
2 files changed, 13 insertions(+), 1 deletions(-)

M src/iter.rs
M src/lib.rs
M src/iter.rs => src/iter.rs +1 -1
@@ 116,7 116,7 @@ impl<'a, A: Author, T> Iterator for CausalIter<'a, A, T> {
        match self.current.take() {
            Some(current) if Some(current) != self.first_excluded => {
                self.current = self.cfold.index_after(current);
                let (change, deleted) = &self.cfold.log[current.0];
                let (change, deleted) = &self.cfold.log.get(current.0)?;
                Some((change, current, *deleted))
            }
            _ => None,

M src/lib.rs => src/lib.rs +12 -0
@@ 177,6 177,18 @@ impl<A: Author, T> Chronofold<A, T> {
        }
    }

    pub fn empty() -> Self {
        Self {
            log: vec![],
            root: LogIndex(0),
            version: Version::default(),
            next_indices: OffsetMap::default(),
            authors: RangeFromMap::default(),
            index_shifts: RangeFromMap::default(),
            references: OffsetMap::default(),
        }
    }

    /// Returns `true` if the chronofold contains no elements.
    pub fn is_empty(&self) -> bool {
        self.len() == 0