arnaucube
arnaucube/poulpyPublic Self-hosted repository
poulpy/math/src/ring.rs
math/src/ring.rsRaw
 1pub mod impl_u64;
 2
 3use crate::modulus::prime::Prime;
 4use crate::poly::{Poly, PolyRNS};
 5use num_bigint::BigInt;
 6use crate::dft::DFT;
 7
 8
 9pub struct Ring<O>{
10    pub n:usize,
11    pub modulus:Prime<O>,
12    pub dft:Box<dyn DFT<O>>,
13}
14
15impl<O> Ring<O>{
16    pub fn n(&self) -> usize{
17        return self.n
18    }
19
20    pub fn new_poly(&self) -> Poly<u64>{
21        Poly::<u64>::new(self.n())
22    }
23}
24
25pub struct RingRNS<'a, O>(& 'a [Ring<O>]);
26
27impl<O: Copy> RingRNS<'_, O> {
28
29    pub fn n(&self) -> usize{
30        self.0[0].n()
31    }
32
33    pub fn new_polyrns(&self) -> PolyRNS<u64>{
34        PolyRNS::<u64>::new(self.n(), self.level())
35    }
36
37    pub fn max_level(&self) -> usize{
38        self.0.len()-1
39    }
40    
41    pub fn level(&self) -> usize{
42        self.0.len()-1
43    }
44
45    pub fn at_level(&self, level:usize) -> RingRNS<O>{
46        assert!(level <= self.0.len());
47        RingRNS(&self.0[..level+1])
48    }
49}