pub struct DecrementalUsizeSet { /* private fields */ }
Expand description

usize の decremental set。

$\{0, 1, \dots, u-1\}$ で初期化し、要素を取り除く操作を行える。

Complexity

演算時間計算量
new$\Theta(n/w)$
removeamortized $O(1)$
lessamortized $O(1)$
less_equalamortized $O(1)$
greateramortized $O(1)$
greater_equalamortized $O(1)$

空間:$O(n)$ bits.

References

Examples

use nekolib::ds::DecrementalUsizeSet;

let mut set = DecrementalUsizeSet::new(6);
assert_eq!(set.universe_len(), 6);
assert_eq!(set.len(), 6);

set.remove(3);
assert_eq!(set.less(3), Some(2));
assert_eq!(set.less_equal(3), Some(2));
assert_eq!(set.greater(3), Some(4));
assert_eq!(set.greater_equal(3), Some(4));

assert_eq!(set.less(4), Some(2));
assert_eq!(set.less_equal(4), Some(4));
assert_eq!(set.greater(4), Some(5));
assert_eq!(set.greater_equal(4), Some(4));

assert_eq!(set.less(0), None);
assert_eq!(set.greater(5), None);

set.remove(0);
set.remove(5);
assert_eq!(set.less_equal(0), None);
assert_eq!(set.greater_equal(5), None);

assert!(set.contains(4));
assert!(!set.contains(3));

assert_eq!(set.universe_len(), 6);
assert_eq!(set.len(), 3);

Implementations§

source§

impl DecrementalUsizeSet

source

pub fn new(u: usize) -> Self

$S\gets\{0, 1, \dots, u-1\}$ で初期化。

source

pub fn universe_len(&self) -> usize

$u$ を返す。

source

pub fn len(&self) -> usize

$|S|$ を返す。

source

pub fn is_empty(&self) -> bool

$S=\emptyset$ を返す。

source

pub fn contains(&self, i: usize) -> bool

$i\in S$ を返す。

source

pub fn less(&self, i: usize) -> Option<usize>

$\max_{j\lt i}\text{ s.t. }j\in S$ を返す。

source

pub fn less_equal(&self, i: usize) -> Option<usize>

$\max_{j\le i}\text{ s.t. }j\in S$ を返す。

source

pub fn greater(&self, i: usize) -> Option<usize>

$\min_{j\gt i}\text{ s.t. }j\in S$ を返す。

source

pub fn greater_equal(&self, i: usize) -> Option<usize>

$\min_{j\ge i}\text{ s.t. }j\in S$ を返す。

source

pub fn remove(&mut self, i: usize) -> bool

$S\gets S\setminus\{i\}$ で更新する。

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. 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 Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V