1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! # minhash-lsh
//! [](https://github.com/schelterlabs/rust-minhash/actions/workflows/build.yml)
//!
//! This crate reimplements the `MinHash` and `MinHash LSH` approaches from the Python package [datasketch](https://github.com/ekzhu/datasketch) in Rust. It's only a partial reimplementation, use it at your own risk.
//!
//! ## Example MinHash
//!
//! ```rust
//! use datasketch_minhash_lsh::MinHash;
//!
//! let mut m1 = <MinHash>::new(4, Some(1));
//! let mut m2 = <MinHash>::new(4, Some(1));
//! assert_eq!(m1.jaccard(&m2).unwrap(), 1.0);
//!
//! m2.update(&12);
//! assert_eq!(m1.jaccard(&m2).unwrap(), 0.0);
//!
//! m1.update(&13);
//! assert!(m1.jaccard(&m2).unwrap() < 1.0);
//!
//! m1.update(&12);
//! let distance = m1.jaccard(&m2).unwrap();
//! assert!(distance < 1.0 && distance > 0.0);
//! ```
//! ## Example MinHashLsh
//!
//! ```rust
//! use datasketch_minhash_lsh::{MinHashLsh, MinHash};
//!
//! let mut lsh = <MinHashLsh<&str>>::new(16, None, Some(0.5)).unwrap();
//! let mut m1 = <MinHash>::new(16, Some(0));
//! m1.update(&"a");
//!
//! let mut m2 = <MinHash>::new(16, Some(0));
//! m2.update(&"b");
//!
//! lsh.insert("a", &m1).unwrap();
//! lsh.insert("b", &m2).unwrap();
//!
//! let result = lsh.query(&m1).unwrap();
//! assert!(result.contains(&"a"));
//!
//! let result = lsh.query(&m2).unwrap();
//! assert!(result.contains(&"b"));
//! assert!(result.len() <= 2);
//! ```
//!
use SmallRng;
use ;
pub use crate*;
pub use crate*;