Skip to content

Commit 1bfe320

Browse files
committed
Override side impl for Hamming
Using provided implementation randomly selects a side if the margin_no_header is 0. Override side impl for Hamming Using provided implementation randomly selects a side if the margin_no_header is 0.
1 parent 870fa98 commit 1bfe320

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/distance/hamming.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::distance::Distance;
2+
use crate::internals::Side;
23
use crate::node::Leaf;
34
use crate::parallel::ImmutableSubsetLeafs;
45
use crate::unaligned_vector::{Binary, UnalignedVector};
@@ -107,6 +108,19 @@ impl Distance for Hamming {
107108
p.as_bytes().iter().zip(q.as_bytes()).map(|(u, v)| (u & v).count_ones()).sum::<u32>();
108109
ret as f32
109110
}
111+
112+
fn side<R: Rng>(
113+
normal_plane: &UnalignedVector<Self::VectorCodec>,
114+
node: &Leaf<Self>,
115+
_rng: &mut R,
116+
) -> Side {
117+
let dot = Self::margin_no_header(&node.vector, normal_plane);
118+
if dot > 0.0 {
119+
Side::Right
120+
} else {
121+
Side::Left
122+
}
123+
}
110124
}
111125

112126
#[inline]

0 commit comments

Comments
 (0)