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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//! Exact Hamming radius search over 64-bit and 256-bit hashes held in memory: every stored record
//! within distance `d` of a query, with its distance, and never a match missed.
//!
//! A plain Rust library with no framework dependency. A set of [`Records`] holds fixed-width
//! values, `u64` or `[u64; 4]`, each with an application's 64-bit id or without. Several variants
//! search it behind one trait, [`Search`], and every one returns exactly the matches of the plainest
//! of them:
//!
//! - [`Planned`]: the one to use. It owns the records and, within a memory budget, multi-index
//! tables over them, and answers each query by a scan or a probe of the tables, whichever its
//! estimate says costs less;
//! - [`Scan`]: a flat scan on a code path chosen at run time from what the CPU has ([`Isa`]):
//! `popcnt`, AVX2, AVX-512 or NEON;
//! - [`MultiIndex`]: multi-index hashing with tables of 16-bit chunks, sized from the guarantee
//! `m(r + 1) − 1`;
//! - [`Reference`]: the plainest scan, which every other variant is checked against;
//! - [`Mapped`]: a [snapshot] file searched in place, mapped into memory.
//!
//! [`search`] and [`search_batch`] run one, on as many threads as asked, and return [`Found`]
//! lists sorted by distance and then id, or position for a set without ids. A caller's limit keeps
//! the nearest matches, never the first found, a result says when anything cut it short, and
//! [`Found::plan`] says how a planned query ran. [`neighbour_table`] measures how many records sit
//! at each distance from a typical one.
//!
//! ```
//! use std::sync::Arc;
//!
//! use legit_hamming::{Options, Planned, Records, search};
//!
//! let records = Records::from_records([(1, 0b1011u64), (2, 0b1000), (5, u64::MAX)])?;
//! let index = Planned::new(Arc::new(records), 64 << 20, 1);
//!
//! let found = search(&index, 0b1001, &Options::new(1));
//! let ids: Vec<_> = found.matches.iter().map(|m| (m.id, m.distance)).collect();
//! assert_eq!(ids, [(Some(1), 1), (Some(2), 1)]);
//! assert!(found.is_complete());
//! # Ok::<(), legit_hamming::Error>(())
//! ```
//!
//! The [`service`] module puts named indexes and subsets loaded from snapshot directories behind
//! a search service, for the `legit-hamming` program's `query` command and, with the
//! `serve` feature, its `serve` worker on Redis Streams, in the `serve` module.
//!
//! `unsafe` code is confined to the vector kernels, behind a safe wrapper that checks the CPU at
//! run time and falls back to the scalar path, and the memory map, whose constructors are `unsafe
//! fn`s: a map is sound only while no process changes its files, which the caller promises. Every
//! other path, the service and the `verify` command included, reads files into memory it owns; the
//! rest of the crate denies `unsafe`.
pub use ;
pub use ;
pub use Hit;
pub use ;
pub use ;
pub use ;
pub use Planned;
pub use Records;
pub use ;
pub use ;
pub use Value;
/// The README's examples, run as tests.
;