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
128
129
130
131
132
133
134
//! Read-only structural storage accounting for HDT.
//!
//! Vector capacities measure requested buffer storage, not allocator usable size.
//! Payload byte values count live keys and values of the ordered (B-tree) and
//! hashed containers, and exclude B-tree spare slots, node metadata and hash
//! table overhead. Neither value is total heap usage or RSS; allocator overhead
//! and the snapshot are excluded.
/// Structural storage snapshot of an [`crate::HdtGraph`], from
/// [`crate::HdtGraph::storage_stats`], collected outside timed graph
/// operations.
///
/// A stable interface of the experimental HDT engine
/// ([`crate::EngineConfig::Hdt`]). The struct is exhaustive: its eight public
/// fields are frozen for 1.x, and a new field requires a major release.
///
/// # Guaranteed
///
/// For a snapshot `s` of a graph `g`, computed at the call:
///
/// - `s.vertex_count == g.node_count()` and `s.edge_count == g.edge_count()`.
/// - Every `*_bytes` field is in bytes; `vertex_count`, `edge_count`,
/// `available_levels` and the per-level counts are plain counts.
/// - `s.vector_capacity_bytes` is the sum of `s.level_capacity_bytes`,
/// `s.edge_arc_capacity_bytes` and, for every level, its
/// `token_capacity_bytes`, `vertex_index_capacity_bytes`,
/// `free_list_capacity_bytes`, `adjacency_capacity_bytes` and
/// `mapping_capacity_bytes`.
/// - `s.levels` is empty exactly when `s.vertex_count == 0`, and
/// `s.levels[i].level == i` for every index `i` (ascending, from level 0).
/// - `s.available_levels == 0` exactly when `s.vertex_count == 0`, and
/// `s.levels.len() <= s.available_levels`. Since vertices are never
/// removed, `available_levels` never decreases for one graph.
/// - Level 0 holds a spanning forest of the whole graph:
/// `s.levels[0].tree_edges` equals `vertex_count` minus the number of
/// connected components, and `tree_edges` does not increase from one level
/// to the next (each level's forest contains the next one's).
/// - Each edge has exactly one level, where it is counted at both endpoints:
/// the sum over all levels of `tree_incidences + non_tree_incidences` is
/// `2 * s.edge_count`, and the sum of `tree_incidences` is
/// `2 * s.levels[0].tree_edges`.
///
/// # Implementation-dependent
///
/// Every capacity and payload byte value, the number of materialized levels,
/// the per-level `vertices` record slots, which edges are tree edges at which
/// level, and the exact `available_levels` beyond the properties above depend
/// on the implementation, the operation history and the standard library's
/// growth policy, and may change in any release. Capacities retain their
/// peaks after removals. None of the values is total heap usage or RSS:
/// allocator overhead, hash table and B-tree overhead and the snapshot itself
/// are excluded.
///
/// # Examples
///
/// ```
/// use knotrel_core::HdtGraph;
///
/// let mut graph = HdtGraph::new();
/// graph.link(1, 2)?;
/// graph.link(2, 3)?;
/// graph.link(3, 1)?;
/// graph.add_node(4);
/// let storage = graph.storage_stats();
/// assert_eq!(storage.vertex_count, 4);
/// assert_eq!(storage.edge_count, 3);
/// // Four vertices in two components: a spanning forest of two edges.
/// assert_eq!(storage.levels[0].tree_edges, 2);
/// let incidences: usize = storage
/// .levels
/// .iter()
/// .map(|level| level.tree_incidences + level.non_tree_incidences)
/// .sum();
/// assert_eq!(incidences, 2 * storage.edge_count);
/// # Ok::<(), knotrel_core::GraphError>(())
/// ```
/// Storage and live incidences of one materialized HDT level, an element of
/// [`HdtStorageStats::levels`].
///
/// A stable interface of the experimental HDT engine; the struct is
/// exhaustive, so its eleven public fields are frozen for 1.x. The properties
/// that relate these fields to each other and to the graph are guaranteed as
/// listed on [`HdtStorageStats`]; every byte value and `vertices` are
/// implementation-dependent. `Default` gives an all-zero value.