private static int[] FindCandidate(byte[] input, int inputIndex, int inputLimit, int inputOffset, int shift, short[] table, int skip) { int candidateIndex = 0; for (inputIndex += 1; inputIndex + BytesBetweenHashLookups(skip) <= inputLimit; inputIndex += BytesBetweenHashLookups(skip++)) { int currentInt = DataHelper.LoadInt(input, inputIndex); int hash = HashBytes(currentInt, shift); candidateIndex = inputOffset + table[hash]; Debug.Assert(candidateIndex >= 0); Debug.Assert(candidateIndex < inputIndex); table[hash] = (short)(inputIndex - inputOffset); if (currentInt == DataHelper.LoadInt(input, candidateIndex)) { break; } } return(new int[] { inputIndex, candidateIndex, skip }); }
private static int[] EmitCopies( byte[] input, int inputOffset, int inputSize, int inputIndex, byte[] output, int outputIndex, short[] table, int shift, int candidateIndex) { int inputBytes; do { int matched = 4 + FindMatchLength(input, candidateIndex + 4, input, inputIndex + 4, inputOffset + inputSize); int offset = inputIndex - candidateIndex; inputIndex += matched; outputIndex = EmitCopy(output, outputIndex, offset, matched); if (inputIndex >= inputOffset + inputSize - INPUT_MARGIN_BYTES) { return(new int[] { inputIndex, outputIndex }); } int previous = DataHelper.LoadInt(input, inputIndex - 1); inputBytes = DataHelper.LoadInt(input, inputIndex); int previousHash = HashBytes(previous, shift); table[previousHash] = (short)(inputIndex - inputOffset - 1); int currentHash = HashBytes(inputBytes, shift); candidateIndex = inputOffset + table[currentHash]; table[currentHash] = (short)(inputIndex - inputOffset); } while (inputBytes == DataHelper.LoadInt(input, candidateIndex)); return(new int[] { inputIndex, outputIndex }); }
private static int ReadTrailer(byte[] data, int index, int bytes) { return(DataHelper.LoadInt(data, index) & _wordmask[bytes]); }