pub struct ProofTree {
pub root: ProofNode,
pub query: Term,
pub bindings: HashMap<String, Term>,
pub is_complete: bool,
}Expand description
A complete distributed proof tree for a top-level query.
After DistributedBackwardChainer::prove_with_tree returns, callers
inspect is_complete to know whether the goal was fully proved and
bindings to extract the final variable bindings.
Fields§
§root: ProofNodeRoot node of the tree.
query: TermThe top-level query term.
bindings: HashMap<String, Term>Final variable bindings produced by the proof search.
is_complete: booltrue when every node in the tree is resolved.
Implementations§
Source§impl ProofTree
impl ProofTree
Sourcepub fn new(
root: ProofNode,
query: Term,
bindings: HashMap<String, Term>,
) -> Self
pub fn new( root: ProofNode, query: Term, bindings: HashMap<String, Term>, ) -> Self
Construct a new proof tree.
Sourcepub fn failed(query: Term) -> Self
pub fn failed(query: Term) -> Self
Build an “empty” (failed) proof tree for a query that could not be proved.
Sourcepub fn contributing_peers(&self) -> Vec<String>
pub fn contributing_peers(&self) -> Vec<String>
All unique peer IDs that contributed to the proof.
Sourcepub fn prune_unresolved(&mut self)
pub fn prune_unresolved(&mut self)
Remove branches that did not contribute to a resolved proof.
Traverses the tree and prunes any subtree whose root node is not
resolved. After pruning, is_complete is re-derived from the root.
Only the shortest resolution path is kept for each unique set of bindings: when multiple resolved branches exist at the same level, the shallowest one (fewest total nodes) is retained.
Sourcepub fn collapse_chains(&mut self)
pub fn collapse_chains(&mut self)
Collapse relay chains where an intermediate node has exactly one child.
A chain A → B → C becomes A → C when B has a single child and carries no rule CID or peer attribution of its own. Depths are recomputed after collapsing to keep the tree consistent.
Sourcepub fn remote_contributions(&self) -> Vec<(&ProofNode, SocketAddr)>
pub fn remote_contributions(&self) -> Vec<(&ProofNode, SocketAddr)>
Return all proof nodes that were resolved by remote peers together with
a parsed std::net::SocketAddr.
The peer field is expected to contain an address in the form
"ip:port". Nodes whose peer string cannot be parsed as a
SocketAddr are silently omitted.
Sourcepub fn merge(&mut self, other: ProofTree)
pub fn merge(&mut self, other: ProofTree)
Merge other into self, keeping the deeper/more-complete subtree for
each branch.
When both trees have a resolved root the tree with more nodes (richer
derivation) wins. When only one is resolved that one wins. Bindings
from other are folded in for keys not already present in self.
Sourcepub fn to_stream(
&self,
session_id: impl Into<String>,
) -> (ProofTreeStreamer, UnboundedReceiver<ProofTreeUpdate>)
pub fn to_stream( &self, session_id: impl Into<String>, ) -> (ProofTreeStreamer, UnboundedReceiver<ProofTreeUpdate>)
Stream this tree as crate::proof_tree_streaming::ProofTreeUpdate events.
The method walks the tree in BFS order, emitting one update per node,
then emits a final update. Returns the crate::proof_tree_streaming::ProofTreeStreamer
that was used together with the receiving end of the channel so the
caller can consume updates asynchronously.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for ProofTree
impl<'de> Deserialize<'de> for ProofTree
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for ProofTree
impl RefUnwindSafe for ProofTree
impl Send for ProofTree
impl Sync for ProofTree
impl Unpin for ProofTree
impl UnsafeUnpin for ProofTree
impl UnwindSafe for ProofTree
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more