mapgraph/aliases.rs
1//! Contains type aliases of the [`Graph`] type that use specific node and edge maps and the maps themselves.
2
3use crate::{graph::Node, FrozenGraph, Graph};
4#[cfg(feature = "alloc")]
5use alloc::collections::BTreeMap;
6#[cfg(feature = "std")]
7use std::{collections::HashMap, hash::RandomState};
8#[cfg(feature = "slotmap")]
9use {
10 crate::{
11 graph::Edge,
12 map::slotmap::{EdgeIndex, NodeIndex},
13 },
14 slotmap::{DenseSlotMap, HopSlotMap, SecondaryMap, SlotMap, SparseSecondaryMap},
15};
16
17/// A type alias for a [`SlotMap`] that maps a certain key type (the default is [`NodeIndex`]) to
18/// [`Node`] structures.
19///
20/// This is intended to be used as a node map type by the [`Graph`] type.
21#[cfg(feature = "slotmap")]
22pub type SlotNodeMap<N, NI = NodeIndex, EI = EdgeIndex> = SlotMap<NI, Node<N, EI>>;
23
24/// A type alias for a [`SlotMap`] that maps a certain key type (the default is [`EdgeIndex`]) to
25/// [`Edge`] structures.
26///
27/// This is intended to be used as an edge map type by the [`Graph`] type.
28#[cfg(feature = "slotmap")]
29pub type SlotEdgeMap<E, NI = NodeIndex, EI = EdgeIndex> = SlotMap<EI, Edge<E, NI, EI>>;
30
31/// A type alias for a [`HopSlotMap`] that maps a certain key type (the default is [`NodeIndex`]) to
32/// [`Node`] structures.
33///
34/// This is intended to be used as a node map type by the [`Graph`] type.
35#[cfg(feature = "slotmap")]
36pub type HopSlotNodeMap<N, NI = NodeIndex, EI = EdgeIndex> = HopSlotMap<NI, Node<N, EI>>;
37
38/// A type alias for a [`HopSlotMap`] that maps a certain key type (the default is [`EdgeIndex`]) to
39/// [`Edge`] structures.
40///
41/// This is intended to be used as an edge map type by the [`Graph`] type.
42#[cfg(feature = "slotmap")]
43pub type HopSlotEdgeMap<E, NI = NodeIndex, EI = EdgeIndex> = HopSlotMap<EI, Edge<E, NI, EI>>;
44
45/// A type alias for a [`DenseSlotMap`] that maps a certain key type (the default is [`NodeIndex`]) to
46/// [`Node`] structures.
47///
48/// This is intended to be used as a node map type by the [`Graph`] type.
49#[cfg(feature = "slotmap")]
50pub type DenseSlotNodeMap<N, NI = NodeIndex, EI = EdgeIndex> = DenseSlotMap<NI, Node<N, EI>>;
51
52/// A type alias for a [`DenseSlotMap`] that maps a certain key type (the default is [`EdgeIndex`]) to
53/// [`Edge`] structures.
54///
55/// This is intended to be used as an edge map type by the [`Graph`] type.
56#[cfg(feature = "slotmap")]
57pub type DenseSlotEdgeMap<E, NI = NodeIndex, EI = EdgeIndex> = DenseSlotMap<EI, Edge<E, NI, EI>>;
58
59/// A reexport of [`SecondaryMap`] from the [`slotmap`] crate.
60#[cfg(feature = "slotmap")]
61pub type SecondarySlotMap<K, V> = SecondaryMap<K, V>;
62
63/// A reexport of [`SparseSecondaryMap`] from the [`slotmap`] crate.
64#[cfg(all(feature = "slotmap", feature = "std"))]
65pub type SparseSecondarySlotMap<K, V> = SparseSecondaryMap<K, V>;
66
67/// A type alias for a [`SecondaryMap`] with the unit type as the value type.
68///
69/// This is intended to be used by algorithms on graphs that use [`SlotMap`]s (or equivalents) to
70/// back either their node or edge maps.
71#[cfg(feature = "slotmap")]
72pub type SecondarySlotKeySet<K> = SecondaryMap<K, ()>;
73
74/// A type alias for a [`SparseSecondaryMap`] with the unit type as the value type.
75///
76/// This is intended to be used by algorithms on graphs that use [`SlotMap`]s (or equivalents) to
77/// back either their node or edge maps.
78///
79/// For differences between a [`SecondaryMap`] and a [`SparseSecondaryMap`] see docs for these
80/// types.
81#[cfg(all(feature = "slotmap", feature = "std"))]
82pub type SparseSecondarySlotKeySet<K> = SparseSecondaryMap<K, ()>;
83
84/// A type alias for a [`BTreeMap`] that maps a certain key type to [`Node`] structures.
85///
86/// This is intended to be used as a node map type by the [`Graph`] type.
87#[cfg(feature = "alloc")]
88pub type BTreeNodeMap<N, NI, EI> = BTreeMap<NI, Node<N, EI>>;
89
90/// A type alias for a [`Graph`] that uses a [`BTreeMap`] to store its
91/// nodes.
92#[cfg(feature = "alloc")]
93pub type BTreeNodeGraph<N, E, NI, EI, EM> = Graph<N, E, NI, EI, BTreeNodeMap<N, NI, EI>, EM>;
94
95/// A type alias for a [`FrozenGraph`] that uses a [`BTreeMap`] to
96/// store its nodes.
97#[cfg(feature = "alloc")]
98pub type FrozenBTreeNodeGraph<N, E, NI, EI, EM> =
99 FrozenGraph<N, E, NI, EI, BTreeNodeMap<N, NI, EI>, EM>;
100
101/// A type alias for a [`Graph`] that uses a [`BTreeMap`] to store its
102/// nodes and a [`SlotMap`] to store its edges.
103///
104/// The default edge index type is [`EdgeIndex`].
105#[cfg(all(feature = "alloc", feature = "slotmap"))]
106pub type BTreeSlotMapGraph<N, E, NI, EI = EdgeIndex> =
107 BTreeNodeGraph<N, E, NI, EI, SlotEdgeMap<E, NI, EI>>;
108
109/// A type alias for a [`FrozenGraph`] that uses a [`BTreeMap`] to
110/// store its nodes and a [`SlotMap`] to store its edges.
111///
112/// The default edge index type is [`EdgeIndex`].
113#[cfg(all(feature = "alloc", feature = "slotmap"))]
114pub type FrozenBTreeSlotMapGraph<N, E, NI, EI = EdgeIndex> =
115 FrozenBTreeNodeGraph<N, E, NI, EI, SlotEdgeMap<E, NI, EI>>;
116
117/// A type alias for a [`HashMap`] that maps a certain key type to [`Node`] structures.
118///
119/// This is intended to be used as a node map type by the [`Graph`] type.
120///
121/// # Custom hashers
122///
123/// [`HashNodeMap`] supports passing a custom hasher type to [`HashMap`] via its last generic
124/// parameter `S`, the default is [`RandomState`] which is also the default type used by the Rust
125/// standard library.
126#[cfg(feature = "std")]
127pub type HashNodeMap<N, NI, EI, S = RandomState> = HashMap<NI, Node<N, EI>, S>;
128
129/// A type alias for a [`Graph`] that uses a [`HashMap`] to store its
130/// nodes.
131///
132/// # Custom hashers
133///
134/// [`HashNodeGraph`] supports passing a custom hasher type to [`HashMap`] via its last generic
135/// parameter `S`, the default is [`RandomState`] which is also the default type used by the Rust
136/// standard library.
137#[cfg(feature = "std")]
138pub type HashNodeGraph<N, E, NI, EI, EM, S = RandomState> =
139 Graph<N, E, NI, EI, HashNodeMap<N, NI, EI, S>, EM>;
140
141#[cfg(feature = "std")]
142/// A type alias for a [`FrozenGraph`] that uses a [`HashMap`] to store
143/// its nodes.
144///
145/// # Custom hashers
146///
147/// [`FrozenHashNodeGraph`] supports passing a custom hasher type to [`HashMap`] via its last
148/// generic parameter `S`, the default is [`RandomState`] which is also the default type used by the
149/// Rust standard library.
150pub type FrozenHashNodeGraph<N, E, NI, EI, EM, S = RandomState> =
151 FrozenGraph<N, E, NI, EI, HashNodeMap<N, NI, EI, S>, EM>;
152
153/// A type alias for a [`Graph`] that uses a [`HashMap`] to store its
154/// nodes and a [`SlotMap`] to store its edges.
155///
156/// The default edge index type is [`EdgeIndex`].
157///
158/// # Custom hashers
159///
160/// [`HashSlotMapGraph`] supports passing a custom hasher type to [`HashMap`] via its last generic
161/// parameter `S`, the default is [`RandomState`] which is also the default type used by the Rust
162/// standard library.
163#[cfg(all(feature = "std", feature = "slotmap"))]
164pub type HashSlotMapGraph<N, E, NI, EI = EdgeIndex, S = RandomState> =
165 HashNodeGraph<N, E, NI, EI, SlotEdgeMap<E, NI, EI>, S>;
166
167/// A type alias for a [`FrozenGraph`] that uses a [`HashMap`] to store
168/// its nodes and a [`SlotMap`] to store its edges.
169///
170/// The default edge index type is [`EdgeIndex`].
171///
172/// # Custom hashers
173///
174/// [`FrozenHashSlotMapGraph`] supports passing a custom hasher type to [`HashMap`] via its last
175/// generic parameter `S`, the default is [`RandomState`] which is also the default type used by the
176/// Rust standard library.
177#[cfg(all(feature = "std", feature = "slotmap"))]
178pub type FrozenHashSlotMapGraph<N, E, NI, EI = EdgeIndex, S = RandomState> =
179 FrozenHashNodeGraph<N, E, NI, EI, SlotEdgeMap<E, NI, EI>, S>;
180
181/// A type alias for a [`Graph`] that uses [`SlotMap`]s to store nodes and edges.
182///
183/// The default node and edge index types are [`NodeIndex`] and [`EdgeIndex`].
184#[cfg(feature = "slotmap")]
185pub type SlotMapGraph<N, E, NI = NodeIndex, EI = EdgeIndex> =
186 Graph<N, E, NI, EI, SlotNodeMap<N, NI, EI>, SlotEdgeMap<E, NI, EI>>;
187
188/// A type alias for a [`FrozenGraph`] that uses [`SlotMap`]s to store nodes and edges.
189///
190/// The default node and edge index types are [`NodeIndex`] and [`EdgeIndex`].
191#[cfg(feature = "slotmap")]
192pub type FrozenSlotMapGraph<N, E, NI = NodeIndex, EI = EdgeIndex> =
193 FrozenGraph<N, E, NI, EI, SlotNodeMap<N, NI, EI>, SlotEdgeMap<E, NI, EI>>;