+use std::ops::BitXor;
use std::fmt::Debug;
-pub trait FiniteNimberBase : std::ops::BitXor<Output=Self> + Clone + Eq + Debug + Sized {
+pub trait FiniteNimberBase : BitXor<Output=Self> + Clone + Eq + Debug + Sized {
type Owned: FiniteNimberBase;
fn to_owned(self) -> Self::Owned;
fn to_owned(self) -> Self::Owned {self}
}
+#[derive(Clone, PartialEq, Eq, Debug)]
+pub struct IntVector(pub Vec<u64>);
+
+impl BitXor for IntVector {
+ type Output = Self;
+
+ fn bitxor(self, other: Self) -> Self {
+ Self(self.0.into_iter().zip(other.0.into_iter()).map(|(a,b)| a ^ b).collect())
+ }
+}
+
+impl FiniteNimberBase for IntVector {
+ type Owned = Self;
+
+ fn to_owned(self) -> Self::Owned {self}
+}
+
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct FiniteNimber<T: FiniteNimberBase> {
n: T,
mod finitenimber;
pub use finitenimber::FiniteNimber;
+pub use finitenimber::IntVector;
#[cfg(test)]
mod tests {
let a = FiniteNimber::new(0b1100u64);
let b = FiniteNimber::new(0b1010u64);
assert_eq!(a + b, FiniteNimber::new(0b0110u64));
+
+ let a = FiniteNimber::new(IntVector(vec![1, 1, 0, 0]));
+ let b = FiniteNimber::new(IntVector(vec![1, 0, 1, 0]));
+ assert_eq!(a + b, FiniteNimber::new(IntVector(vec![0, 1, 1, 0])));
}
}