Ejemplo n.º 1
0
        private unsafe long EncodeCopyForBestMatch(ulong hash, long candidateStart, long unencodedStart, long unencodedSize, byte *newDataPtr, ByteBuffer newData)
        {
            BlockHash.Match bestMatch = new BlockHash.Match();

            dictionary.FindBestMatch(hash, candidateStart, unencodedStart, unencodedSize, newDataPtr, newData, ref bestMatch);
            if (bestMatch.size < minBlockSize)
            {
                return(0);
            }

            if (bestMatch.tOffset > 0)
            {
                newData.Position = (int)unencodedStart;
                windowEncoder?.Add(newData.ReadBytesAsSpan((int)bestMatch.tOffset));
            }

            windowEncoder?.Copy((int)bestMatch.sOffset, (int)bestMatch.size);

            return(bestMatch.size + bestMatch.tOffset);
        }
Ejemplo n.º 2
0
        //currently does not support looking in target
        //only the dictionary
        long EncodeCopyForBestMatch(ulong hash, long candidateStart, long unencodedStart, long unencodedSize)
        {
            BlockHash.Match bestMatch = new BlockHash.Match();

            dictionary.FindBestMatch(hash, candidateStart, unencodedStart, unencodedSize, newData, bestMatch);

            if (bestMatch.Size < MinBlockSize)
            {
                return(0);
            }

            if (bestMatch.TargetOffset > 0)
            {
                newData.Position = unencodedStart;
                windowEncoder.Add(newData.ReadBytes((int)bestMatch.TargetOffset));
            }

            windowEncoder.Copy((int)bestMatch.SourceOffset, (int)bestMatch.Size);

            return(bestMatch.Size + bestMatch.TargetOffset);
        }