Struct BTreeCounter

Source
pub struct BTreeCounter<T> { /* private fields */ }

Implementations§

Source§

impl<T> BTreeCounter<T>

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn keys(&self) -> Keys<'_, T, usize>

Source

pub fn values(&self) -> Values<'_, T, usize>

Source

pub fn iter(&self) -> Iter<'_, T, usize>

Examples found in repository?
crates/competitive/src/data_structure/counter.rs (line 150)
149    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
150        f.debug_map().entries(self.iter()).finish()
151    }
Source

pub fn range<Q, R>(&self, range: R) -> Range<'_, T, usize>
where Q: Ord, R: RangeBounds<Q>, T: Borrow<Q> + Ord,

Source§

impl<T> BTreeCounter<T>
where T: Ord,

Source

pub fn new() -> Self

Source

pub fn clear(&mut self)

Source

pub fn get(&self, item: &T) -> usize

Source

pub fn add(&mut self, item: T)

Examples found in repository?
crates/competitive/src/data_structure/counter.rs (line 231)
229    fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
230        for item in iter {
231            self.add(item)
232        }
233    }
Source

pub fn add_count(&mut self, item: T, count: usize)

Examples found in repository?
crates/competitive/src/data_structure/counter.rs (line 202)
201    pub fn add(&mut self, item: T) {
202        self.add_count(item, 1)
203    }
204    pub fn add_count(&mut self, item: T, count: usize) {
205        *self.map.entry(item).or_default() += count;
206    }
207    pub fn remove(&mut self, item: &T) -> bool {
208        self.remove_count(item, 1) == 1
209    }
210    pub fn remove_count(&mut self, item: &T, count: usize) -> usize {
211        if let Some(cnt) = self.map.get_mut(item) {
212            if *cnt <= count {
213                let cnt = *cnt;
214                self.map.remove(item);
215                cnt
216            } else {
217                *cnt -= count;
218                count
219            }
220        } else {
221            0
222        }
223    }
224}
225impl<T> Extend<T> for BTreeCounter<T>
226where
227    T: Ord,
228{
229    fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
230        for item in iter {
231            self.add(item)
232        }
233    }
234}
235impl<T> Extend<(T, usize)> for BTreeCounter<T>
236where
237    T: Ord,
238{
239    fn extend<I: IntoIterator<Item = (T, usize)>>(&mut self, iter: I) {
240        for (item, count) in iter {
241            self.add_count(item, count)
242        }
243    }
Source

pub fn remove(&mut self, item: &T) -> bool

Source

pub fn remove_count(&mut self, item: &T, count: usize) -> usize

Examples found in repository?
crates/competitive/src/data_structure/counter.rs (line 208)
207    pub fn remove(&mut self, item: &T) -> bool {
208        self.remove_count(item, 1) == 1
209    }

Trait Implementations§

Source§

impl<T: Clone> Clone for BTreeCounter<T>

Source§

fn clone(&self) -> BTreeCounter<T>

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<T> Debug for BTreeCounter<T>
where T: Debug,

Source§

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

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

impl<T> Default for BTreeCounter<T>
where T: Ord,

Source§

fn default() -> Self

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

impl<T> Extend<(T, usize)> for BTreeCounter<T>
where T: Ord,

Source§

fn extend<I: IntoIterator<Item = (T, usize)>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<T> Extend<T> for BTreeCounter<T>
where T: Ord,

Source§

fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<T> FromIterator<(T, usize)> for BTreeCounter<T>
where T: Ord,

Source§

fn from_iter<I: IntoIterator<Item = (T, usize)>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<T> FromIterator<T> for BTreeCounter<T>
where T: Ord,

Source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more

Auto Trait Implementations§

§

impl<T> Freeze for BTreeCounter<T>

§

impl<T> RefUnwindSafe for BTreeCounter<T>
where T: RefUnwindSafe,

§

impl<T> Send for BTreeCounter<T>
where T: Send,

§

impl<T> Sync for BTreeCounter<T>
where T: Sync,

§

impl<T> Unpin for BTreeCounter<T>

§

impl<T> UnwindSafe for BTreeCounter<T>
where T: RefUnwindSafe,

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