Skip to main content

Neighbor

Struct Neighbor 

Source
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: L

Implementations§

Source§

impl<V, L> Neighbor<V, L>

Source

pub fn new(to: V, label: L) -> Self

Examples found in repository?
crates/competitive/src/graph/graph_base.rs (line 18)
17    fn from((to, label): (V, L)) -> Self {
18        Self::new(to, label)
19    }
More examples
Hide additional examples
crates/competitive/src/graph/adjacency_list.rs (line 19)
18    pub fn add_edge(&mut self, from: usize, to: usize) {
19        self.graph[from].push(Neighbor::new(to, self.esize));
20        self.esize += 1;
21    }
22    pub fn add_undirected_edge(&mut self, u: usize, v: usize) {
23        self.graph[u].push(Neighbor::new(v, self.esize));
24        self.graph[v].push(Neighbor::new(u, self.esize));
25        self.esize += 1;
26    }
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§

Source§

impl<V: Clone, L: Clone> Clone for Neighbor<V, L>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<V: Copy, L: Copy> Copy for Neighbor<V, L>

Source§

impl<V: Debug, L: Debug> Debug for Neighbor<V, L>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<V: Eq, L: Eq> Eq for Neighbor<V, L>

Source§

impl<V, L> From<(V, L)> for Neighbor<V, L>

Source§

fn from((to, label): (V, L)) -> Self

Converts to this type from the input type.
Source§

impl<V: Hash, L: Hash> Hash for Neighbor<V, L>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<V: Ord, L: Ord> Ord for Neighbor<V, L>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl<V: PartialEq, L: PartialEq> PartialEq for Neighbor<V, L>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<V: PartialOrd, L: PartialOrd> PartialOrd for Neighbor<V, L>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<V: PartialEq, L: PartialEq> StructuralPartialEq for Neighbor<V, L>

Auto Trait Implementations§

§

impl<V, L> Freeze for Neighbor<V, L>
where V: Freeze, L: Freeze,

§

impl<V, L> RefUnwindSafe for Neighbor<V, L>

§

impl<V, L> Send for Neighbor<V, L>
where V: Send, L: Send,

§

impl<V, L> Sync for Neighbor<V, L>
where V: Sync, L: Sync,

§

impl<V, L> Unpin for Neighbor<V, L>
where V: Unpin, L: Unpin,

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsTotalOrd for T
where T: PartialOrd,

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PartialOrdExt for T
where T: PartialOrd,

Source§

fn chmin(&mut self, other: T)

Source§

fn chmax(&mut self, other: T)

Source§

fn minmax(self, other: T) -> (T, T)

Source§

impl<T> ToArrayVecScalar for T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.