2 use fixedbitset
::FixedBitSet
;
13 #[cfg(feature = "stable_graph")]
14 use stable_graph
::StableGraph
;
15 #[cfg(feature = "stable_graph")]
16 use visit
::{NodeIndexable, IntoEdgeReferences}
;
19 use super::visit
::GetAdjacencyMatrix
;
21 /// The adjacency matrix for **Graph** is a bitmap that's computed by
22 /// `.adjacency_matrix()`.
23 impl<N
, E
, Ty
, Ix
> GetAdjacencyMatrix
for Graph
<N
, E
, Ty
, Ix
> where
27 type AdjMatrix
= FixedBitSet
;
29 fn adjacency_matrix(&self) -> FixedBitSet
31 let n
= self.node_count();
32 let mut matrix
= FixedBitSet
::with_capacity(n
* n
);
33 for edge
in self.edge_references() {
34 let i
= edge
.source().index() * n
+ edge
.target().index();
36 if !self.is_directed() {
37 let j
= edge
.source().index() + n
* edge
.target().index();
44 fn is_adjacent(&self, matrix
: &FixedBitSet
, a
: NodeIndex
<Ix
>, b
: NodeIndex
<Ix
>) -> bool
46 let n
= self.node_count();
47 let index
= n
* a
.index() + b
.index();
48 matrix
.contains(index
)
53 #[cfg(feature = "stable_graph")]
54 /// The adjacency matrix for **Graph** is a bitmap that's computed by
55 /// `.adjacency_matrix()`.
56 impl<N
, E
, Ty
, Ix
> GetAdjacencyMatrix
for StableGraph
<N
, E
, Ty
, Ix
> where
60 type AdjMatrix
= FixedBitSet
;
62 fn adjacency_matrix(&self) -> FixedBitSet
64 let n
= self.node_bound();
65 let mut matrix
= FixedBitSet
::with_capacity(n
* n
);
66 for edge
in self.edge_references() {
67 let i
= edge
.source().index() * n
+ edge
.target().index();
69 if !self.is_directed() {
70 let j
= edge
.source().index() + n
* edge
.target().index();
77 fn is_adjacent(&self, matrix
: &FixedBitSet
, a
: NodeIndex
<Ix
>, b
: NodeIndex
<Ix
>) -> bool
79 let n
= self.node_count();
80 let index
= n
* a
.index() + b
.index();
81 matrix
.contains(index
)