diff options
| author | Yuval Adam <_@yuv.al> | 2019-03-19 18:09:57 +0200 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2019-03-19 18:17:51 +0200 |
| commit | 14758a47201477ce0dd277b1f3711609719992c6 (patch) | |
| tree | 56b89c5e8b4d66be24b9be1423d725daad554918 /src/lib.rs | |
| parent | 98c5a14abe4bd13b4d281957763cc27c1d57fc89 (diff) | |
Basic div_round_up
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 25 |
1 files changed, 19 insertions, 6 deletions
@@ -1,9 +1,15 @@ -pub struct GfPoly { +use std::ops::{Add, Sub, Mul}; pub struct BCH { m: i16, t: i16, - prim_poly: u16 + prim_poly: u16, + + n:i16, +} + +fn div_round_up(a: i16, b: i16) -> i16 { + (a + b - 1) / b } impl BCH { @@ -21,7 +27,6 @@ impl BCH { pub fn new(m: i16, t: i16, prim_poly: u16) -> Option<BCH> { let err: u16 = 0; let i: u16; - let words: u16; let genpoly: u32; const MIN_M: i16 = 5; @@ -32,11 +37,18 @@ impl BCH { return None } - Some(BCH { + let n = (1 << m) - 1; + let words = div_round_up(m * t, 32); + let ecc_bytes = div_round_up(m * t, 8); + + let bch = BCH { m, t, - prim_poly - }) + prim_poly, + n + }; + + Some(bch) } pub fn decode(self) -> i16{ @@ -61,4 +73,5 @@ mod tests { let bch = BCH::new(16, 0, 0); assert_eq!(bch.is_none(), true); } + } |
