MCPcopy Index your code
hub / github.com/coder/coder / extractQueryTrigrams

Function extractQueryTrigrams

agent/filefinder/query.go:68–86  ·  view source on GitHub ↗
(tokens [][]byte)

Source from the content-addressed store, hash-verified

66}
67
68func extractQueryTrigrams(tokens [][]byte) []uint32 {
69 seen := make(map[uint32]struct{})
70 for _, tok := range tokens {
71 if len(tok) < 3 {
72 continue
73 }
74 for i := 0; i <= len(tok)-3; i++ {
75 seen[packTrigram(tok[i], tok[i+1], tok[i+2])] = struct{}{}
76 }
77 }
78 if len(seen) == 0 {
79 return nil
80 }
81 result := make([]uint32, 0, len(seen))
82 for g := range seen {
83 result = append(result, g)
84 }
85 return result
86}
87
88func packTrigram(a, b, c byte) uint32 {
89 return uint32(toLowerASCII(a))<<16 | uint32(toLowerASCII(b))<<8 | uint32(toLowerASCII(c))

Callers 1

newQueryPlanFunction · 0.85

Calls 1

packTrigramFunction · 0.85

Tested by

no test coverage detected