Trait hi_sparse_bitset::BitSetInterface
source · pub unsafe trait BitSetInterface: BitSetBase + LevelMasksIterExt + IntoIterator<IntoIter = CachingIndexIter<Self>> + Sized {
// Provided methods
fn block_iter(&self) -> CachingBlockIter<&Self> ⓘ { ... }
fn iter(&self) -> CachingIndexIter<&Self> ⓘ { ... }
fn into_block_iter(self) -> CachingBlockIter<Self> ⓘ { ... }
fn contains(&self, index: usize) -> bool { ... }
fn is_empty(&self) -> bool { ... }
}
Expand description
Bitset interface.
Implemented for bitset references and optionally for values. So as argument - accept BitSetInterface by value. (Act as kinda forwarding reference in C++)
§Traversing
CachingBlockIter and CachingIndexIter have specialized for_each()
implementation and traverse()
.
Like with most Rust iterators, traversing1 is somewhat faster then iteration. In this particular case, it has noticeable difference in micro-benchmarks. Remember, that iteration is already super-fast, and any tiny change become important at that scale. Hence, this will have effect in really tight loops (like incrementing counter).
§Implementation
Consider using impl_bitset! instead of implementing it manually.
Implementing BitSetInterface for T will make it passable by value to apply, reduce. That may be not what you want, if your type contains heavy data, or your LevelMasksIterExt implementation depends on *Self being stable during iteration. If that is the case - implement only for &T.
Under “traverse” we understand function application for each element of bitset. ↩
Provided Methods§
fn block_iter(&self) -> CachingBlockIter<&Self> ⓘ
fn iter(&self) -> CachingIndexIter<&Self> ⓘ
fn into_block_iter(self) -> CachingBlockIter<Self> ⓘ
fn contains(&self, index: usize) -> bool
sourcefn is_empty(&self) -> bool
fn is_empty(&self) -> bool
O(1) if TRUSTED_HIERARCHY, O(N) otherwise.