Let edge expansion terminate with the edge or the new child.
This commit is contained in:
parent
17105eafec
commit
f3f55f946e
@ -399,7 +399,9 @@ impl<'a, T, S, A> EdgeExpander<'a, T, S, A> where T: Hash + Eq + Clone + 'a, S:
|
||||
/// added for `state`, initialized with the data produced by `g`. A parent
|
||||
/// edge pointing back to the vertex that this edge originates from will
|
||||
/// also be added, with initial data the value returned by `h`.
|
||||
pub fn expand<G, H>(mut self, state: T, g: G, h: H) -> MutEdge<'a, T, S, A>
|
||||
///
|
||||
/// Returns an edge handle for the newly expanded edge.
|
||||
pub fn expand_to_edge<G, H>(mut self, state: T, g: G, h: H) -> MutEdge<'a, T, S, A>
|
||||
where G: FnOnce() -> S, H: FnOnce() -> A {
|
||||
let target_id = match self.graph.state_ids.get_or_insert(state) {
|
||||
NamespaceInsertion::Present(target_id) => target_id,
|
||||
@ -413,4 +415,22 @@ impl<'a, T, S, A> EdgeExpander<'a, T, S, A> where T: Hash + Eq + Clone + 'a, S:
|
||||
self.arc_mut().target = Target::Expanded(target_id);
|
||||
MutEdge { graph: self.graph, id: self.id, }
|
||||
}
|
||||
|
||||
/// Expands this expander's edge, by connecting to the vertex associated
|
||||
/// with the game state `state`.
|
||||
///
|
||||
/// If `state` does not correspond to an extant vertex, a new vertex will be
|
||||
/// added for `state`, initialized with the data produced by `g`. A parent
|
||||
/// edge pointing back to the vertex that this edge originates from will
|
||||
/// also be added, with initial data the value returned by `h`.
|
||||
///
|
||||
/// Returns a node handle for the newly expanded edge's target.
|
||||
pub fn expand_to_child<G, H>(self, state: T, g: G, h: H) -> MutNode<'a, T, S, A>
|
||||
where G: FnOnce() -> S, H: FnOnce() -> A {
|
||||
let edge = self.expand_to_edge(state, g, h);
|
||||
match edge.to_target() {
|
||||
Target::Expanded(n) => n,
|
||||
Target::Unexpanded(_) => panic!("Edge expansion failed"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user