forked from andybalholm/brotli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
matchfinder: factor out matchEmitter
- Loading branch information
1 parent
349ed2f
commit c506503
Showing
2 changed files
with
47 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package matchfinder | ||
|
||
// An absoluteMatch is like a Match, but it stores indexes into the byte | ||
// stream instead of lengths. | ||
type absoluteMatch struct { | ||
// Start is the index of the first byte. | ||
Start int | ||
|
||
// End is the index of the byte after the last byte | ||
// (so that End - Start = Length). | ||
End int | ||
|
||
// Match is the index of the previous data that matches | ||
// (Start - Match = Distance). | ||
Match int | ||
} | ||
|
||
// A matchEmitter manages the output of matches for a MatchFinder. | ||
type matchEmitter struct { | ||
// Dst is the destination slice that Matches are added to. | ||
Dst []Match | ||
|
||
// NextEmit is the index of the next byte to emit. | ||
NextEmit int | ||
} | ||
|
||
func (e *matchEmitter) emit(m absoluteMatch) { | ||
e.Dst = append(e.Dst, Match{ | ||
Unmatched: m.Start - e.NextEmit, | ||
Length: m.End - m.Start, | ||
Distance: m.Start - m.Match, | ||
}) | ||
e.NextEmit = m.End | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters