Compare commits
4 Commits
0.2.0
...
fixes-major
| Author | SHA1 | Date | |
|---|---|---|---|
| fb9dfe8280 | |||
| dd0399dcdd | |||
| 3c4391ac1d | |||
| bbd9506bbc |
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "grapherity"
|
name = "grapherity"
|
||||||
version = "0.2.0"
|
version = "0.2.1"
|
||||||
authors = ["Stefan Müller"]
|
authors = ["Stefan Müller"]
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.85.0"
|
rust-version = "1.85.0"
|
||||||
|
|||||||
@@ -3,4 +3,8 @@ pub mod maps;
|
|||||||
pub mod models;
|
pub mod models;
|
||||||
pub mod traits;
|
pub mod traits;
|
||||||
|
|
||||||
|
pub mod prelude {
|
||||||
|
pub use crate::traits::{GraphTopology, GraphTopologyDeletion};
|
||||||
|
}
|
||||||
|
|
||||||
mod testing;
|
mod testing;
|
||||||
|
|||||||
+7
-7
@@ -13,9 +13,9 @@ impl<V: Copy, T: Clone> VertexMap<V, T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reads beyond len() are valid and return the default value.
|
// Reads beyond capacity() are valid and return the default value.
|
||||||
pub fn len(&self) -> usize {
|
pub fn capacity(&self) -> usize {
|
||||||
self.inner.len()
|
self.inner.capacity()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sync<G: GraphTopology<Vertex = V>>(&mut self, graph: &G) {
|
pub fn sync<G: GraphTopology<Vertex = V>>(&mut self, graph: &G) {
|
||||||
@@ -48,9 +48,9 @@ impl<E: Copy, T: Clone> EdgeMap<E, T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reads beyond len() are valid and return the default value.
|
// Reads beyond capacity() are valid and return the default value.
|
||||||
pub fn len(&self) -> usize {
|
pub fn capacity(&self) -> usize {
|
||||||
self.inner.len()
|
self.inner.capacity()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sync<G: GraphTopology<Edge = E>>(&mut self, graph: &G) {
|
pub fn sync<G: GraphTopology<Edge = E>>(&mut self, graph: &G) {
|
||||||
@@ -87,7 +87,7 @@ impl<E: Copy, T: Clone> EntityMap<E, T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn len(&self) -> usize {
|
pub fn capacity(&self) -> usize {
|
||||||
self.data.len()
|
self.data.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,16 +53,16 @@ macro_rules! vertex_map_tests {
|
|||||||
let mut graph = <$T>::new();
|
let mut graph = <$T>::new();
|
||||||
graph.add_vertex();
|
graph.add_vertex();
|
||||||
let mut map = graph.vertex_map(42);
|
let mut map = graph.vertex_map(42);
|
||||||
let initial_len = map.len();
|
let initial_len = map.capacity();
|
||||||
while graph.vertex_capacity() <= initial_len {
|
while graph.vertex_capacity() <= initial_len {
|
||||||
graph.add_vertex();
|
graph.add_vertex();
|
||||||
}
|
}
|
||||||
assert!(
|
assert!(
|
||||||
map.len() < graph.vertex_capacity(),
|
map.capacity() < graph.vertex_capacity(),
|
||||||
"precondition: map is stale before sync"
|
"precondition: map is stale before sync"
|
||||||
);
|
);
|
||||||
map.sync(&graph);
|
map.sync(&graph);
|
||||||
assert_eq!(map.len(), graph.vertex_capacity());
|
assert_eq!(map.capacity(), graph.vertex_capacity());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -109,7 +109,7 @@ macro_rules! vertex_map_deletion_tests {
|
|||||||
let capacity_before = graph.vertex_capacity();
|
let capacity_before = graph.vertex_capacity();
|
||||||
graph.delete_vertex(v2);
|
graph.delete_vertex(v2);
|
||||||
map.sync(&graph);
|
map.sync(&graph);
|
||||||
assert_eq!(map.len(), capacity_before);
|
assert_eq!(map.capacity(), capacity_before);
|
||||||
assert_eq!(map[v1], 5);
|
assert_eq!(map[v1], 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,16 +197,16 @@ macro_rules! edge_map_tests {
|
|||||||
let v2 = graph.add_vertex();
|
let v2 = graph.add_vertex();
|
||||||
graph.add_edge(v1, v2);
|
graph.add_edge(v1, v2);
|
||||||
let mut map = graph.edge_map(42);
|
let mut map = graph.edge_map(42);
|
||||||
let initial_len = map.len();
|
let initial_len = map.capacity();
|
||||||
while graph.edge_capacity() <= initial_len {
|
while graph.edge_capacity() <= initial_len {
|
||||||
graph.add_edge(v1, v2);
|
graph.add_edge(v1, v2);
|
||||||
}
|
}
|
||||||
assert!(
|
assert!(
|
||||||
map.len() < graph.edge_capacity(),
|
map.capacity() < graph.edge_capacity(),
|
||||||
"precondition: map is stale before sync"
|
"precondition: map is stale before sync"
|
||||||
);
|
);
|
||||||
map.sync(&graph);
|
map.sync(&graph);
|
||||||
assert_eq!(map.len(), graph.edge_capacity());
|
assert_eq!(map.capacity(), graph.edge_capacity());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -259,7 +259,7 @@ macro_rules! edge_map_deletion_tests {
|
|||||||
let capacity_before = graph.edge_capacity();
|
let capacity_before = graph.edge_capacity();
|
||||||
graph.delete_edge(e2);
|
graph.delete_edge(e2);
|
||||||
map.sync(&graph);
|
map.sync(&graph);
|
||||||
assert_eq!(map.len(), capacity_before);
|
assert_eq!(map.capacity(), capacity_before);
|
||||||
assert_eq!(map[e1], 5);
|
assert_eq!(map[e1], 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user