Skip to main content

RingVector

Struct RingVector 

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

Vector of ring elements over Z_m.

Implementations§

Source§

impl RingVector

Source

pub fn new(elements: Vec<RingElement>) -> Self

Create a new vector from a slice of ring elements.

§Panics

Panics if the vector is empty or elements have different moduli.

Source

pub fn try_new(elements: Vec<RingElement>) -> Result<Self, RingError>

Try to create a new vector from ring elements.

§Errors

Returns RingError::DimensionMismatch if the vector is empty and RingError::ModulusMismatch if the elements do not share the same modulus.

Source

pub fn zero(len: usize, modulus: u64) -> Self

Create a zero vector of given length.

§Panics

Panics if len == 0.

Source

pub fn from_values(values: &[u64], modulus: u64) -> Self

Create a vector from raw values.

Source

pub const fn len(&self) -> usize

Get the length of the vector.

Source

pub const fn is_empty(&self) -> bool

Check if vector is empty.

Source

pub const fn modulus(&self) -> u64

Get the modulus.

Source

pub fn get(&self, index: usize) -> RingElement

Get element at index.

§Panics

Panics if index is out of bounds.

Source

pub fn set(&mut self, index: usize, value: RingElement)

Set element at index.

§Panics

Panics if index is out of bounds or if value has a different modulus.

Source

pub fn elements(&self) -> &[RingElement]

Return the underlying elements as a slice.

Source

pub fn dot(&self, other: &Self) -> RingElement

Compute dot product with another vector.

§Panics

Panics if vectors have different lengths or different moduli.

Source

pub fn try_dot(&self, other: &Self) -> Result<RingElement, RingError>

Compute a checked dot product with another vector.

§Errors

Returns RingError::DimensionMismatch or RingError::ModulusMismatch when the operands are incompatible.

Source

pub fn scale(&self, scalar: RingElement) -> Self

Scalar multiplication.

§Panics

Panics if scalar has a different modulus.

Source

pub fn scale_by(&self, scalar: u64) -> Self

Scale by a raw value.

Source

pub fn try_add(&self, other: &Self) -> Result<Self, RingError>

Compute a checked element-wise sum.

§Errors

Returns RingError::DimensionMismatch or RingError::ModulusMismatch when the operands are incompatible.

Source

pub fn try_sub(&self, other: &Self) -> Result<Self, RingError>

Compute a checked element-wise difference.

§Errors

Returns RingError::DimensionMismatch or RingError::ModulusMismatch when the operands are incompatible.

Source

pub fn iter(&self) -> impl Iterator<Item = &RingElement>

Get iterator over elements.

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut RingElement>

Get mutable iterator over elements.

Source

pub fn to_values(&self) -> Vec<u64>

Convert to Vec of raw values.

Trait Implementations§

Source§

impl<'b> Add<&'b RingVector> for &RingVector

Source§

type Output = RingVector

The resulting type after applying the + operator.
Source§

fn add(self, other: &'b RingVector) -> RingVector

Performs the + operation. Read more
Source§

impl Add for RingVector

Source§

type Output = RingVector

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> Self

Performs the + operation. Read more
Source§

impl Clone for RingVector

Source§

fn clone(&self) -> RingVector

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 Debug for RingVector

Source§

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

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

impl<'de> Deserialize<'de> for RingVector

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Index<usize> for RingVector

Source§

type Output = RingElement

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<usize> for RingVector

Source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl Neg for RingVector

Source§

type Output = RingVector

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl PartialEq for RingVector

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for RingVector

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<'b> Sub<&'b RingVector> for &RingVector

Source§

type Output = RingVector

The resulting type after applying the - operator.
Source§

fn sub(self, other: &'b RingVector) -> RingVector

Performs the - operation. Read more
Source§

impl Sub for RingVector

Source§

type Output = RingVector

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> Self

Performs the - operation. Read more
Source§

impl Eq for RingVector

Source§

impl StructuralPartialEq for RingVector

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,