1use std::ops::{Index, IndexMut};
2use eta_algorithms::data_structs::fat_ptr::{FatPtr, FatPtrMut};
3use crate::handles::types::{Edge, VHandle, Weight, Ci};
4
5pub trait StoreVertex: Index<VHandle, Output=Self::VertexType> + IndexMut<VHandle, Output=Self::VertexType>{
6 type VertexType;
7 fn is_empty(&self) -> bool;
8 fn len(&self) -> usize;
9 fn push(&mut self, val: Self::VertexType);
10 fn capacity(&self) -> usize;
11 fn iter(&self) -> std::slice::Iter<Self::VertexType>;
12 fn iter_mut(&mut self) -> std::slice::IterMut<Self::VertexType>;
13 fn as_slice(&self) -> &[Self::VertexType];
14}
15
16pub trait EdgeConnect {
17 fn connect_edges(&mut self, src: VHandle, targets: &[Edge]);
18 fn disconnect(&mut self, src_handle: VHandle, handle: VHandle);
19 fn connect(&mut self, from: VHandle, to: VHandle);
20}
21
22pub trait WeightedEdgeConnect {
23 fn connect_weighted(&mut self, from: VHandle, to: VHandle, weight: Weight);
24}
25
26pub trait EdgeStore: Index<usize, Output=Edge> + IndexMut<usize, Output=Edge>{
27 fn create_vertex_entry(&mut self, size: Ci) -> VHandle;
28 fn edges_as_slice(&self, handle: VHandle) -> &[Edge];
29 fn edges_as_mut_slice(&mut self, handle: VHandle) -> &mut [Edge];
30 fn edges_as_ptr(&self, handle: VHandle) -> FatPtr<Edge>;
31 fn edges_as_mut_ptr(&mut self, handle: VHandle) -> FatPtrMut<Edge>;
32 fn edges_is_empty(&self, handle: VHandle) -> bool;
33 fn edges_len(&self, handle: VHandle) -> usize;
34 fn edges_capacity(&self, handle: VHandle) -> usize;
35 fn edges_index(&self, handle: VHandle) -> usize;
36 fn iter(&self) -> impl Iterator<Item=&Edge>;
37 fn iter_mut (&mut self) -> impl Iterator<Item=&mut Edge>;
38 fn edges_iter(&self, handle: VHandle) -> impl Iterator<Item=&Edge>;
39 fn edges_iter_mut(&mut self, handle: VHandle) -> impl Iterator<Item=&mut Edge>;
40
41 unsafe fn edges_iter_mut_unchecked(&mut self, handle: VHandle) -> impl Iterator<Item=&mut Edge>;
46}
47pub trait EdgeManipulate: EdgeStore + EdgeConnect + Clone{}
48pub trait WeightedEdgeManipulate: EdgeManipulate + WeightedEdgeConnect {}