public void SortSuffixes() { int[] suffixArray = SuffixArray.Build("banana"); Assert.AreEqual(5, suffixArray[0]); Assert.AreEqual(3, suffixArray[1]); Assert.AreEqual(1, suffixArray[2]); Assert.AreEqual(0, suffixArray[3]); Assert.AreEqual(4, suffixArray[4]); Assert.AreEqual(2, suffixArray[5]); }
// TODO: Check Suffix array get matches method public IEnumerable <Match> FindMatchesAtPosition(byte[] input, int position) { var maxSize = FindLimitations.MaxLength <= 0 ? input.Length : FindLimitations.MaxLength; var maxDisplacement = FindLimitations.MaxDisplacement <= 0 ? input.Length : FindLimitations.MaxDisplacement; if (!_array.IsBuilt) { _array.Build(input, 0, FindLimitations.MinLength); } if (input.Length - position < FindLimitations.MinLength) { yield break; } var cappedSize = Math.Min(maxSize, input.Length - position); var longestMatchSize = FindLimitations.MinLength - 1; var displacement = -1; var offsets = _array.GetOffsets(position, FindLimitations.MinLength, FindLimitations.MinDisplacement, maxDisplacement, (int)FindOptions.UnitSize); foreach (var offset in offsets.OrderByDescending(x => x)) { var matchLength = FindLimitations.MinLength; while (matchLength < cappedSize && input[offset + matchLength] == input[position + matchLength]) { matchLength++; } if (matchLength > longestMatchSize) { longestMatchSize = matchLength; displacement = position - offset; if (longestMatchSize == cappedSize) { break; } } } if (displacement > -1) { yield return(new Match(position, displacement, longestMatchSize)); } }