Rename Arc->RawEdge. Add Ord & co. to RawEdge.

This commit is contained in:
Stu Black 2016-04-13 23:05:46 -04:00
parent 649203baad
commit 1a5c88e687
5 changed files with 21 additions and 29 deletions

View File

@ -1,4 +1,4 @@
use std::cmp::{Eq, PartialEq};
use std::cmp::Eq;
use std::collections::HashMap;
use std::collections::hash_map::Entry;
use std::hash::Hash;
@ -111,8 +111,11 @@ impl<T> StateNamespace<T> where T: Hash + Eq + Clone {
}
/// Internal type for graph edges.
#[derive(Debug)]
pub struct Arc<A> {
///
/// The Hash, Ord, and Eq implementations will conflate parallel edges with
/// identical statistics.
#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)]
pub struct RawEdge<A> {
/// Edge data.
pub data: A,
/// Source vertex.
@ -123,17 +126,6 @@ pub struct Arc<A> {
pub target: Target<VertexId, ()>,
}
/// This implementation will conflate parallel edges with identical statistics.
impl<A> PartialEq for Arc<A> where A: PartialEq {
fn eq(&self, other: &Arc<A>) -> bool {
self.source == other.source
&& self.target == other.target
&& self.data == other.data
}
}
impl<A> Eq for Arc<A> where A: Eq { }
/// Internal type for graph vertices.
#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)]
pub struct RawVertex<S> {

View File

@ -214,7 +214,7 @@ impl<'a, T, S, A> Collector<'a, T, S, A> where T: Hash + Eq + Clone + 'a, S: 'a,
#[cfg(test)]
mod test {
use super::Collector;
use ::hidden::base::{EdgeId, Arc, VertexId, StateNamespace, RawVertex};
use ::hidden::base::{EdgeId, VertexId, StateNamespace, RawEdge, RawVertex};
use ::Target;
use std::collections::HashMap;
@ -235,8 +235,8 @@ mod test {
}
fn make_arc(data: &'static str, source: VertexId, target: Target<VertexId, ()>)
-> Arc<&'static str> {
Arc { data: data, source: source, target: target, }
-> RawEdge<&'static str> {
RawEdge { data: data, source: source, target: target, }
}
#[test]

View File

@ -299,11 +299,11 @@ pub fn make_mut_edge<'a, T, S, A>(graph: &'a mut Graph<T, S, A>, id: EdgeId) ->
}
impl<'a, T, S, A> MutEdge<'a, T, S, A> where T: Hash + Eq + Clone + 'a, S: 'a, A: 'a {
fn arc(&self) -> &Arc<A> {
fn arc(&self) -> &RawEdge<A> {
self.graph.get_arc(self.id)
}
fn arc_mut(&mut self) -> &mut Arc<A> {
fn arc_mut(&mut self) -> &mut RawEdge<A> {
self.graph.get_arc_mut(self.id)
}
@ -407,7 +407,7 @@ pub enum Expanded<T> {
}
impl<'a, T, S, A> EdgeExpander<'a, T, S, A> where T: Hash + Eq + Clone + 'a, S: 'a, A: 'a {
fn arc_mut(&mut self) -> &mut Arc<A> {
fn arc_mut(&mut self) -> &mut RawEdge<A> {
self.graph.get_arc_mut(self.id)
}
@ -491,11 +491,11 @@ pub struct MutExpandedEdge<'a, T, S, A> where T: Hash + Eq + Clone + 'a, S: 'a,
}
impl<'a, T, S, A> MutExpandedEdge<'a, T, S, A> where T: Hash + Eq + Clone + 'a, S: 'a, A: 'a {
fn arc(&self) -> &Arc<A> {
fn arc(&self) -> &RawEdge<A> {
self.graph.get_arc(self.id)
}
fn arc_mut(&mut self) -> &mut Arc<A> {
fn arc_mut(&mut self) -> &mut RawEdge<A> {
self.graph.get_arc_mut(self.id)
}

View File

@ -2,7 +2,7 @@ use std::hash::Hash;
use std::iter::Iterator;
use ::{Graph, Target};
use ::hidden::base::{Arc, EdgeId, VertexId, RawVertex};
use ::hidden::base::{EdgeId, VertexId, RawEdge, RawVertex};
/// Immutable handle to a graph vertex ("node handle").
///
@ -250,7 +250,7 @@ pub fn make_edge<'a, T, S, A>(graph: &'a Graph<T, S, A>, id: EdgeId) -> Edge<'a,
}
impl<'a, T, S, A> Edge<'a, T, S, A> where T: Hash + Eq + Clone + 'a, S: 'a, A: 'a {
fn arc(&self) -> &'a Arc<A> {
fn arc(&self) -> &'a RawEdge<A> {
self.graph.get_arc(self.id)
}

View File

@ -29,7 +29,7 @@ pub struct Graph<T, S, A> where T: Hash + Eq + Clone {
/// Lookup table that maps from game states to `VertexId`.
state_ids: StateNamespace<T>,
vertices: Vec<RawVertex<S>>, // Indexed by VertexId.
arcs: Vec<Arc<A>>, // Indexed by EdgeId.
arcs: Vec<RawEdge<A>>, // Indexed by EdgeId.
}
impl<T, S, A> Graph<T, S, A> where T: Hash + Eq + Clone {
@ -53,12 +53,12 @@ impl<T, S, A> Graph<T, S, A> where T: Hash + Eq + Clone {
}
/// Returns the edge for the given `EdgeId`.
fn get_arc(&self, arc: EdgeId) -> &Arc<A> {
fn get_arc(&self, arc: EdgeId) -> &RawEdge<A> {
&self.arcs[arc.as_usize()]
}
/// Returns the edge for the given `EdgeId`.
fn get_arc_mut(&mut self, arc: EdgeId) -> &mut Arc<A> {
fn get_arc_mut(&mut self, arc: EdgeId) -> &mut RawEdge<A> {
&mut self.arcs[arc.as_usize()]
}
@ -84,7 +84,7 @@ impl<T, S, A> Graph<T, S, A> where T: Hash + Eq + Clone {
if let Target::Expanded(target_id) = target {
self.get_vertex_mut(target_id).parents.push(arc_id);
}
self.arcs.push(Arc { data: data, source: source, target: target, });
self.arcs.push(RawEdge { data: data, source: source, target: target, });
arc_id
}
@ -195,7 +195,7 @@ impl<T, S, A> Graph<T, S, A> where T: Hash + Eq + Clone {
/// A search graph is built up incrementally, and this type is used to represent
/// an edge whose destination vertex isn't yet known. Graph-modifying operations
/// which are executed while exploring the graph topology may expand such edges.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub enum Target<T, R> {
/// Edge has not yet been expanded. Associated data may be used to perform
/// expansion.