Documentation ¶
Overview ¶
Package frames describes the Frame interface. A set of standard frames are also defined in this package. These are: Fixed, Window, Wild and WildMin.
Index ¶
- Variables
- func NonZero(f Frame) bool
- func TotalLength(f Frame) int
- type Block
- func (bl *Block) Equals(pat patterns.Pattern) bool
- func (bl *Block) Length() (int, int)
- func (bl *Block) NumSequences() int
- func (bl *Block) Save(ls *persist.LoadSaver)
- func (bl *Block) Sequences() []patterns.Sequence
- func (bl *Block) String() string
- func (bl *Block) Test(b []byte) ([]int, int)
- func (bl *Block) TestR(b []byte) ([]int, int)
- type Frame
- func (f Frame) Equals(f1 Frame) bool
- func (f Frame) Linked(prev Frame, maxDistance, maxRange int) (bool, int, int)
- func (f Frame) Match(b []byte) []int
- func (f Frame) MatchN(b []byte, n int) (int, int)
- func (f Frame) MatchNR(b []byte, n int) (int, int)
- func (f Frame) MatchR(b []byte) []int
- func (f Frame) MaxMatches(l int) (int, int, int)
- func (f Frame) Save(ls *persist.LoadSaver)
- func (f Frame) String() string
- type Machine
- func (m Machine) Equals(pat patterns.Pattern) bool
- func (m Machine) Length() (int, int)
- func (m Machine) NumSequences() int
- func (m Machine) Save(ls *persist.LoadSaver)
- func (m Machine) Sequences() []patterns.Sequence
- func (m Machine) String() string
- func (m Machine) Test(b []byte) ([]int, int)
- func (m Machine) TestR(b []byte) ([]int, int)
- type OffType
- type Position
- type Sequencer
- type SigType
- type Signature
- func (seg Signature) Characterise() SigType
- func (s Signature) Contains(s1 Signature) bool
- func (s Signature) Equals(s1 Signature) bool
- func (s Signature) Mirror() Signature
- func (s Signature) OneEnough() bool
- func (s Signature) Segment(dist, rng, cost, repetition int) []Signature
- func (s Signature) String() string
Constants ¶
This section is empty.
Variables ¶
var OffString = [...]string{"B", "P", "S", "E"}
OffString is an exported array of strings representing each of the four offset types
Functions ¶
func NonZero ¶
NonZero checks whether, when converted to simple byte sequences, this frame's pattern is all 0 bytes.
func TotalLength ¶
TotalLength is sum of the maximum length of the enclosed pattern and the maximum offset.
Types ¶
type Block ¶ added in v1.8.0
type Block struct { L []Frame R []Frame Key patterns.Pattern Le int // Pattern length Off int // fixed offset of the Key, relative to the first frame in the block OffR int // fixed offset of the Key, relative to the last frame in the block }
Block combines Frames that are linked to each other by a fixed offset into a single Pattern Patterns within a block must have a single length (i.e. no Choice patterns with varying lengths). Blocks are used within the Machine pattern to cluster frames to identify repetitions & optimise searching.
func (*Block) NumSequences ¶ added in v1.8.0
Blocks are used where sequence matching inefficient
type Frame ¶
Frame encapsulates a pattern with offset information, mediating between the pattern and the bytestream.
func BMHConvert ¶
BMHConvert converts the patterns within a slice of frames to BMH sequences if possible.
func NewFrame ¶
NewFrame generates Fixed, Window, Wild and WildMin frames. The offsets argument controls what type of frame is created:
- for a Wild frame, give no offsets or give a max offset of < 0 and a min of < 1
- for a WildMin frame, give one offset, or give a max offset of < 0 and a min of > 0
- for a Fixed frame, give two offsets that are both >= 0 and that are equal to each other
- for a Window frame, give two offsets that are both >= 0 and that are not equal to each other.
func SwitchFrame ¶
SwitchFrame returns a new frame with a different orientation (for example to allow right-left searching).
func (Frame) Linked ¶
Linked tests whether a frame is linked to a preceding frame (by a preceding or succeding relationship) with an offset and range that is less than the supplied ints. If -1 is given for maxDistance & maxRange, then will check if frame is linked to a preceding frame via a PREV or SUCC relationship. If -1 is given for maxDistance, but not maxRange, then will check if frame linked without regard to distance (only range), this is useful because if give maxRange of 0 you can tell if it is a fixed relationship
func (Frame) Match ¶
Match the enclosed pattern against the byte slice in a L-R direction. Returns a slice of offsets for where a successive match by a related frame should begin.
func (Frame) MatchN ¶
For the nth match (per above), return the offset for successive match by related frame and bytes that can advance to make a successive test by this frame.
func (Frame) MatchNR ¶
For the nth match (per above), return the offset for successive match by related frame and bytes that can advance to make a successive test by this frame.
func (Frame) MatchR ¶
Match the enclosed pattern against the byte slice in a reverse (R-L) direction. Returns a slice of offsets for where a successive match by a related frame should begin.
func (Frame) MaxMatches ¶ added in v1.7.9
MaxMatches returns:
- the max number of times a frame can match, given a byte slice of length 'l'
- the maximum remaining slice length
- the minimum length of a successful pattern match
type Machine ¶ added in v1.8.0
type Machine Signature
A Machine is a segment of a signature that implements the patterns interface
func (Machine) NumSequences ¶ added in v1.8.0
Machines are used where sequence matching inefficient
type OffType ¶
type OffType uint8
OffType is the type of offset
const ( BOF OffType = iota // beginning of file offset PREV // offset from previous frame SUCC // offset from successive frame EOF // end of file offset )
Four offset types are supported
func (OffType) Orientation ¶
Orientation returns the offset type of the frame which must be either BOF, PREV, SUCC or EOF
type Position ¶ added in v1.8.0
position of a key frame in a segment: the length (minimum length in bytes), start and end indexes. The keyframe can span multiple frames in the segment (if they are immediately adjacent and can make sequences) which is why there is a start and end index If length is 0, the segment goes to the frame matcher
type Sequencer ¶
Sequencer turns sequential frames into a set of plain byte sequences. The set represents possible choices.
func NewSequencer ¶
NewSequencer creates a Sequencer (reversed if true).
type Signature ¶
type Signature []Frame
Signature is just a slice of frames.
func Blockify ¶ added in v1.8.0
Blockify takes a signature segment, identifies any blocks within (frames linked by fixed offsets), converts those frames to block patterns within window frames (the window frame of the first frame in the block), but with a new length), and returns a new segment. If no blocks are within a segment, the original segment will be returned.
func (Signature) Characterise ¶ added in v1.8.0
Simple characterisation of a segment: is it relative to the BOF, or the EOF, or is it a prev/succ segment.
func (Signature) Contains ¶
Contains tests whether a signature wholly contains the segments of another signature.