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
use ;
use crateTreeNode;
use functional;
/// Trait defining the interface for tree traversal algorithms.
/// This trait is an alias for `FusedIterator` over tree nodes.
/// Traverses the tree using the provided traversal iterator, collecting the best leaf nodes.
///
/// This function wraps the functional `traverse` with default leaf and cost functions based on the `TreeNode` trait.
/// It accepts a `callback` parameter that is invoked for every visited node as `callback(index, &node)` and can be
/// used for progress reporting, logging, or side-effects.
///
/// # Parameters
/// - `traversal`: A mutable reference to a traversal iterator.
/// - `max_ops`: The maximum number of nodes to process.
/// - `time_limit`: The maximum time allowed for the traversal.
/// - `queue_size`: The maximum number of best nodes to return.
/// - `callback`: A mutable callback invoked as `callback(n_step, &node)` for each visited node.
///
/// # Returns
/// A vector of tuples containing the cost and the node
/// Finds the best leaf node in the tree using the provided traversal iterator.
///
/// This function wraps `traverse` to return only the single best node. It accepts a `callback` parameter which is
/// invoked for every visited node and can be used to track progress or gather diagnostics.
///
/// # Parameters
/// - `traversal`: A mutable reference to a traversal iterator.
/// - `max_ops`: The maximum number of nodes to process.
/// - `time_limit`: The maximum time allowed for the traversal.
/// - `callback`: A mutable callback invoked as `callback(n_step, &node)` for each visited node.
///
/// # Returns
/// The best leaf node and its cost, or `None` if no leaf is found.