Rename Vertex->RawVertex. Add Ord and PartialOrd to RawVertex.

This commit is contained in:
Stu Black 2016-04-13 23:01:54 -04:00
parent 9d3c123bdb
commit 649203baad
5 changed files with 19 additions and 29 deletions

View File

@ -10,7 +10,7 @@ use ::Target;
/// This type is not exported by the crate because it does not identify the
/// graph that it belongs to, which makes it only slightly less dangerous than a
/// pointer with no lifetime.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct EdgeId(pub usize);
impl EdgeId {
@ -28,7 +28,7 @@ impl EdgeId {
/// states. This type is not exported by the crate because it does not identify
/// the graph that it belongs to, which makes it only slightly less dangerous
/// than a pointer with no lifetime.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct VertexId(pub usize);
impl VertexId {
@ -135,8 +135,8 @@ impl<A> PartialEq for Arc<A> where A: PartialEq {
impl<A> Eq for Arc<A> where A: Eq { }
/// Internal type for graph vertices.
#[derive(Debug)]
pub struct Vertex<S> {
#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)]
pub struct RawVertex<S> {
/// Vertex data.
pub data: S,
/// Parent edges pointing into this vertex.
@ -144,13 +144,3 @@ pub struct Vertex<S> {
/// Child edges pointing out of this vertex.
pub children: Vec<EdgeId>,
}
impl<S> PartialEq for Vertex<S> where S: PartialEq {
fn eq(&self, other: &Vertex<S>) -> bool {
self.parents == other.parents
&& self.children == other.children
&& self.data == other.data
}
}
impl<S> Eq for Vertex<S> where S: Eq { }

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, Vertex};
use ::hidden::base::{EdgeId, Arc, VertexId, StateNamespace, RawVertex};
use ::Target;
use std::collections::HashMap;
@ -230,8 +230,8 @@ mod test {
}
fn make_vertex(data: &'static str, parents: Vec<EdgeId>, children: Vec<EdgeId>)
-> Vertex<&'static str> {
Vertex { data: data, parents: parents, children: children, }
-> RawVertex<&'static str> {
RawVertex { data: data, parents: parents, children: children, }
}
fn make_arc(data: &'static str, source: VertexId, target: Target<VertexId, ()>)

View File

@ -32,11 +32,11 @@ pub fn make_mut_node<'a, T, S, A>(graph: &'a mut Graph<T, S, A>, id: VertexId) -
}
impl<'a, T, S, A> MutNode<'a, T, S, A> where T: Hash + Eq + Clone + 'a, S: 'a, A: 'a {
fn vertex<'s>(&'s self) -> &'s Vertex<S> {
fn vertex<'s>(&'s self) -> &'s RawVertex<S> {
self.graph.get_vertex(self.id)
}
fn vertex_mut<'s>(&'s mut self) -> &'s mut Vertex<S> {
fn vertex_mut<'s>(&'s mut self) -> &'s mut RawVertex<S> {
self.graph.get_vertex_mut(self.id)
}
@ -126,7 +126,7 @@ pub struct MutChildList<'a, T, S, A> where T: Hash + Eq + Clone + 'a, S: 'a, A:
}
impl<'a, T, S, A> MutChildList<'a, T, S, A> where T: Hash + Eq + Clone + 'a, S: 'a, A: 'a {
fn vertex<'s>(&'s self) -> &'s Vertex<S> {
fn vertex<'s>(&'s self) -> &'s RawVertex<S> {
self.graph.get_vertex(self.id)
}
@ -216,7 +216,7 @@ pub struct MutParentList<'a, T, S, A> where T: Hash + Eq + Clone + 'a, S: 'a, A:
}
impl<'a, T, S, A> MutParentList<'a, T, S, A> where T: Hash + Eq + Clone + 'a, S: 'a, A: 'a {
fn vertex<'s>(&'s self) -> &'s Vertex<S> {
fn vertex<'s>(&'s self) -> &'s RawVertex<S> {
self.graph.get_vertex(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, Vertex};
use ::hidden::base::{Arc, EdgeId, VertexId, RawVertex};
/// Immutable handle to a graph vertex ("node handle").
///
@ -79,7 +79,7 @@ pub fn make_child_list<'a, T, S, A>(graph: &'a Graph<T, S, A>, id: VertexId) ->
}
impl<'a, T, S, A> ChildList<'a, T, S, A> where T: Hash + Eq + Clone + 'a, S: 'a, A: 'a {
fn vertex(&self) -> &'a Vertex<S> {
fn vertex(&self) -> &'a RawVertex<S> {
self.graph.get_vertex(self.id)
}
@ -164,7 +164,7 @@ pub fn make_parent_list<'a, T, S, A>(graph: &'a Graph<T, S, A>, id: VertexId) ->
}
impl<'a, T, S, A> ParentList<'a, T, S, A> where T: Hash + Eq + Clone + 'a, S: 'a, A: 'a {
fn vertex(&self) -> &'a Vertex<S> {
fn vertex(&self) -> &'a RawVertex<S> {
self.graph.get_vertex(self.id)
}

View File

@ -28,7 +28,7 @@ use self::hidden::mutators::{MutEdge, MutNode, make_mut_edge, make_mut_node};
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<Vertex<S>>, // Indexed by VertexId.
vertices: Vec<RawVertex<S>>, // Indexed by VertexId.
arcs: Vec<Arc<A>>, // Indexed by EdgeId.
}
@ -43,12 +43,12 @@ impl<T, S, A> Graph<T, S, A> where T: Hash + Eq + Clone {
}
/// Returns the vertex for the given `VertexId`.
fn get_vertex(&self, state: VertexId) -> &Vertex<S> {
fn get_vertex(&self, state: VertexId) -> &RawVertex<S> {
&self.vertices[state.as_usize()]
}
/// Returns the vertex for the given `VertexId`.
fn get_vertex_mut(&mut self, state: VertexId) -> &mut Vertex<S> {
fn get_vertex_mut(&mut self, state: VertexId) -> &mut RawVertex<S> {
&mut self.vertices[state.as_usize()]
}
@ -67,8 +67,8 @@ impl<T, S, A> Graph<T, S, A> where T: Hash + Eq + Clone {
/// This method does not add incoming or outgoing edges (expanded or
/// not). That must be done by calling `add_arc` with the new vertex
/// `VertexId`.
fn add_vertex(&mut self, data: S) -> &mut Vertex<S> {
self.vertices.push(Vertex {
fn add_vertex(&mut self, data: S) -> &mut RawVertex<S> {
self.vertices.push(RawVertex {
data: data,
parents: Vec::new(),
children: Vec::new(),