Struct Adjacency

Source
pub struct Adjacency {
    pub id: usize,
    pub to: usize,
}

Fields§

§id: usize§to: usize

Implementations§

Source§

impl Adjacency

Source

pub fn new(id: usize, to: usize) -> Adjacency

Examples found in repository?
crates/competitive/src/graph/sparse_graph.rs (line 89)
77    fn construct_graph(vsize: usize, edges: Vec<(usize, usize)>) -> SparseGraph<Self> {
78        let mut start: Vec<_> = vec![0usize; vsize + 1];
79        for (from, _) in edges.iter().cloned() {
80            start[from] += 1;
81        }
82        for i in 1..=vsize {
83            start[i] += start[i - 1];
84        }
85        let mut elist = Vec::<Adjacency>::with_capacity(edges.len());
86        let ptr = elist.as_mut_ptr();
87        for (id, (from, to)) in edges.iter().cloned().enumerate() {
88            start[from] -= 1;
89            unsafe { ptr.add(start[from]).write(Adjacency::new(id, to)) };
90        }
91        unsafe { elist.set_len(edges.len()) };
92        SparseGraph {
93            vsize,
94            start,
95            elist,
96            edges,
97            _marker: PhantomData,
98        }
99    }
100}
101
102impl SparseGraphConstruction for UndirectedEdge {
103    fn construct_graph(vsize: usize, edges: Vec<(usize, usize)>) -> SparseGraph<Self> {
104        let mut start: Vec<_> = vec![0usize; vsize + 1];
105        for (from, to) in edges.iter().cloned() {
106            start[to] += 1;
107            start[from] += 1;
108        }
109        for i in 1..=vsize {
110            start[i] += start[i - 1];
111        }
112        let mut elist = Vec::<Adjacency>::with_capacity(edges.len() * 2);
113        let ptr = elist.as_mut_ptr();
114        for (id, (from, to)) in edges.iter().cloned().enumerate() {
115            start[from] -= 1;
116            unsafe { ptr.add(start[from]).write(Adjacency::new(id, to)) };
117            start[to] -= 1;
118            unsafe { ptr.add(start[to]).write(Adjacency::new(id, from)) };
119        }
120        unsafe { elist.set_len(edges.len() * 2) };
121        SparseGraph {
122            vsize,
123            start,
124            elist,
125            edges,
126            _marker: PhantomData,
127        }
128    }
129}
130
131impl SparseGraphConstruction for BidirectionalEdge {
132    fn construct_graph(vsize: usize, edges: Vec<(usize, usize)>) -> SparseGraph<Self> {
133        let mut start: Vec<_> = vec![0usize; vsize + 1];
134        for (from, to) in edges.iter().cloned() {
135            start[to] += 1;
136            start[from] += 1;
137        }
138        for i in 1..=vsize {
139            start[i] += start[i - 1];
140        }
141        let mut elist = Vec::<Adjacency>::with_capacity(edges.len() * 2);
142        let ptr = elist.as_mut_ptr();
143        for (id, (from, to)) in edges.iter().cloned().enumerate() {
144            start[from] -= 1;
145            unsafe { ptr.add(start[from]).write(Adjacency::new(id * 2, to)) };
146            start[to] -= 1;
147            unsafe { ptr.add(start[to]).write(Adjacency::new(id * 2 + 1, from)) };
148        }
149        unsafe { elist.set_len(edges.len() * 2) };
150        SparseGraph {
151            vsize,
152            start,
153            elist,
154            edges,
155            _marker: PhantomData,
156        }
157    }

Trait Implementations§

Source§

impl AdjacencyIndex for Adjacency

Source§

type VIndex = usize

Source§

fn vindex(&self) -> Self::VIndex

Source§

impl AdjacencyIndexWithEindex for Adjacency

Source§

type EIndex = usize

Source§

fn eindex(&self) -> Self::EIndex

Source§

impl Clone for Adjacency

Source§

fn clone(&self) -> Adjacency

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Adjacency

Source§

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

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

impl Default for Adjacency

Source§

fn default() -> Adjacency

Returns the “default value” for a type. Read more
Source§

impl Hash for Adjacency

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 Ord for Adjacency

Source§

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

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

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

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

impl PartialEq for Adjacency

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Adjacency

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · 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 · 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 · 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 · 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 Copy for Adjacency

Source§

impl Eq for Adjacency

Source§

impl StructuralPartialEq for Adjacency

Auto Trait Implementations§

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.