github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/pkg/steampipeconfig/versionmap/version_list_map.go (about) 1 package versionmap 2 3 import ( 4 "sort" 5 6 "github.com/Masterminds/semver/v3" 7 "github.com/turbot/steampipe/pkg/steampipeconfig/modconfig" 8 ) 9 10 // VersionListMap is a map keyed by dependency name storing a list of versions for each dependency 11 type VersionListMap map[string]semver.Collection 12 13 func (m VersionListMap) Add(name string, version *semver.Version) { 14 versions := append(m[name], version) 15 // reverse sort the versions 16 sort.Sort(sort.Reverse(versions)) 17 m[name] = versions 18 19 } 20 21 // FlatMap converts the VersionListMap map into a bool map keyed by qualified dependency name 22 func (m VersionListMap) FlatMap() map[string]bool { 23 var res = make(map[string]bool) 24 for name, versions := range m { 25 for _, version := range versions { 26 key := modconfig.BuildModDependencyPath(name, version) 27 res[key] = true 28 } 29 } 30 return res 31 }