github.com/khulnasoft-lab/tunnel-db@v0.0.0-20231117205118-74e1113bd007/pkg/vulnsrc/redhat-oval/cpe.go (about) 1 package redhatoval 2 3 import "sort" 4 5 type CPEMap map[string]struct{} 6 7 func (m CPEMap) Add(cpe string) { 8 m[cpe] = struct{}{} 9 } 10 11 func (m CPEMap) List() CPEList { 12 var cpeList []string 13 for cpe := range m { 14 cpeList = append(cpeList, cpe) 15 } 16 sort.Strings(cpeList) 17 return cpeList 18 } 19 20 type CPEList []string 21 22 func (l CPEList) Index(cpe string) int { 23 for i, c := range l { 24 if c == cpe { 25 return i 26 } 27 } 28 return -1 29 } 30 31 func (l CPEList) Indices(cpes []string) []int { 32 var indices []int 33 for _, cpe := range cpes { 34 indices = append(indices, l.Index(cpe)) 35 } 36 sort.Ints(indices) 37 return indices 38 }