Skip to main content

BucketQueue16

Struct BucketQueue16 

Source
struct BucketQueue16 {
    counts: Vec<u32>,
    occupied: Vec<u64>,
    summary: [u64; 16],
    top: u16,
    maximum: u16,
    len: usize,
}

Fields§

§counts: Vec<u32>§occupied: Vec<u64>§summary: [u64; 16]§top: u16§maximum: u16§len: usize

Implementations§

Source§

impl BucketQueue16

Source

fn new() -> Self

Examples found in repository?
crates/competitive/src/data_structure/bucket_queue.rs (line 169)
167    fn from_values(values: impl IntoIterator<Item = u16>, len: usize) -> Self {
168        assert!(len <= u32::MAX as usize);
169        let mut result = Self::new();
170        result.len = len;
171        for value in values {
172            result.counts[value as usize] += 1;
173        }
174        for (value, &count) in result.counts.iter().enumerate() {
175            if count != 0 {
176                result.occupied[value / 64] |= 1 << (value % 64);
177            }
178        }
179        for (word, &occupied) in result.occupied.iter().enumerate() {
180            if occupied != 0 {
181                result.summary[word / 64] |= 1 << (word % 64);
182            }
183        }
184        for (word, &summary) in result.summary.iter().enumerate() {
185            if summary != 0 {
186                result.top |= 1 << word;
187            }
188        }
189        if len != 0 {
190            let summary = (u16::BITS - 1 - result.top.leading_zeros()) as usize;
191            let word = summary * 64 + 63 - result.summary[summary].leading_zeros() as usize;
192            result.maximum =
193                (word * 64 + 63 - result.occupied[word].leading_zeros() as usize) as u16;
194        }
195        result
196    }
Source

fn push(&mut self, value: u16)

Examples found in repository?
crates/competitive/src/data_structure/bucket_queue.rs (line 229)
227    fn replace(&mut self, value: u16) -> Option<u16> {
228        if self.len == 0 {
229            self.push(value);
230            return None;
231        }
232        let result = self.maximum;
233        if value == result {
234            return Some(result);
235        }
236
237        let old = result as usize;
238        self.counts[old] -= 1;
239        if self.counts[old] == 0 {
240            let word = old / 64;
241            let summary = word / 64;
242            self.occupied[word] &= !(1 << (old % 64));
243            if self.occupied[word] == 0 {
244                self.summary[summary] &= !(1 << (word % 64));
245                if self.summary[summary] == 0 {
246                    self.top &= !(1 << summary);
247                }
248            }
249        }
250
251        let new = value as usize;
252        if self.counts[new] == 0 {
253            let word = new / 64;
254            self.occupied[word] |= 1 << (new % 64);
255            self.summary[word / 64] |= 1 << (word % 64);
256            self.top |= 1 << (word / 64);
257        }
258        self.counts[new] += 1;
259
260        if value > result || self.counts[old] == 0 {
261            let summary = (u16::BITS - 1 - self.top.leading_zeros()) as usize;
262            let word = summary * 64 + 63 - self.summary[summary].leading_zeros() as usize;
263            self.maximum = (word * 64 + 63 - self.occupied[word].leading_zeros() as usize) as u16;
264        }
265        Some(result)
266    }
Source

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

Source

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

Source

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

Source

fn clear(&mut self)

Trait Implementations§

Source§

impl Clone for BucketQueue16

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 BucketQueue16

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.