-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.go
33 lines (27 loc) · 639 Bytes
/
search.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main
type SearchResult struct {
rowRef *Row
startI uint
rowI uint
}
// SearchRows concurrently searches for a given query string in a slice of Rows.
// It returns a channel of search results.
func SearchRows(rows []Row, q string) <-chan SearchResult {
results := make(chan SearchResult)
go func() {
defer close(results)
for i := range rows {
y := rows[i].RenderIndexOf(q, 0)
// Handle multiple search terms in one Row.
for y != -1 {
results <- SearchResult{
rowRef: &rows[i],
startI: uint(y),
rowI: uint(i),
}
y = rows[i].RenderIndexOf(q, y+1)
}
}
}()
return results
}