Skip to main content

BucketQueue8

Struct BucketQueue8 

Source
struct BucketQueue8 {
    counts: [u32; 256],
    occupied: [u64; 4],
    summary: u8,
    maximum: u8,
    len: usize,
}

Fields§

§counts: [u32; 256]§occupied: [u64; 4]§summary: u8§maximum: u8§len: usize

Implementations§

Source§

impl BucketQueue8

Source

fn new() -> Self

Examples found in repository?
crates/competitive/src/data_structure/bucket_queue.rs (line 38)
36    fn from_values(values: impl IntoIterator<Item = u8>, len: usize) -> Self {
37        assert!(len <= u32::MAX as usize);
38        let mut result = Self::new();
39        result.len = len;
40        for value in values {
41            result.counts[value as usize] += 1;
42        }
43        for (value, &count) in result.counts.iter().enumerate() {
44            if count != 0 {
45                result.occupied[value / 64] |= 1 << (value % 64);
46            }
47        }
48        for (word, &occupied) in result.occupied.iter().enumerate() {
49            if occupied != 0 {
50                result.summary |= 1 << word;
51            }
52        }
53        if len != 0 {
54            let word = (u8::BITS - 1 - result.summary.leading_zeros()) as usize;
55            result.maximum =
56                (word * 64 + 63 - result.occupied[word].leading_zeros() as usize) as u8;
57        }
58        result
59    }
Source

fn push(&mut self, value: u8)

Examples found in repository?
crates/competitive/src/data_structure/bucket_queue.rs (line 87)
85    fn replace(&mut self, value: u8) -> Option<u8> {
86        if self.len == 0 {
87            self.push(value);
88            return None;
89        }
90        let result = self.maximum;
91        if value == result {
92            return Some(result);
93        }
94
95        let old = result as usize;
96        self.counts[old] -= 1;
97        if self.counts[old] == 0 {
98            let word = old / 64;
99            self.occupied[word] &= !(1 << (old % 64));
100            if self.occupied[word] == 0 {
101                self.summary &= !(1 << word);
102            }
103        }
104
105        let new = value as usize;
106        if self.counts[new] == 0 {
107            self.occupied[new / 64] |= 1 << (new % 64);
108            self.summary |= 1 << (new / 64);
109        }
110        self.counts[new] += 1;
111
112        if value > result || self.counts[old] == 0 {
113            let word = (u8::BITS - 1 - self.summary.leading_zeros()) as usize;
114            self.maximum = (word * 64 + 63 - self.occupied[word].leading_zeros() as usize) as u8;
115        }
116        Some(result)
117    }
Source

fn from_values(values: impl IntoIterator<Item = u8>, len: usize) -> Self

Source

fn pop(&mut self) -> Option<u8>

Source

fn replace(&mut self, value: u8) -> Option<u8>

Source

fn clear(&mut self)

Trait Implementations§

Source§

impl Clone for BucketQueue8

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 Debug for BucketQueue8

Source§

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

Formats the value using the given formatter. Read more

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> 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> 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.