Documentation ¶
Index ¶
- Variables
- func Match4(needle, haystack []byte, indices []int) []int
- func Match4String(needle, haystack string, indices []int) []int
- func Match8(needle, haystack []byte, indices []int) []int
- func Match8And4(needle, haystack []byte, indices8 []int, indices4 []int) ([]int, []int)
- func MatchLen(a []byte, b []byte, max int) int
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var UseSse41 bool
var UseSse42 bool
Functions ¶
func Match4 ¶
Match4 will return start indeces of all matches of a 4 byte needle in a haystack that is a multiple of 16 in length. Indeces are returned ordered from index 0 and upwards.
Example ¶
var haystack = []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, } found := Match4(haystack[8:12], haystack, nil) fmt.Printf("%#v", found)
Output: []int{8, 24, 40, 56}
func Match4String ¶
Match4String performs the same operation as Match4 on strings
func Match8 ¶
Match8 will return start indeces of all matches of a 8 byte needle in a haystack that is a multiple of 16 in length. Indeces are returned ordered from index 0 and upwards.
Example ¶
var haystack = []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, } found := Match8(haystack[8:16], haystack, nil) fmt.Printf("%#v", found)
Output: []int{8, 24, 40, 56}
func Match8And4 ¶
Match4And8 will return start indeces of all matches of a 8 byte needle in a haystack that is a multiple of 16 in length. Matches for the first four bytes are returned in the first index, and 8 byte matches are returned in the second. An index that is an 8 byte match will not be present in the 4-byte matches. Indeces are returned ordered from index 0 and upwards.
Example ¶
var haystack = []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, } // Match 12 and 8 bytes f8, f4 := Match8And4(haystack[12:20], haystack, nil, nil) fmt.Printf("Length 8 match: %#v\n", f8) fmt.Printf("Length 4 match: %#v", f4)
Output: Length 8 match: []int{12} Length 4 match: []int{28}
func MatchLen ¶
Example ¶
var data = []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, } // Get match length length := MatchLen(data[10:], data[26:], 16) fmt.Printf("Number of matching bytes: %d, first mismatch %d/%d\n", length, data[10+length], data[26+length])
Output: Number of matching bytes: 6, first mismatch 0/100
Types ¶
This section is empty.