1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
use crate::structure::VertexProperty; use crate::structure::GID; use std::collections::hash_map::{IntoIter, Iter}; use std::collections::HashMap; use std::hash::Hasher; #[derive(Debug, Clone)] pub struct Vertex { id: GID, label: String, properties: HashMap<String, Vec<VertexProperty>>, } impl Vertex { pub(crate) fn new<T>( id: GID, label: T, properties: HashMap<String, Vec<VertexProperty>>, ) -> Vertex where T: Into<String>, { Vertex { id, label: label.into(), properties, } } pub fn id(&self) -> &GID { &self.id } pub fn label(&self) -> &String { &self.label } pub fn iter(&self) -> Iter<String, Vec<VertexProperty>> { self.properties.iter() } pub fn property(&self, key: &str) -> Option<&VertexProperty> { self.properties.get(key).and_then(|v| v.get(0)) } } impl IntoIterator for Vertex { type Item = (String, Vec<VertexProperty>); type IntoIter = IntoIter<String, Vec<VertexProperty>>; fn into_iter(self) -> Self::IntoIter { self.properties.into_iter() } } impl std::cmp::Eq for Vertex {} impl std::hash::Hash for Vertex { fn hash<H: Hasher>(&self, state: &mut H) { self.id.hash(state); } } impl PartialEq for Vertex { fn eq(&self, other: &Vertex) -> bool { &self.id == other.id() } }