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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT license.
*/
//! Distance layers indexing.
//!
//! An important assumption made by this module is that the data within each layer is
//! uniformly sized: each entry occupies the same number of bytes. Furthermore, the data
//! to be stored may not assume any particular alignment. Implementations will strive to
//! achieve a reasonable alignment, but this may not be relied on.
//!
//! # Query Distance Specialization
//!
//! The design of this module allows aggressive optimization of graph search kernels via
//! the [`Search`] and [`QueryVisitor`] pairs of traits.
//!
//! Implementations of [`Search`] can pass a [`QueryDistance`] kernel specialized to
//! a specific geometry (dimensionality or metric type) which upstream [`QueryVisitor`]
//! will fuse into larger kernels. While this allows for high performance graph kernels,
//! some considerations should be taken into account:
//!
//! 1. For correctness purposes, upstream callers cannot do any kind of caching. As such,
//! the dispatch layer used to select the kernel passed to the [`QueryVisitor`] should
//! be relatively efficient.
//!
//! 2. Keep the number of specializations bounded for compile time reasons.
use ANNResult;
use crateBytes;
pub use ;
/// Base layer for data representations.
/// Store an element of type `T` into a raw byte buffer.
///
/// Implementations may assume that `bytes.len()` is equal to [`Layer::bytes`].
/// A distance computation on raw byte slices.
///
/// When paired with [`Layer`] via helpers like [`AsDistance`], implementations may assume
/// that `x` and `y` have length [`Layer::bytes`].
///
/// No alignment guarantees are made for `x` and `y`, though in practice they are likely
/// to be aligned to 32 or 64 bytes.
/// Return a [`Distance`] function for a [`Layer`].
/// A unary query distance on raw byte slices.
///
/// When paired with [`Layer`] via helpers like [`Search`], implementations may assume
/// that `x` has length [`Layer::bytes`].
///
/// No alignment guarantees are made for `x`, though in practice it is likely to be
/// aligned to 32 or 64 bytes.
/// Enable search over vectors defined by a [`Layer`].