1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
// Copyright (C) myl7
// SPDX-License-Identifier: Apache-2.0
#![feature(portable_simd)]
use std::fmt::Debug;
use std::ops::{Add, AddAssign};
#[cfg(feature = "byte")]
pub mod byte;
#[cfg(feature = "int")]
pub mod int;
/// Group (mathematics) that can be converted from a byte array
///
/// `Into<[u8; LAMBDA]>` is not used so not included, but implemented by [`byte`] and [`int`]
pub trait Group<const LAMBDA: usize>
where
Self: Add<Output = Self>
+ AddAssign
+ PartialEq
+ Eq
+ Debug
+ Sized
+ Clone
+ Sync
+ Send
+ From<[u8; LAMBDA]>,
{
/// Zero in the group
fn zero() -> Self;
/// Additive inverse in the group, e.g., `-x` for `x` in the integer group
fn add_inverse(self) -> Self;
/// Helper to get the additive inverse if true.
/// Used for expressions like `$(-1)^n x$`, in which `t` can be computed from `n`.
fn add_inverse_if(self, t: bool) -> Self {
if t {
self.add_inverse()
} else {
self
}
}
}