Hit it with the cargo fmt
bat.
This commit is contained in:
parent
d627b8b964
commit
1fcff8f4eb
11
src/lib.rs
11
src/lib.rs
@ -132,14 +132,21 @@ impl<T: Hash + Eq + Clone, S, A> Graph<T, S, A> {
|
||||
///
|
||||
/// If `state` does not correspond to a known game state, returns `None`.
|
||||
pub fn find_node<'s>(&'s self, state: &T) -> Option<nav::Node<'s, T, S, A>> {
|
||||
self.state_ids.get(state).map(|symbol| nav::Node::new(self, *symbol.id()))
|
||||
self
|
||||
.state_ids
|
||||
.get(state)
|
||||
.map(|symbol| nav::Node::new(self, *symbol.id()))
|
||||
}
|
||||
|
||||
/// Gets a mutable node handle for the given game state.
|
||||
///
|
||||
/// If `state` does not correspond to a known game state, returns `None`.
|
||||
pub fn find_node_mut(&mut self, state: &T) -> Option<mutators::MutNode<'_, T, S, A>> {
|
||||
self.state_ids.get(state).map(|s| *s.id()).map(move |id| mutators::MutNode::new(self, id))
|
||||
self
|
||||
.state_ids
|
||||
.get(state)
|
||||
.map(|s| *s.id())
|
||||
.map(move |id| mutators::MutNode::new(self, id))
|
||||
}
|
||||
|
||||
/// Adds a vertex (with no parents or children) for the given game state and
|
||||
|
@ -21,10 +21,7 @@ use symbol_map::SymbolId;
|
||||
/// `f(i)`.
|
||||
///
|
||||
/// Elements `j` of `data` for which `f(j)` is `None` are discarded.
|
||||
fn permute_compact<T>(
|
||||
data: &mut Vec<T>,
|
||||
f: impl Fn(usize) -> Option<usize>,
|
||||
) {
|
||||
fn permute_compact<T>(data: &mut Vec<T>, f: impl Fn(usize) -> Option<usize>) {
|
||||
if data.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
@ -220,8 +220,12 @@ impl<'a, T: Hash + Eq + Clone + 'a, S: 'a, A: 'a> MutChildList<'a, T, S, A> {
|
||||
/// vertex exists, it is created and associated with the data returned by
|
||||
/// `f`. Returns a mutable edge handle for the new edge, with a lifetime
|
||||
/// limited to a borrow of `self`.
|
||||
pub fn add_child(&mut self, child_label: T, f: impl FnOnce() -> S, edge_data: A) -> MutEdge<'_, T, S, A>
|
||||
{
|
||||
pub fn add_child(
|
||||
&mut self,
|
||||
child_label: T,
|
||||
f: impl FnOnce() -> S,
|
||||
edge_data: A,
|
||||
) -> MutEdge<'_, T, S, A> {
|
||||
let target_id = match self
|
||||
.graph
|
||||
.state_ids
|
||||
@ -354,8 +358,7 @@ impl<'a, T: Hash + Eq + Clone + 'a, S: 'a, A: 'a> MutParentList<'a, T, S, A> {
|
||||
parent_label: T,
|
||||
f: impl FnOnce() -> S,
|
||||
edge_data: A,
|
||||
) -> MutEdge<'_, T, S, A>
|
||||
{
|
||||
) -> MutEdge<'_, T, S, A> {
|
||||
let source_id = match self
|
||||
.graph
|
||||
.state_ids
|
||||
|
@ -225,7 +225,10 @@ impl<'a, T: 'a + Hash + Eq + Clone, S: 'a, A: 'a> Stack<'a, T, S, A> {
|
||||
if i == self.path.len() {
|
||||
Some(StackItem::Head(self.head()))
|
||||
} else {
|
||||
self.path.get(i).map(|edge_id| StackItem::Item(Edge::new(self.graph, *edge_id)))
|
||||
self
|
||||
.path
|
||||
.get(i)
|
||||
.map(|edge_id| StackItem::Item(Edge::new(self.graph, *edge_id)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -236,10 +239,7 @@ where
|
||||
{
|
||||
/// Creates a new path iterator from a borrow of a path.
|
||||
fn new(path: &'s Stack<'a, T, S, A>) -> Self {
|
||||
StackIter {
|
||||
path,
|
||||
position: 0,
|
||||
}
|
||||
StackIter { path, position: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -271,7 +271,9 @@ where
|
||||
/// Returns a reference to an edge between the given nodes that is already in
|
||||
/// the graph, or `None` if there is no such edge.
|
||||
pub fn find_edge(&self, source: NodeRef<'id>, target: NodeRef<'id>) -> Option<EdgeRef<'id>> {
|
||||
self.children(source).find(|child| self.raw_edge(*child).target == target.id)
|
||||
self
|
||||
.children(source)
|
||||
.find(|child| self.raw_edge(*child).target == target.id)
|
||||
}
|
||||
|
||||
/// Adds a node for the given game state with the given data, returning a
|
||||
@ -464,10 +466,7 @@ where
|
||||
|
||||
/// Deletes all graph components that are not reachable by a traversal
|
||||
/// starting from each of `roots`.
|
||||
pub fn retain_reachable_from(
|
||||
self,
|
||||
roots: impl IntoIterator<Item = NodeRef<'id>>,
|
||||
) {
|
||||
pub fn retain_reachable_from(self, roots: impl IntoIterator<Item = NodeRef<'id>>) {
|
||||
let root_ids: Vec<VertexId> = roots.into_iter().map(|n| n.id).collect();
|
||||
self.retain_reachable_from_ids(&root_ids);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user