pub struct Neighbor<V, L> {
pub to: V,
pub label: L,
}Expand description
A neighboring vertex and the label of the arc used to reach it.
Fields§
§to: V§label: LImplementations§
Source§impl<V, L> Neighbor<V, L>
impl<V, L> Neighbor<V, L>
Sourcepub fn new(to: V, label: L) -> Self
pub fn new(to: V, label: L) -> Self
Examples found in repository?
More examples
crates/competitive/src/graph/sparse_graph.rs (line 77)
65 fn construct_graph(vsize: usize, edges: Vec<(usize, usize)>) -> SparseGraph<Self> {
66 let mut start: Vec<_> = vec![0usize; vsize + 1];
67 for (from, _) in edges.iter().cloned() {
68 start[from] += 1;
69 }
70 for i in 1..=vsize {
71 start[i] += start[i - 1];
72 }
73 let mut neighbors = Vec::<Neighbor<usize, usize>>::with_capacity(edges.len());
74 let ptr = neighbors.as_mut_ptr();
75 for (id, (from, to)) in edges.iter().cloned().enumerate() {
76 start[from] -= 1;
77 unsafe { ptr.add(start[from]).write(Neighbor::new(to, id)) };
78 }
79 unsafe { neighbors.set_len(edges.len()) };
80 SparseGraph {
81 vsize,
82 start,
83 neighbors,
84 edges,
85 _marker: PhantomData,
86 }
87 }
88}
89
90impl SparseGraphConstruction for UndirectedEdge {
91 fn construct_graph(vsize: usize, edges: Vec<(usize, usize)>) -> SparseGraph<Self> {
92 let mut start: Vec<_> = vec![0usize; vsize + 1];
93 for (from, to) in edges.iter().cloned() {
94 start[to] += 1;
95 start[from] += 1;
96 }
97 for i in 1..=vsize {
98 start[i] += start[i - 1];
99 }
100 let mut neighbors = Vec::<Neighbor<usize, usize>>::with_capacity(edges.len() * 2);
101 let ptr = neighbors.as_mut_ptr();
102 for (id, (from, to)) in edges.iter().cloned().enumerate() {
103 start[from] -= 1;
104 unsafe { ptr.add(start[from]).write(Neighbor::new(to, id)) };
105 start[to] -= 1;
106 unsafe { ptr.add(start[to]).write(Neighbor::new(from, id)) };
107 }
108 unsafe { neighbors.set_len(edges.len() * 2) };
109 SparseGraph {
110 vsize,
111 start,
112 neighbors,
113 edges,
114 _marker: PhantomData,
115 }
116 }
117}
118
119impl SparseGraphConstruction for BidirectionalEdge {
120 fn construct_graph(vsize: usize, edges: Vec<(usize, usize)>) -> SparseGraph<Self> {
121 let mut start: Vec<_> = vec![0usize; vsize + 1];
122 for (from, to) in edges.iter().cloned() {
123 start[to] += 1;
124 start[from] += 1;
125 }
126 for i in 1..=vsize {
127 start[i] += start[i - 1];
128 }
129 let mut neighbors = Vec::<Neighbor<usize, usize>>::with_capacity(edges.len() * 2);
130 let ptr = neighbors.as_mut_ptr();
131 for (id, (from, to)) in edges.iter().cloned().enumerate() {
132 start[from] -= 1;
133 unsafe { ptr.add(start[from]).write(Neighbor::new(to, id * 2)) };
134 start[to] -= 1;
135 unsafe { ptr.add(start[to]).write(Neighbor::new(from, id * 2 + 1)) };
136 }
137 unsafe { neighbors.set_len(edges.len() * 2) };
138 SparseGraph {
139 vsize,
140 start,
141 neighbors,
142 edges,
143 _marker: PhantomData,
144 }
145 }Trait Implementations§
impl<V: Copy, L: Copy> Copy for Neighbor<V, L>
impl<V: Eq, L: Eq> Eq for Neighbor<V, L>
Source§impl<V: Ord, L: Ord> Ord for Neighbor<V, L>
impl<V: Ord, L: Ord> Ord for Neighbor<V, L>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl<V: PartialOrd, L: PartialOrd> PartialOrd for Neighbor<V, L>
impl<V: PartialOrd, L: PartialOrd> PartialOrd for Neighbor<V, L>
impl<V: PartialEq, L: PartialEq> StructuralPartialEq for Neighbor<V, L>
Auto Trait Implementations§
impl<V, L> Freeze for Neighbor<V, L>
impl<V, L> RefUnwindSafe for Neighbor<V, L>where
V: RefUnwindSafe,
L: RefUnwindSafe,
impl<V, L> Send for Neighbor<V, L>
impl<V, L> Sync for Neighbor<V, L>
impl<V, L> Unpin for Neighbor<V, L>
impl<V, L> UnsafeUnpin for Neighbor<V, L>where
V: UnsafeUnpin,
L: UnsafeUnpin,
impl<V, L> UnwindSafe for Neighbor<V, L>where
V: UnwindSafe,
L: UnwindSafe,
Blanket Implementations§
Source§impl<T> AsTotalOrd for Twhere
T: PartialOrd,
impl<T> AsTotalOrd for Twhere
T: PartialOrd,
fn as_total_ord(&self) -> TotalOrd<&T>
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more