pub struct IndexKey { /* private fields */ }Expand description
A bit-packed multi-index key.
A key carries the width it was built for, and the storage arm is a function of that width, so two keys are equal exactly when they were built for the same width and hold the same bits. Arms wider than 128 bits are boxed so a narrow key does not pay the footprint of the widest arm.
The contents are deliberately opaque. A key can only be produced by
FlatIndexer::encode or KeyBuilder::finish, both of which establish
that its value occupies exactly width_bits bits. KeyBuilder::push
relies on that invariant to place a sub-key without masking or truncation,
and it is not one a caller could be asked to maintain by hand.
§Examples
use tensor4all_core::index_key::FlatIndexer;
let indexer = FlatIndexer::try_new(&[2, 2]).unwrap();
let a = indexer.encode(&[1, 0]).unwrap();
let b = indexer.encode(&[0, 1]).unwrap();
assert_ne!(a, b);
assert_eq!(a, indexer.encode(&[1, 0]).unwrap());
assert_eq!(a.width_bits(), 2);Implementations§
Source§impl IndexKey
impl IndexKey
Sourcepub fn width_bits(&self) -> u64
pub fn width_bits(&self) -> u64
The width this key was built for, in bits.
This is what KeyBuilder::push consumes, so a sub-key can never be
appended under a width that disagrees with its contents.
§Examples
use tensor4all_core::index_key::FlatIndexer;
let indexer = FlatIndexer::try_new(&[3, 4]).unwrap();
assert_eq!(indexer.width_bits(), 4);
assert_eq!(indexer.encode(&[2, 3]).unwrap().width_bits(), 4);Trait Implementations§
impl Eq for IndexKey
impl StructuralPartialEq for IndexKey
Auto Trait Implementations§
impl Freeze for IndexKey
impl RefUnwindSafe for IndexKey
impl Send for IndexKey
impl Sync for IndexKey
impl Unpin for IndexKey
impl UnsafeUnpin for IndexKey
impl UnwindSafe for IndexKey
Blanket Implementations§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
U: Sized,
fn as_<T>(self) -> Twhere
T: CastFrom<U>,
U: Sized,
self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read moreSource§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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
impl<T, U> Imply<T> for U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more