mirror of
https://github.com/anchore/syft.git
synced 2026-11-05 00:46:38 +01:00
chore: refactor basic CPE functionality to its own package (#1436)
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package cpe
|
||||
|
||||
import (
|
||||
"sort"
|
||||
)
|
||||
|
||||
func Merge(a, b []CPE) (result []CPE) {
|
||||
aCPEs := make(map[string]CPE)
|
||||
|
||||
// keep all CPEs from a and create a quick string-based lookup
|
||||
for _, aCPE := range a {
|
||||
aCPEs[aCPE.BindToFmtString()] = aCPE
|
||||
result = append(result, aCPE)
|
||||
}
|
||||
|
||||
// keep all unique CPEs from b
|
||||
for _, bCPE := range b {
|
||||
if _, exists := aCPEs[bCPE.BindToFmtString()]; !exists {
|
||||
result = append(result, bCPE)
|
||||
}
|
||||
}
|
||||
|
||||
sort.Sort(BySpecificity(result))
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user