-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathextractor.rs
More file actions
54 lines (46 loc) · 1.82 KB
/
extractor.rs
File metadata and controls
54 lines (46 loc) · 1.82 KB
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
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors
use crate::DynArray;
/// Context threaded through tree traversal for percentage calculations etc.
pub struct TreeContext {
/// Stack of ancestor nbytes values. `None` entries reset the percentage root
/// (e.g. for chunked arrays where each chunk is its own root).
pub(crate) ancestor_sizes: Vec<Option<u64>>,
}
impl TreeContext {
pub(crate) fn new() -> Self {
Self {
ancestor_sizes: Vec::new(),
}
}
/// The total size used as the denominator for percentage calculations.
/// Returns `None` if there is no ancestor (i.e., this node is the root or
/// a chunk boundary reset the percentage root).
pub fn parent_total_size(&self) -> Option<u64> {
self.ancestor_sizes.last().cloned().flatten()
}
pub(crate) fn push(&mut self, size: Option<u64>) {
self.ancestor_sizes.push(size);
}
pub(crate) fn pop(&mut self) {
self.ancestor_sizes.pop();
}
}
/// Trait for contributing display information to tree nodes.
///
/// Each extractor represents one "dimension" of display (e.g., nbytes, stats, metadata, buffers).
/// Extractors are composable: you can combine any number of them via [`TreeDisplay::with`].
///
/// [`TreeDisplay::with`]: super::TreeDisplay::with
pub trait TreeExtractor: Send + Sync {
/// Annotations appended to the header line (e.g., `nbytes=10 B (100.00%)`).
fn header_annotations(&self, array: &dyn DynArray, ctx: &TreeContext) -> Vec<String> {
let _ = (array, ctx);
vec![]
}
/// Additional detail lines shown below the header (e.g., `metadata: EmptyMetadata`).
fn detail_lines(&self, array: &dyn DynArray, ctx: &TreeContext) -> Vec<String> {
let _ = (array, ctx);
vec![]
}
}