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
//! Serialized HNSW graph links: build, store, parse, and read.
//!
//! # Structures and relations
//!
//! ```text
//! BUILD (write path) LOAD (read path)
//!
//! Vec<Vec<Vec<edges>>> fs: impl UniversalReadFs
//! │ │
//! │ + GraphLinksFormatParam (format.rs) │ GraphLinks::load_universal
//! │ ├─ Plain / Compressed │ opens the file and keeps
//! │ └─ CompressedWithVectors │ the handle alive
//! │ └─ &dyn GraphLinksVectors │
//! ▼ (vectors.rs) │
//! serialize_graph_links ──────────────┐ │
//! (serializer.rs) │ │
//! │ writes bytes via `header` │ │
//! ▼ ▼ ▼
//! ┌───────────────────────────────────────────────────────────────────────┐
//! │ GraphLinks (links.rs) — public handle, a self_cell of: │
//! │ │
//! │ owner: GraphLinksEnum (storage.rs) dependent: GraphLinksView<'_> │
//! │ ├─ Ram(Vec<u8>) (view.rs) │
//! │ └─ Universal( zero-copy parse that BORROWS │
//! │ Box<dyn GraphLinksStorage>) the owner's bytes; every │
//! │ ▲ erases an `S: UniversalRead` read accessor │
//! │ │ file handle (mmap, io_uring, …) (links / │
//! │ │ point_level / …) reads │
//! │ │ through the view, so the │
//! │ │ search hot path does no │
//! │ │ dynamic dispatch. │
//! └───────────────────────────────────────────────────────────────────────┘
//! ```
//!
//! | file | responsibility |
//! |----------------|----------------------------------------------------------------------|
//! | [`links`] | [`GraphLinks`] — public handle pairing owned bytes with a parsed view |
//! | [`storage`] | `GraphLinksEnum` + `GraphLinksStorage`: RAM vs. universal-IO backing |
//! | [`view`] | `GraphLinksView` — zero-copy parser/accessor over the bytes |
//! | [`serializer`] | [`serialize_graph_links`] — edges → serialized bytes |
//! | [`header`] | on-disk header structs shared by the serializer and the view |
//! | [`format`] | [`GraphLinksFormat`] / [`GraphLinksFormatParam`] format selectors |
//! | [`vectors`] | [`GraphLinksVectors`] & friends: inline vectors for `CompressedWithVectors` |
//!
//! # Serialized layout
//!
//! ```text
//! sorted
//! points: points:
//! points to lvl 012345 142350
//! 0 -> 0
//! 1 -> 4 lvl4: 7 lvl4: 7
//! 2 -> 2 lvl3: Z Y lvl3: ZY
//! 3 -> 2 lvl2: abcd lvl2: adbc
//! 4 -> 3 lvl1: ABCDE lvl1: ADBCE
//! 5 -> 1 lvl0: 123456 lvl0: 123456 <- lvl 0 is not sorted
//!
//!
//! lvl offset: 6 11 15 17
//! │ │ │ │
//! │ │ │ │
//! ▼ ▼ ▼ ▼
//! indexes: 012345 6789A BCDE FG H
//!
//! flatten: 123456 ADBCE adbc ZY 7
//! ▲ ▲ ▲ ▲ ▲ ▲ ▲
//! │ │ │ │ │ │ │
//! │ │ │ │ │ │ │
//! │ │ │ │ │ │ │
//! reindex: 142350 142350 142350 142350 (same for each level)
//!
//!
//! for lvl > 0:
//! links offset = level_offsets[level] + offsets[reindex[point_id]]
//! ```
pub use ;
pub use ;
pub use serialize_graph_links;
pub use ;
pub use LinksIterator;
/// Sort the first `m` values in `links` and return them. Used to compare stored
/// links where the order of the first `m` links is not preserved.
pub