7 Commits

Author SHA1 Message Date
warrence ad9850800d Update IncidenceCursor trait doc with note on Copy 2026-07-17 11:30:45 +02:00
warrence a14202effc Merge branch 'main' into release-0.3.0 2026-07-17 11:29:41 +02:00
warrence 913a9e0baa Fix AppendGraph::capacity to actually use the underlying vec's capacity 2026-07-17 09:54:16 +02:00
warrence 8c6c98859c Add Copy to IncidenceCursor trait 2026-07-17 09:53:05 +02:00
warrence 24c08438d6 Add IncidenceCursor to prelude 2026-07-17 09:52:35 +02:00
warrence bf6a7142f3 Fix readme typo 2026-07-17 09:50:43 +02:00
warrence fb9dfe8280 Renamed len() to capacity() in EntityMap, VertexMap, and EdgeMap
len() is generally expected to describe the number of elements in a collection,
but in this case elements beyond len() are accessible without restriction.
capacity() is a better name because it describes data storage size.
2026-07-10 11:58:45 +02:00
4 changed files with 7 additions and 15 deletions
+1 -1
View File
@@ -133,7 +133,7 @@ pub mod models;
pub mod traits; pub mod traits;
pub mod prelude { pub mod prelude {
pub use crate::traits::{GraphTopology, GraphTopologyDeletion}; pub use crate::traits::{GraphTopology, GraphTopologyDeletion, IncidenceCursor};
} }
mod testing; mod testing;
-10
View File
@@ -18,11 +18,6 @@ impl<V: Copy, T: Clone> VertexMap<V, T> {
self.inner.capacity() self.inner.capacity()
} }
#[deprecated(since = "0.2.2", note = "use 'capacity' instead")]
pub fn len(&self) -> usize {
self.capacity()
}
pub fn sync<G: GraphTopology<Vertex = V>>(&mut self, graph: &G) { pub fn sync<G: GraphTopology<Vertex = V>>(&mut self, graph: &G) {
self.inner.resize(graph.vertex_capacity()); self.inner.resize(graph.vertex_capacity());
} }
@@ -58,11 +53,6 @@ impl<E: Copy, T: Clone> EdgeMap<E, T> {
self.inner.capacity() self.inner.capacity()
} }
#[deprecated(since = "0.2.2", note = "use 'capacity' instead")]
pub fn len(&self) -> usize {
self.capacity()
}
pub fn sync<G: GraphTopology<Edge = E>>(&mut self, graph: &G) { pub fn sync<G: GraphTopology<Edge = E>>(&mut self, graph: &G) {
self.inner.resize(graph.edge_capacity()); self.inner.resize(graph.edge_capacity());
} }
+1 -1
View File
@@ -91,7 +91,7 @@ impl GraphTopology for AppendGraph {
} }
fn vertex_capacity(&self) -> usize { fn vertex_capacity(&self) -> usize {
self.vertices.len() self.vertices.capacity()
} }
fn vertex_map<T: Clone>(&self, default: T) -> VertexMap<Self::Vertex, T> { fn vertex_map<T: Clone>(&self, default: T) -> VertexMap<Self::Vertex, T> {
+5 -3
View File
@@ -38,7 +38,7 @@ pub trait GraphTopology {
/// when an algorithm needs to pause traversal, perform other graph queries or mutations, and /// when an algorithm needs to pause traversal, perform other graph queries or mutations, and
/// then continue from where it left off. This cursor type can be obtained via /// then continue from where it left off. This cursor type can be obtained via
/// [`incidence_cursor`](Self::incidence_cursor). /// [`incidence_cursor`](Self::incidence_cursor).
type IncidenceCursor: IncidenceCursor<Self> + Copy; type IncidenceCursor: IncidenceCursor<Self>;
/// Returns the number of vertices in the graph. /// Returns the number of vertices in the graph.
fn vertex_count(&self) -> usize; fn vertex_count(&self) -> usize;
@@ -210,10 +210,13 @@ pub trait GraphTopologyDeletion: GraphTopology {
/// A cursor for traversing the incidences of a vertex one step at a time. /// A cursor for traversing the incidences of a vertex one step at a time.
/// ///
/// Because the cursor is [`Copy`], its state can be saved and restored to replay or branch a
/// traversal.
///
/// Cursors are obtained via [`GraphTopology::incidence_cursor`]. See /// Cursors are obtained via [`GraphTopology::incidence_cursor`]. See
/// [`GraphTopology::IncidenceCursor`] for guidance on when to prefer a cursor over /// [`GraphTopology::IncidenceCursor`] for guidance on when to prefer a cursor over
/// [`GraphTopology::incidences`]. /// [`GraphTopology::incidences`].
pub trait IncidenceCursor<G: GraphTopology + ?Sized> { pub trait IncidenceCursor<G: GraphTopology + ?Sized>: Copy {
/// Advances the cursor and returns the next incidence as `Some((u, e))`, or `None` if the /// Advances the cursor and returns the next incidence as `Some((u, e))`, or `None` if the
/// traversal is exhausted. /// traversal is exhausted.
/// ///
@@ -222,7 +225,6 @@ pub trait IncidenceCursor<G: GraphTopology + ?Sized> {
/// ``` /// ```
/// # use grapherity::prelude::*; /// # use grapherity::prelude::*;
/// # use grapherity::models::Graph; /// # use grapherity::models::Graph;
/// # use grapherity::traits::IncidenceCursor;
/// // Constructs a graph with two vertices connected to `v`. /// // Constructs a graph with two vertices connected to `v`.
/// let mut graph = Graph::new(); /// let mut graph = Graph::new();
/// let v = graph.add_vertex(); /// let v = graph.add_vertex();