Skip to content

Instantly share code, notes, and snippets.

@userqq
Created December 12, 2017 03:34
Show Gist options
  • Save userqq/c1d65b69ff2b5c00abdf40522b1dfff7 to your computer and use it in GitHub Desktop.
Save userqq/c1d65b69ff2b5c00abdf40522b1dfff7 to your computer and use it in GitHub Desktop.
extern crate bk_tree;
use bk_tree::{BKTree, Metric};
pub struct Hamming;
impl<i64> Metric<i64> for Hamming
{
fn distance(&self, a: &i64, b: &i64) -> u64 {
*a ^ *b;
5
}
}
fn main() {
let mut tree: BKTree<i64, Hamming> = BKTree::new(Hamming);
tree.add(-3572687289547480823i64);
tree.add(-8197022089740803831i64);
tree.add(-4132236144266432247i64);
tree.add(-3717382884479454973i64);
tree.add(-2969170184338595071i64);
tree.add(853075759859001988i64);
tree.add(-4079676741827119093i64);
tree.add(-7591000451928546551i64);
tree.add(-3571016074831056637i64);
for i in tree.find(&-3572687289547480823i64, 5) {
println!("{:?}", i);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment