hypergraph/core/vertices/
get_full_adjacent_vertices_from.rs1use indexmap::IndexMap;
2use itertools::{
3 Itertools,
4 fold,
5};
6
7use crate::{
8 HyperedgeIndex,
9 HyperedgeTrait,
10 Hypergraph,
11 VertexIndex,
12 VertexTrait,
13 core::shared::Connection,
14 errors::HypergraphError,
15};
16
17#[allow(clippy::type_complexity)]
18impl<V, HE> Hypergraph<V, HE>
19where
20 V: VertexTrait,
21 HE: HyperedgeTrait,
22{
23 pub fn get_full_adjacent_vertices_from(
26 &self,
27 from: VertexIndex,
28 ) -> Result<Vec<(VertexIndex, Vec<HyperedgeIndex>)>, HypergraphError<V, HE>> {
29 let results = self.get_connections(&Connection::In(from))?;
30
31 Ok(fold(
32 results,
33 IndexMap::<VertexIndex, Vec<HyperedgeIndex>>::new(),
34 |mut acc, (hyperedge_index, vertex_index)| {
35 if let Some(index) = vertex_index {
36 let hyperedges = acc.entry(index).or_default();
37
38 hyperedges.push(hyperedge_index);
39 }
40
41 acc
42 },
43 )
44 .into_iter()
45 .collect_vec())
46 }
47}