use crate::VtxTrait;
#[derive(Debug)]
pub enum Vertex<T: VtxTrait> {
V {
id: u64,
val: T,
neigh: Vec<Box<u64>>,
},
Empty,
}
impl<T: VtxTrait> Vertex<T> {
pub fn init(&mut self, new_id: u64, nv: T) {
match self {
&mut Vertex::V { .. } => {}
&mut Vertex::Empty => {
*self = Vertex::V {
id: new_id,
val: nv,
neigh: vec![],
};
}
}
}
pub fn add_neigh(&mut self, n_id: u64) {
match self {
&mut Vertex::V { ref mut neigh, .. } => {
neigh.push(Box::new(n_id));
}
Vertex::Empty => return,
}
}
pub fn set_val(&mut self, nv: T) {
match self {
Vertex::V { ref mut val, .. } => {
*val = nv;
}
Vertex::Empty => return,
}
}
pub fn get_val(self) -> Option<T> {
match self {
Vertex::V { val, .. } => Some(val),
Vertex::Empty => None,
}
}
pub fn print(&self) {
match self {
Vertex::V {
ref id,
ref val,
ref neigh,
} => {
let mut s = String::new();
let f = format!("v{} = {}: [", id, val);
let fs = &f[..];
s.push_str(fs);
for i in 0..neigh.len() {
let ff = format!("{},", neigh[i]);
let ffs = &ff[..];
s.push_str(ffs);
}
println!("{}]", s);
}
Vertex::Empty => return,
}
}
}