Thunk

Struct Thunk 

Source
pub struct Thunk<I>(/* private fields */);
Expand description

惰性集合

可以进行惰性的二元逻辑运算,中间不计算、不分配内存,最后一次性迭代或收集。

通过 FlatBitSet::thunk 创建。

let s1 = FlatBitSet::<usize>::from_iter([1, 2, 3]);
let s2 = FlatBitSet::<usize>::from_iter([2, 3, 4]);
let s3 = FlatBitSet::<usize>::from_iter([3, 4, 5]);
let thunk = (s1.thunk() ^ s2.thunk()) | (s1.thunk() & s3.thunk());
assert!(thunk.clone().into_iter().eq([1, 3, 4]));
assert_eq!(thunk.collect(), FlatBitSet::<usize>::from_iter([1, 3, 4]));

Implementations§

Source§

impl<I, K, C> Thunk<I>
where I: Iterator<Item = (K, C)>, K: Key, C: Chunk,

Source

pub fn perform_biop<O, I2>(self, other: Thunk<I2>) -> Thunk<BiOpIter<O, I, I2>>
where O: BiOp<C>, I2: Iterator<Item = (K, C)>,

进行惰性二元运算

请使用 Thunk::intersection 之类的方法。 也可以使用 t1 & t2 之类的运算符,作用相同,更为简洁。

Source

pub fn collect(self) -> FlatBitSet<K, C>
where I: Clone,

转换为 FlatBitSet

会预先计算大小,最多只会分配一次。

let s1 = FlatBitSet::<usize>::from_iter([1, 2, 3]);
let s2 = FlatBitSet::<usize>::from_iter([2, 3, 4]);
let thunk = s1.thunk() ^ s2.thunk();
assert_eq!(thunk.collect(), FlatBitSet::<usize>::from_iter([1, 4]));
Source§

impl<I, K, C> Thunk<I>
where I: Iterator<Item = (K, C)>, K: Key, C: Chunk,

Source

pub fn intersection<I2: Iterator<Item = (K, C)>>( self, other: Thunk<I2>, ) -> Thunk<BiOpIter<AndOp, I, I2>>

惰性计算交集

可以使用运算符 t1 & t2,作用相同,更为简洁。

let s1 = FlatBitSet::<usize>::from_iter([1, 2, 3]);
let s2 = FlatBitSet::<usize>::from_iter([2, 3, 4]);
let thunk = s1.thunk().intersection(s2.thunk());
assert!(thunk.into_iter().eq([2, 3]));

可以看看返回新集合的 FlatBitSet::intersection、就地计算的 FlatBitSet::intersection_with 以及返回迭代器的 FlatBitSet::intersection_iter

Source§

impl<I, K, C> Thunk<I>
where I: Iterator<Item = (K, C)>, K: Key, C: Chunk,

Source

pub fn union<I2: Iterator<Item = (K, C)>>( self, other: Thunk<I2>, ) -> Thunk<BiOpIter<OrOp, I, I2>>

惰性计算并集

可以使用运算符 t1 | t2,作用相同,更为简洁。

let s1 = FlatBitSet::<usize>::from_iter([1, 2, 3]);
let s2 = FlatBitSet::<usize>::from_iter([2, 3, 4]);
let thunk = s1.thunk().union(s2.thunk());
assert!(thunk.into_iter().eq([1, 2, 3, 4]));

可以看看返回新集合的 FlatBitSet::union、就地计算的 FlatBitSet::union_with 以及返回迭代器的 FlatBitSet::union_iter

Source§

impl<I, K, C> Thunk<I>
where I: Iterator<Item = (K, C)>, K: Key, C: Chunk,

Source

pub fn symmetric_difference<I2: Iterator<Item = (K, C)>>( self, other: Thunk<I2>, ) -> Thunk<BiOpIter<XorOp, I, I2>>

惰性计算对称差

可以使用运算符 t1 ^ t2,作用相同,更为简洁。

let s1 = FlatBitSet::<usize>::from_iter([1, 2, 3]);
let s2 = FlatBitSet::<usize>::from_iter([2, 3, 4]);
let thunk = s1.thunk().symmetric_difference(s2.thunk());
assert!(thunk.into_iter().eq([1, 4]));

可以看看返回新集合的 FlatBitSet::symmetric_difference、就地计算的 FlatBitSet::symmetric_difference_with 以及返回迭代器的 FlatBitSet::symmetric_difference_iter

Source§

impl<I, K, C> Thunk<I>
where I: Iterator<Item = (K, C)>, K: Key, C: Chunk,

Source

pub fn difference<I2: Iterator<Item = (K, C)>>( self, other: Thunk<I2>, ) -> Thunk<BiOpIter<DiffOp, I, I2>>

惰性计算差集

可以使用运算符 t1 - t2,作用相同,更为简洁。

let s1 = FlatBitSet::<usize>::from_iter([1, 2, 3]);
let s2 = FlatBitSet::<usize>::from_iter([2, 3, 4]);
let thunk = s1.thunk().difference(s2.thunk());
assert!(thunk.into_iter().eq([1]));

可以看看返回新集合的 FlatBitSet::difference、就地计算的 FlatBitSet::difference_with 以及返回迭代器的 FlatBitSet::difference_iter

Trait Implementations§

Source§

impl<I, I2, K, C> BitAnd<Thunk<I2>> for Thunk<I>
where I: Iterator<Item = (K, C)>, I2: Iterator<Item = (K, C)>, K: Key, C: Chunk,

Source§

type Output = Thunk<BiOpIter<AndOp, I, I2>>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Thunk<I2>) -> Self::Output

Performs the & operation. Read more
Source§

impl<I, I2, K, C> BitOr<Thunk<I2>> for Thunk<I>
where I: Iterator<Item = (K, C)>, I2: Iterator<Item = (K, C)>, K: Key, C: Chunk,

Source§

type Output = Thunk<BiOpIter<OrOp, I, I2>>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Thunk<I2>) -> Self::Output

Performs the | operation. Read more
Source§

impl<I, I2, K, C> BitXor<Thunk<I2>> for Thunk<I>
where I: Iterator<Item = (K, C)>, I2: Iterator<Item = (K, C)>, K: Key, C: Chunk,

Source§

type Output = Thunk<BiOpIter<XorOp, I, I2>>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Thunk<I2>) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<I: Clone> Clone for Thunk<I>

Source§

fn clone(&self) -> Thunk<I>

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<I, K, C> IntoIterator for Thunk<I>
where I: Iterator<Item = (K, C)>, K: Key, C: Chunk,

Source§

type Item = K

The type of the elements being iterated over.
Source§

type IntoIter = GenericIter<I, K, C>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<I, I2, K, C> Sub<Thunk<I2>> for Thunk<I>
where I: Iterator<Item = (K, C)>, I2: Iterator<Item = (K, C)>, K: Key, C: Chunk,

Source§

type Output = Thunk<BiOpIter<DiffOp, I, I2>>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Thunk<I2>) -> Self::Output

Performs the - operation. Read more

Auto Trait Implementations§

§

impl<I> Freeze for Thunk<I>
where I: Freeze,

§

impl<I> RefUnwindSafe for Thunk<I>
where I: RefUnwindSafe,

§

impl<I> Send for Thunk<I>
where I: Send,

§

impl<I> Sync for Thunk<I>
where I: Sync,

§

impl<I> Unpin for Thunk<I>
where I: Unpin,

§

impl<I> UnwindSafe for Thunk<I>
where I: UnwindSafe,

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.