~dkellner/chronofold

9942ab8e6d687434cc0a223688d34ba857c71690 — Dominik Kellner 4 months ago 9be9962
Fix `iter_newer_ops`, remove incorrect optimization for now
2 files changed, 17 insertions(+), 2 deletions(-)

M src/version.rs
M tests/version.rs
M src/version.rs => src/version.rs +3 -2
@@ 78,8 78,9 @@ impl<A: Author, T: Clone> Chronofold<A, T> {
        &'a self,
        version: &'a Version<A>,
    ) -> impl Iterator<Item = Op<A, T>> + 'a {
        let lower_bound = version.log_indices.values().min().unwrap_or(&LogIndex(0));
        self.iter_ops(lower_bound..)
        // TODO: Don't iterate over all ops in cases where that is not
        // necessary.
        self.iter_ops(..)
            .filter(move |op| match version.log_indices.get(&op.id.1) {
                None => true,
                Some(idx) => op.id.0 > *idx,

M tests/version.rs => tests/version.rs +14 -0
@@ 22,6 22,7 @@ fn iter_newer_ops() {
    let v1 = cfold.version().clone();
    cfold.session(1).push_back('!');
    cfold.session(2).push_back('?');

    assert_eq!(
        vec![
            Op::new(t(3, 1), Some(t(2, 1)), Change::Insert('!')),


@@ 29,6 30,19 @@ fn iter_newer_ops() {
        ],
        cfold.iter_newer_ops(&v1).collect::<Vec<Op<u8, char>>>()
    );

    let mut v2 = Version::new();
    v2.inc(&Timestamp(LogIndex(1), 3));
    assert_eq!(
        vec![
            Op::new(t(0, 1), None, Change::Insert('f')),
            Op::new(t(1, 1), Some(t(0, 1)), Change::Insert('o')),
            Op::new(t(2, 1), Some(t(1, 1)), Change::Insert('o')),
            Op::new(t(3, 1), Some(t(2, 1)), Change::Insert('!')),
            Op::new(t(4, 2), Some(t(3, 1)), Change::Insert('?'))
        ],
        cfold.iter_newer_ops(&v2).collect::<Vec<_>>()
    );
}

fn t(log_index: usize, author: u8) -> Timestamp<u8> {