pulumi/pkg/ast/stable.go
joeduffy e56a34b4e0 Make ast.StableX routines for the various AST maps
We previously used stable enumeration of the various AST maps in the core
visitor, however we now need stable enumeration in more places (like the AWS
backend I am working on).  This change refactors this logic to expose a set
of core ast.StableX routines that stably enumerate maps, and then simply uses
them in place of the existing visitor logic.  (Missing generics right now...)
2016-11-18 15:57:07 -08:00

57 lines
967 B
Go

// Copyright 2016 Marapongo, Inc. All rights reserved.
package ast
import (
"sort"
)
func StableDependencies(d Dependencies) []Name {
deps := make(Names, 0, len(d))
for dep := range d {
deps = append(deps, dep)
}
sort.Sort(deps)
return deps
}
func StableParameters(p Parameters) []string {
params := make([]string, 0, len(p))
for param := range p {
params = append(params, param)
}
sort.Strings(params)
return params
}
func StableServices(s ServiceMap) []Name {
svcs := make(Names, 0, len(s))
for svc := range s {
svcs = append(svcs, svc)
}
sort.Sort(svcs)
return svcs
}
func StableTargets(t Targets) []string {
targets := make([]string, 0, len(t))
for target := range t {
targets = append(targets, target)
}
sort.Strings(targets)
return targets
}
type Names []Name
func (s Names) Len() int {
return len(s)
}
func (s Names) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func (s Names) Less(i, j int) bool {
return s[i] < s[j]
}