emitter.go 845 B

12345678910111213141516171819202122232425262728293031323334
  1. package matchfinder
  2. // An absoluteMatch is like a Match, but it stores indexes into the byte
  3. // stream instead of lengths.
  4. type absoluteMatch struct {
  5. // Start is the index of the first byte.
  6. Start int
  7. // End is the index of the byte after the last byte
  8. // (so that End - Start = Length).
  9. End int
  10. // Match is the index of the previous data that matches
  11. // (Start - Match = Distance).
  12. Match int
  13. }
  14. // A matchEmitter manages the output of matches for a MatchFinder.
  15. type matchEmitter struct {
  16. // Dst is the destination slice that Matches are added to.
  17. Dst []Match
  18. // NextEmit is the index of the next byte to emit.
  19. NextEmit int
  20. }
  21. func (e *matchEmitter) emit(m absoluteMatch) {
  22. e.Dst = append(e.Dst, Match{
  23. Unmatched: m.Start - e.NextEmit,
  24. Length: m.End - m.Start,
  25. Distance: m.Start - m.Match,
  26. })
  27. e.NextEmit = m.End
  28. }