Skip to content

Commit

Permalink
keep doing it inplace...
Browse files Browse the repository at this point in the history
  • Loading branch information
luizirber committed Aug 10, 2020
1 parent 8e126a9 commit c119765
Showing 1 changed file with 26 additions and 29 deletions.
55 changes: 26 additions & 29 deletions src/core/src/sketch/nodegraph.rs
Expand Up @@ -303,40 +303,37 @@ impl Comparable<&Nodegraph> for Nodegraph {

impl Comparable<Nodegraph> for Nodegraph {
fn similarity(&self, other: &Nodegraph) -> f64 {
intersection_size(&self, &other) as f64 / union_size(&self, &other) as f64
}

fn containment(&self, other: &Nodegraph) -> f64 {
intersection_size(&self, &other) as f64 / self.occupied_bins as f64
}
}
let mut intersection = 0;
let mut union = 0;

fn intersection_size(me: &Nodegraph, other: &Nodegraph) -> usize {
me.bs
.iter()
.zip(&other.bs)
.map(|(bs, bs_other)| {
self.bs.iter().zip(&other.bs).for_each(|(bs, bs_other)| {
bs.as_slice()
.iter()
.zip(bs_other.as_slice().iter())
.map(|(x, y)| (x & y).count_ones() as usize)
.sum::<usize>()
})
.sum()
}
.for_each(|(x, y)| {
intersection += (x & y).count_ones() as usize;
union += (x | y).count_ones() as usize;
});
});
intersection as f64 / union as f64
}

fn union_size(me: &Nodegraph, other: &Nodegraph) -> usize {
me.bs
.iter()
.zip(&other.bs)
.map(|(bs, bs_other)| {
bs.as_slice()
.iter()
.zip(bs_other.as_slice().iter())
.map(|(x, y)| (x | y).count_ones() as usize)
.sum::<usize>()
})
.sum()
fn containment(&self, other: &Nodegraph) -> f64 {
let intersection: usize = self
.bs
.iter()
.zip(&other.bs)
.map(|(bs, bs_other)| {
bs.as_slice()
.iter()
.zip(bs_other.as_slice().iter())
.map(|(x, y)| (x & y).count_ones() as usize)
.sum::<usize>()
})
.sum();

intersection as f64 / self.occupied_bins as f64
}
}

impl Comparable<KmerMinHash> for Nodegraph {
Expand Down

0 comments on commit c119765

Please sign in to comment.