pub struct XorBasis { /* private fields */ }
Expand description
Basis of xor operation.
Implementations§
Source§impl XorBasis
impl XorBasis
Sourcepub fn reduce(&self, x: u64) -> (u64, u64)
pub fn reduce(&self, x: u64) -> (u64, u64)
Return (reduced basis, coordinate). Coordinate means if i-th bit is 1, x was reduced by i-th inserted basis.
Examples found in repository?
crates/competitive/src/algorithm/xorbasis.rs (line 27)
26 pub fn insert(&mut self, x: u64) -> bool {
27 let (y, coord) = self.reduce(x);
28 if y != 0 {
29 self.bases.push((y, coord, x));
30 }
31 y != 0
32 }
33 /// Return coordinate if element can be consisted by current basis.
34 pub fn find(&self, x: u64) -> Option<u64> {
35 let (y, coord) = self.reduce(x);
36 if y == 0 { Some(coord) } else { None }
37 }
38 /// Return coordinate if element can be consisted by current basis.
39 pub fn basis(&self, x: u64) -> Option<Vec<u64>> {
40 let (y, coord) = self.reduce(x);
41 if y == 0 {
42 Some(
43 self.bases
44 .iter()
45 .enumerate()
46 .filter_map(|(i, (_, _, b))| {
47 if coord & (1 << i) != 0 {
48 Some(*b)
49 } else {
50 None
51 }
52 })
53 .collect(),
54 )
55 } else {
56 None
57 }
58 }
Sourcepub fn insert(&mut self, x: u64) -> bool
pub fn insert(&mut self, x: u64) -> bool
Return true if inserted element cannot be consisted by current basis and be added as a new basis. Return false if inserted element can be consisted by current basis.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for XorBasis
impl RefUnwindSafe for XorBasis
impl Send for XorBasis
impl Sync for XorBasis
impl Unpin for XorBasis
impl UnwindSafe for XorBasis
Blanket Implementations§
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