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
//! [`Visitor`] trait used by
//! [`crate::tree::RandomCutTree::traverse`] to dispatch per-node
//! callbacks during a root→leaf walk, plus the two production
//! visitors:
//!
//! - [`scalar_score::ScalarScoreVisitor`] — collusive-displacement
//! anomaly scoring per Guha et al. (2016) §3.
//! - [`attribution::AttributionVisitor`] — per-feature
//! [`crate::DiVector`] attribution exposing which dimensions drove
//! the score.
use crate;
pub use AttributionVisitor;
pub use ScoreAttributionVisitor;
pub use ScalarScoreVisitor;
/// Trait implemented by anyone observing a root→leaf traversal of a
/// [`crate::tree::RandomCutTree`].
///
/// `D` is the per-point dimensionality of the tree being walked. The
/// trait is generic over `D` so the cached bounding boxes can be
/// passed in as `&BoundingBox<D>` without erasing their compile-time
/// dimensionality.
///
/// The visitor receives one callback per visited internal node and a
/// final callback when the matching leaf is reached. After the walk
/// completes, [`Visitor::result`] consumes the visitor and returns
/// the accumulated output.
///
/// # Contract
///
/// - `accept_internal` is called once per ancestor on the path from
/// the root to the leaf, in root→leaf order.
/// - `accept_leaf` is called exactly once, on the leaf where the walk
/// stops.
/// - `result` is called exactly once, after the traversal finishes.
///
/// # Examples
///
/// ```
/// use anomstream_core::{ScalarScoreVisitor, Visitor};
/// // `ScalarScoreVisitor` implements `Visitor<D>` for any `D`.
/// let v: ScalarScoreVisitor = ScalarScoreVisitor::new(8);
/// assert_eq!(v.total_mass(), 8);
/// ```