github.com/kastenhq/syft@v0.0.0-20230821225854-0710af25cdbe/syft/cpe/merge_cpes.go (about)

     1  package cpe
     2  
     3  import (
     4  	"sort"
     5  )
     6  
     7  func Merge(a, b []CPE) (result []CPE) {
     8  	aCPEs := make(map[string]CPE)
     9  
    10  	// keep all CPEs from a and create a quick string-based lookup
    11  	for _, aCPE := range a {
    12  		aCPEs[aCPE.BindToFmtString()] = aCPE
    13  		result = append(result, aCPE)
    14  	}
    15  
    16  	// keep all unique CPEs from b
    17  	for _, bCPE := range b {
    18  		if _, exists := aCPEs[bCPE.BindToFmtString()]; !exists {
    19  			result = append(result, bCPE)
    20  		}
    21  	}
    22  
    23  	sort.Sort(BySpecificity(result))
    24  	return result
    25  }