コード例 #1
0
        /// <summary>
        ///     This method creates the windows and finds longest match from lookahead in history. If one
        ///     longer than 2 is found, then a PointerByte is returned indicating where the match is relative
        ///     to the current index.
        /// </summary>
        /// <returns> EncodedLZByte that is either a pointer to match or raw data. </returns>
        public EncodedLZByte Slide()
        {
            if (AtEnd())
            {
                return(null);
            }

            var history   = LoadHistory(_historyLength);
            var lookAhead = LoadLookAhead(_lookAheadLength);

            MatchPointer match;

            try {
                match = findLongestMatch(history, lookAhead);
            }
            catch (Exception exception) {
                // If the loading went bad
                if (exception is DllNotFoundException ||
                    exception is MarshalDirectiveException)
                {
                    // Change to using the C# implementation
                    findLongestMatch = FindMatchingBytes.FindLongestMatch;
                    match            = findLongestMatch(history, lookAhead);
                }
                else
                {
                    throw;
                }
            }

            EncodedLZByte r;

            if (match.Length != 0)
            {
                r              = new PointerByte(history.Length - match.Index - 1, match.Length - 1);
                _currentIndex += match.Length;
            }
            else
            {
                r = new RawByte(lookAhead[0]);
                _currentIndex++;
            }

            return(r);
        }
コード例 #2
0
 public SlidingWindow(byte[] bytes)
 {
     _bytes           = bytes;
     findLongestMatch = CFindMatchingBytes.FindLongestMatch;
 }