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
87
88
89
90
91
92
93
94
95
96
97
//! Similarity hashes of images and text that stay the same once stored: each algorithm is a
//! written, versioned definition whose output never changes.
//!
//! A plain Rust library with no framework dependency. It computes a [`Hash`](struct@Hash),
//! compares two with [`Hash::distance`], and splits one into [`Hash::chunks`], index keys for
//! finding near matches in a database.
//!
//! - Images: [`average_v1`], [`difference_v1`] and [`perceptual_v1`] hash a [`Luma`] image, an
//! 8-bit greyscale view; [`LumaBuf::from_rgb8_v1`] converts RGB. [`pdq_v1`], Meta's PDQ, and
//! [`blockhash_v1`] hash an [`Rgba`] image into 256 bits; [`RgbaBuf::from_rgb8`] makes one from
//! RGB. With the `image` feature, [`decode_luma_v1`], [`decode_rgba_v1`] and
//! [`Algorithm::hash_encoded`] read PNG and JPEG files.
//! - Text: [`simhash_v1`] hashes weighted features, such as the words from [`words_v1`] or the
//! shingles from [`shingles_v1`].
//! - Sets: [`minhash_v1`] makes a [`Signature`], 128 values that estimate how much two sets of
//! features overlap, with [`Signature::band_keys`] to find probable near matches;
//! [`minhash_v1_shingles`] makes one from the shingles of a text. [`minhash_legacy_v1`] and
//! [`minhash_legacy_v1_shingles`] make the signatures datasketch made by default before its
//! version 2.0.0, to agree with those.
//!
//! ```
//! use legit_hashes::{Hash, Luma, perceptual_v1, simhash_v1, words_v1};
//!
//! let pixels: Vec<u8> = (0..64 * 48).map(|i| (i % 64 * 4) as u8).collect();
//! let image = perceptual_v1(Luma::new(64, 48, &pixels)?);
//!
//! let text = simhash_v1(words_v1("A plain Rust library").map(|word| (word, 1)));
//!
//! // Store the string form; it names the algorithm and its version...
//! let stored = image.to_string();
//! assert!(stored.starts_with("perceptual-v1:"));
//! assert_eq!(stored.parse::<Hash>()?.distance(&image)?, 0);
//!
//! // ...and hashes of different algorithms don't compare.
//! assert!(image.distance(&text).is_err());
//! # Ok::<(), legit_hashes::Error>(())
//! ```
//!
//! Every hashing function and [`Algorithm`] variant names its version. A released definition never
//! changes its output; a change ships as a new version beside the old one. Nothing is called
//! "latest" or "default", so upgrading the crate never changes what an application stores.
//!
//! Features:
//!
//! - `image`: [`decode_luma_v1`], [`decode_rgba_v1`] and [`Algorithm::hash_encoded`], decoding PNG
//! and JPEG with the `image` crate.
//! - `serde`: `Serialize` and `Deserialize` for [`Hash`](struct@Hash), [`Algorithm`],
//! [`Signature`] and [`SignatureAlgorithm`], as their string forms.
pub use Algorithm;
pub use blockhash_v1;
pub use ;
pub use ;
pub use Hash;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use perceptual_v1;
pub use ;
pub use ;
pub use ;
/// The README's examples, compiled and run as doctests. One reads a file, so they need `image`.
;