Skip to content

Commit

Permalink
binary search
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcacheux committed Oct 9, 2024
1 parent bf6ad46 commit b0142fa
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions pkg/security/resolvers/sbom/file_querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
package sbom

import (
"cmp"
"slices"
"strings"

"github.com/DataDog/datadog-agent/pkg/security/seclog"
Expand Down Expand Up @@ -44,16 +46,22 @@ func newFileQuerier(report *trivy.Report) fileQuerier {
}
}
}

slices.SortFunc(files, func(a, b fqEntry) int {
return cmp.Compare(a.hash, b.hash)
})

return fileQuerier{files: files}
}

func (fq *fileQuerier) queryHash(hash uint64) *Package {
for _, entry := range fq.files {
if entry.hash == hash {
return entry.pkg
}
i, found := slices.BinarySearchFunc(fq.files, hash, func(entry fqEntry, hash uint64) int {
return cmp.Compare(entry.hash, hash)
})
if !found {
return nil
}
return nil
return fq.files[i].pkg
}

func (fq *fileQuerier) queryFile(path string) *Package {
Expand Down

0 comments on commit b0142fa

Please sign in to comment.