This commit is contained in:
Henry Schimke
2023-01-05 14:03:37 -06:00
parent f425b89510
commit 0185e80090
7 changed files with 15 additions and 15 deletions

View File

@@ -22,7 +22,6 @@ use std::{cmp, fmt};
use crate::Exceptions; use crate::Exceptions;
static EMPTY_BITS: [u32; 0] = [0; 0];
static LOAD_FACTOR: f32 = 0.75f32; static LOAD_FACTOR: f32 = 0.75f32;
/** /**
@@ -39,7 +38,7 @@ pub struct BitArray {
impl BitArray { impl BitArray {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
bits: EMPTY_BITS.to_vec(), bits: Vec::new(),
size: 0, size: 0,
} }
} }
@@ -327,7 +326,7 @@ impl BitArray {
* @return underlying array of ints. The first element holds the first 32 bits, and the least * @return underlying array of ints. The first element holds the first 32 bits, and the least
* significant bit is bit 0. * significant bit is bit 0.
*/ */
pub fn getBitArray(&self) -> &Vec<u32> { pub fn getBitArray(&self) -> &[u32] {
&self.bits &self.bits
} }

View File

@@ -215,6 +215,7 @@ impl BitMatrix {
Ok(((self.bits[offset] >> (x & 0x1f)) & 1) != 0) Ok(((self.bits[offset] >> (x & 0x1f)) & 1) != 0)
} }
/// Confusingly returns true if the requested element is out of bounds
pub fn check_in_bounds(&self, x: u32, y: u32) -> bool { pub fn check_in_bounds(&self, x: u32, y: u32) -> bool {
(y as usize * self.row_size + (x as usize / 32)) > self.bits.len() (y as usize * self.row_size + (x as usize / 32)) > self.bits.len()
} }

View File

@@ -40,7 +40,7 @@ use super::{BitArray, BitMatrix};
* @author Sean Owen * @author Sean Owen
*/ */
pub struct GlobalHistogramBinarizer { pub struct GlobalHistogramBinarizer {
_luminances: Vec<u8>, //_luminances: Vec<u8>,
width: usize, width: usize,
height: usize, height: usize,
source: Box<dyn LuminanceSource>, source: Box<dyn LuminanceSource>,
@@ -134,7 +134,7 @@ impl GlobalHistogramBinarizer {
pub fn new(source: Box<dyn LuminanceSource>) -> Self { pub fn new(source: Box<dyn LuminanceSource>) -> Self {
Self { Self {
_luminances: vec![0; source.getWidth()], //_luminances: vec![0; source.getWidth()],
width: source.getWidth(), width: source.getWidth(),
height: source.getHeight(), height: source.getHeight(),
black_matrix: OnceCell::new(), black_matrix: OnceCell::new(),

View File

@@ -47,7 +47,7 @@ impl GenericGFPoly {
* or if leading coefficient is 0 and this is not a * or if leading coefficient is 0 and this is not a
* constant polynomial (that is, it is not the monomial "0") * constant polynomial (that is, it is not the monomial "0")
*/ */
pub fn new(field: GenericGFRef, coefficients: &Vec<i32>) -> Result<Self, Exceptions> { pub fn new(field: GenericGFRef, coefficients: &[i32]) -> Result<Self, Exceptions> {
if coefficients.is_empty() { if coefficients.is_empty() {
return Err(Exceptions::IllegalArgumentException(Some( return Err(Exceptions::IllegalArgumentException(Some(
"coefficients.len()".to_owned(), "coefficients.len()".to_owned(),

View File

@@ -76,9 +76,8 @@ impl ReedSolomonDecoder {
if noError { if noError {
return Ok(0); return Ok(0);
} }
let syndrome = match GenericGFPoly::new(self.field, &syndromeCoefficients) { let Ok(syndrome) = GenericGFPoly::new(self.field, &syndromeCoefficients) else {
Ok(res) => res, return Err(Exceptions::ReedSolomonException(None));
Err(_fail) => return Err(Exceptions::ReedSolomonException(None)),
}; };
let sigmaOmega = self.runEuclideanAlgorithm( let sigmaOmega = self.runEuclideanAlgorithm(
&GenericGF::buildMonomial(self.field, twoS as usize, 1), &GenericGF::buildMonomial(self.field, twoS as usize, 1),

View File

@@ -38,7 +38,7 @@ impl ReedSolomonEncoder {
pub fn new(field: GenericGFRef) -> Self { pub fn new(field: GenericGFRef) -> Self {
let n = field; let n = field;
Self { Self {
cachedGenerators: vec![GenericGFPoly::new(n, &vec![1]).unwrap()], cachedGenerators: vec![GenericGFPoly::new(n, &[1]).unwrap()],
field: n, field: n,
} }
} }

View File

@@ -71,20 +71,21 @@ impl StringUtils {
* "SJIS", "UTF8", "ISO8859_1", or the platform default encoding if none * "SJIS", "UTF8", "ISO8859_1", or the platform default encoding if none
* of these can possibly be correct * of these can possibly be correct
*/ */
pub fn guessEncoding(bytes: &[u8], hints: &DecodingHintDictionary) -> String { pub fn guessEncoding(bytes: &[u8], hints: &DecodingHintDictionary) -> &'static str {
let c = StringUtils::guessCharset(bytes, hints); let c = StringUtils::guessCharset(bytes, hints);
if c.name() if c.name()
== encoding::label::encoding_from_whatwg_label("SJIS") == encoding::label::encoding_from_whatwg_label("SJIS")
.unwrap() .unwrap()
.name() .name()
{ {
return "SJIS".to_owned(); "SJIS"
} else if c.name() == encoding::all::UTF_8.name() { } else if c.name() == encoding::all::UTF_8.name() {
return "UTF8".to_owned(); "UTF8"
} else if c.name() == encoding::all::ISO_8859_1.name() { } else if c.name() == encoding::all::ISO_8859_1.name() {
return "ISO8859_1".to_owned(); "ISO8859_1"
}else {
c.name()
} }
return c.name().to_owned();
} }
/** /**