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: usizeImplementations§
Source§impl BucketQueue16
impl BucketQueue16
Sourcefn new() -> Self
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 }Sourcefn push(&mut self, value: u16)
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 }fn from_values(values: impl IntoIterator<Item = u16>, len: usize) -> Self
fn pop(&mut self) -> Option<u16>
fn replace(&mut self, value: u16) -> Option<u16>
fn clear(&mut self)
Trait Implementations§
Source§impl Clone for BucketQueue16
impl Clone for BucketQueue16
Auto Trait Implementations§
impl Freeze for BucketQueue16
impl RefUnwindSafe for BucketQueue16
impl Send for BucketQueue16
impl Sync for BucketQueue16
impl Unpin for BucketQueue16
impl UnsafeUnpin for BucketQueue16
impl UnwindSafe for BucketQueue16
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