aboutsummaryrefslogtreecommitdiff
path: root/v2/searchset.go
diff options
context:
space:
mode:
authorTyler Pirtle <rtp@google.com>2021-08-12 11:12:40 -0700
committerBill Neubauer <wcn@google.com>2022-03-16 15:32:32 -0700
commitb0cb880cf75a9a9a07d3a676b68dce0eee66f7a6 (patch)
treeb1f9efb67e9f2c0a436806e58a20fd03697c4f82 /v2/searchset.go
parentf39a63e84c1fdad417cab8808c76cfbbd48ec410 (diff)
downloadlicenseclassifier-b0cb880cf75a9a9a07d3a676b68dce0eee66f7a6.tar.gz
use a map instead of a slice for the fuseRange filter. It looks like it wants to do some form of random access based on SrcStart / SrcEnd, so this might be a better fit.
<<< b/196234339 was the problem There's an off-by one that I don't entirely understand so I'm trying to split the difference here. The filter variable is currently a slice and we're seeing an off-by-one in production with the amd_vulkan/LICENSE: ``` panic: runtime error: index out of range [3] with length 3 goroutine 1646 [running]: ``` Given that SrcStart / SrcEnd appear to be positions in the text file and the `i` variable seems to move between that range, it seemed natural to replace filter with a map of indexes instead of a slice...this way we can preserve the somewhat random-access pattern that appears to be happening but avoid any range errors. >>> PiperOrigin-RevId: 390415408
Diffstat (limited to 'v2/searchset.go')
-rw-r--r--v2/searchset.go2
1 files changed, 1 insertions, 1 deletions
diff --git a/v2/searchset.go b/v2/searchset.go
index c2c3447..35d4aea 100644
--- a/v2/searchset.go
+++ b/v2/searchset.go
@@ -203,7 +203,7 @@ func (c *Classifier) fuseRanges(origin string, matched matchRanges, confidence f
var claimed matchRanges
errorMargin := int(math.Round(float64(size) * (1.0 - confidence)))
- filter := make([]bool, targetSize)
+ filter := map[int]bool{}
for _, m := range runs {
for i := m.SrcStart; i < m.SrcEnd; i++ {
filter[i] = true