Skip to content

Commit

Permalink
fix order diffing
Browse files Browse the repository at this point in the history
  • Loading branch information
chpio committed Mar 9, 2017
1 parent d043164 commit 7c07252
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions vtree/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "vtree"
version = "0.0.0"

[dependencies]
itertools = "0.5.9"
ordermap = "0.2.7"

[lib]
Expand Down
17 changes: 11 additions & 6 deletions vtree/src/child.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::convert::{From, Into};
use std::ops::Deref;
use key::Key;
use std::option::Option as StdOption;
use itertools::Itertools;

pub struct Single<G, AN>
where G: Into<AN>
Expand Down Expand Up @@ -156,18 +157,22 @@ impl<G, AN> Multi<G, AN>
-> impl Iterator<Item = (usize, usize)> + 'a {
let curr_it = self.nodes
.keys()
.filter(move |key| last.nodes.contains_key(key));
.enumerate()
.filter(move |&(_, k)| !last.nodes.contains_key(k));

let last_it = last.nodes
.keys()
.enumerate()
.filter(move |&(_, key)| self.nodes.contains_key(key));
.filter(move |k| self.nodes.contains_key(k))
.enumerate();

curr_it
.zip(last_it)
.filter(|&(ref c_key, (_, ref l_key))| c_key != l_key)
.map(move |(_, (l_index, l_key))| {
.merge_by(last_it, |a, b| a.0 <= b.0)
.enumerate()
.map(move |(l_index, (_, l_key))| {
let c_index = self.nodes.get_pair_index(l_key).unwrap().0;
(c_index, l_index)
})
.filter(|&(c_i, l_i)| c_i != l_i)
}
}

Expand Down
1 change: 1 addition & 0 deletions vtree/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![feature(conservative_impl_trait)]

extern crate ordermap;
extern crate itertools;

pub mod diff;
pub mod key;
Expand Down

0 comments on commit 7c07252

Please sign in to comment.