Skip to main content

TriVec

Struct TriVec 

Source
pub struct TriVec { /* private fields */ }
Expand description

位切片的三值向量。

相等语义按值:两个 TriVec 只要长度与逐元素取值一致就相等, 与内部是否分配了全零的 unknowns 平面无关。

Implementations§

Source§

impl TriVec

Source

pub fn from_binary(ones: Vec<u64>, len: usize) -> Self

零拷贝接管二进制位平面:ones 的位为 1 表示 True,0 表示 False。

ones 必须至少覆盖 len 位;多余字会被截断,末尾多余位会被清零。

§Panics

ones 字数不足时 panic;边界输入请用 TriVec::try_from_binary。

Source

pub fn try_from_binary(ones: Vec<u64>, len: usize) -> Result<Self, TriVecError>

同 TriVec::from_binary,但字数不足时返回错误。

Source

pub fn from_bools(bits: &[bool]) -> Self

从 bool 切片打包。

Source

pub fn from_ternary(values: &[Ternary]) -> Self

从标量三值切片打包。

Source

pub fn to_bools(&self) -> Option<Vec<bool>>

若全部是二值,解包成 bool;含 Unknown 时返回 None。

Source

pub fn len(&self) -> usize

长度。

Source

pub fn is_empty(&self) -> bool

是否为空。

Source

pub fn words(&self) -> usize

位平面字数。

Source

pub fn is_binary(&self) -> bool

是否为纯二值(没有 Unknown)。

Source

pub fn ones(&self) -> &[u64]

ones 位平面(只读)。

Source

pub fn unknowns(&self) -> Option<&[u64]>

unknowns 位平面;None 表示纯二值。

Source

pub fn get(&self, i: usize) -> Ternary

取第 i 个三值。

§Panics

i 越界时 panic;边界输入请用 TriVec::try_get。

Source

pub fn try_get(&self, i: usize) -> Result<Ternary, TriVecError>

取第 i 个三值;越界返回错误。

Source

pub fn set(&mut self, i: usize, value: Ternary)

写第 i 个三值;首次写 Unknown 时分配 unknown 平面。

§Panics

i 越界时 panic;边界输入请用 TriVec::try_set。

Source

pub fn try_set(&mut self, i: usize, value: Ternary) -> Result<(), TriVecError>

写第 i 个三值;越界返回错误。

Source

pub fn count_unknowns(&self) -> usize

Unknown 的个数。

Source

pub fn word(&self, word: usize) -> TriBit

取整个字(64 路)的位并行表示。

§Panics

字索引越界时 panic;边界输入请用 TriVec::try_word。

Source

pub fn try_word(&self, word: usize) -> Result<TriBit, TriVecError>

取整个字的位并行表示;越界返回错误。

Source

pub fn not(&mut self)

原地取反:True/False 互换,Unknown 不变。

Source

pub fn and_assign( &mut self, other: &Self, alg: Algebra, ) -> Result<(), ShapeError>

原地与。K3/Ł3 用格序,B3 用毒值。

Source

pub fn or_assign( &mut self, other: &Self, alg: Algebra, ) -> Result<(), ShapeError>

原地或。K3/Ł3 用格序,B3 用毒值。

Trait Implementations§

Source§

impl Clone for TriVec

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TriVec

Source§

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

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

impl Eq for TriVec

Source§

impl PartialEq for TriVec

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.