(request MatchRequest)
| 155 | } |
| 156 | |
| 157 | func (m *Matcher) scan(request MatchRequest) MatchResult { |
| 158 | startedAt := time.Now() |
| 159 | |
| 160 | numChunks := len(request.chunks) |
| 161 | if numChunks == 0 { |
| 162 | m := EmptyMerger(request.revision) |
| 163 | return MatchResult{m, m, false} |
| 164 | } |
| 165 | pattern := request.pattern |
| 166 | passMerger := PassMerger(&request.chunks, m.tac, request.revision, pattern.startIndex) |
| 167 | if pattern.IsEmpty() { |
| 168 | return MatchResult{passMerger, passMerger, false} |
| 169 | } |
| 170 | |
| 171 | minIndex := request.chunks[0].items[0].Index() |
| 172 | maxIndex := request.chunks[numChunks-1].lastIndex(minIndex) |
| 173 | cancelled := util.NewAtomicBool(false) |
| 174 | |
| 175 | numWorkers := min(m.partitions, numChunks) |
| 176 | var nextChunk atomic.Int32 |
| 177 | resultChan := make(chan partialResult, numWorkers) |
| 178 | countChan := make(chan int, numChunks) |
| 179 | waitGroup := sync.WaitGroup{} |
| 180 | |
| 181 | for idx := range numWorkers { |
| 182 | waitGroup.Add(1) |
| 183 | if m.slab[idx] == nil { |
| 184 | m.slab[idx] = util.MakeSlab(slab16Size, slab32Size) |
| 185 | } |
| 186 | go func(idx int, slab *util.Slab) { |
| 187 | defer waitGroup.Done() |
| 188 | var matches []Result |
| 189 | for { |
| 190 | ci := int(nextChunk.Add(1)) - 1 |
| 191 | if ci >= numChunks { |
| 192 | break |
| 193 | } |
| 194 | chunkMatches := request.pattern.Match(request.chunks[ci], slab) |
| 195 | matches = append(matches, chunkMatches...) |
| 196 | if cancelled.Get() { |
| 197 | return |
| 198 | } |
| 199 | countChan <- len(chunkMatches) |
| 200 | } |
| 201 | if m.sort && request.pattern.sortable { |
| 202 | m.sortBuf[idx] = radixSortResults(matches, m.tac, m.sortBuf[idx]) |
| 203 | } |
| 204 | resultChan <- partialResult{idx, matches} |
| 205 | }(idx, m.slab[idx]) |
| 206 | } |
| 207 | |
| 208 | wait := func() bool { |
| 209 | cancelled.Set(true) |
| 210 | waitGroup.Wait() |
| 211 | return true |
| 212 | } |
| 213 | |
| 214 | count := 0 |
no test coverage detected