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