Added section comments in the fast Java library.

master
Project Nayuki 1 month ago
parent c255757e8b
commit 2d0d3c9276

@ -34,17 +34,25 @@ import java.util.function.Function;
// A thread-safe cache based on soft references.
final class Memoizer<T,R> {
/*---- Fields ----*/
private final Function<T,R> function;
private Map<T,SoftReference<R>> cache = new ConcurrentHashMap<>();
private Set<T> pending = new HashSet<>();
/*---- Constructor ----*/
// Creates a memoizer based on the given function that takes one input to compute an output.
public Memoizer(Function<T,R> func) {
function = func;
}
/*---- Method ----*/
// Computes function.apply(arg) or returns a cached copy of a previous call.
public R get(T arg) {
// Non-blocking fast path

@ -28,11 +28,16 @@ package io.nayuki.fastqrcodegen;
// and does not depend on the data or error correction level or mask.
final class QrTemplate {
/*---- Constant ----*/
// Use this memoizer to get instances of this class.
public static final Memoizer<Integer,QrTemplate> MEMOIZER
= new Memoizer<>(QrTemplate::new);
/*---- Fields ----*/
private final int version; // In the range [1, 40].
private final int size; // Derived from version.
@ -45,6 +50,9 @@ final class QrTemplate {
private int[] isFunction;
/*---- Constructor ----*/
// Creates a QR Code template for the given version number.
private QrTemplate(int ver) {
if (ver < QrCode.MIN_VERSION || ver > QrCode.MAX_VERSION)
@ -61,6 +69,9 @@ final class QrTemplate {
}
/*---- Methods ----*/
// Reads this object's version field, and draws and marks all function modules.
private void drawFunctionPatterns() {
// Draw horizontal and vertical timing patterns

@ -30,16 +30,24 @@ import java.util.Objects;
// Computes Reed-Solomon error correction codewords for given data codewords.
final class ReedSolomonGenerator {
/*---- Constant ----*/
// Use this memoizer to get instances of this class.
public static final Memoizer<Integer,ReedSolomonGenerator> MEMOIZER
= new Memoizer<>(ReedSolomonGenerator::new);
/*---- Field ----*/
// A table of size 256 * degree, where polynomialMultiply[i][j] = multiply(i, coefficients[j]).
// 'coefficients' is the temporary array computed in the constructor.
private byte[][] polynomialMultiply;
/*---- Constructor ----*/
// Creates a Reed-Solomon ECC generator polynomial for the given degree.
private ReedSolomonGenerator(int degree) {
if (degree < 1 || degree > 255)
@ -72,6 +80,9 @@ final class ReedSolomonGenerator {
}
/*---- Method ----*/
// Returns the error correction codeword for the given data polynomial and this divisor polynomial.
public void getRemainder(byte[] data, int dataOff, int dataLen, byte[] result) {
Objects.requireNonNull(data);
@ -89,6 +100,9 @@ final class ReedSolomonGenerator {
}
/*---- Utility function ----*/
// Returns the product of the two given field elements modulo GF(2^8/0x11D). The arguments and result
// are unsigned 8-bit integers. This could be implemented as a lookup table of 256*256 entries of uint8.
private static int multiply(int x, int y) {

Loading…
Cancel
Save