aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/terraform/helper/schema/set.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/helper/schema/set.go')
-rw-r--r--vendor/github.com/hashicorp/terraform/helper/schema/set.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/terraform/helper/schema/set.go b/vendor/github.com/hashicorp/terraform/helper/schema/set.go
index de05f40..cba2890 100644
--- a/vendor/github.com/hashicorp/terraform/helper/schema/set.go
+++ b/vendor/github.com/hashicorp/terraform/helper/schema/set.go
@@ -17,6 +17,12 @@ func HashString(v interface{}) int {
17 return hashcode.String(v.(string)) 17 return hashcode.String(v.(string))
18} 18}
19 19
20// HashInt hashes integers. If you want a Set of integers, this is the
21// SchemaSetFunc you want.
22func HashInt(v interface{}) int {
23 return hashcode.String(strconv.Itoa(v.(int)))
24}
25
20// HashResource hashes complex structures that are described using 26// HashResource hashes complex structures that are described using
21// a *Resource. This is the default set implementation used when a set's 27// a *Resource. This is the default set implementation used when a set's
22// element type is a full resource. 28// element type is a full resource.
@@ -153,6 +159,31 @@ func (s *Set) Equal(raw interface{}) bool {
153 return reflect.DeepEqual(s.m, other.m) 159 return reflect.DeepEqual(s.m, other.m)
154} 160}
155 161
162// HashEqual simply checks to the keys the top-level map to the keys in the
163// other set's top-level map to see if they are equal. This obviously assumes
164// you have a properly working hash function - use HashResource if in doubt.
165func (s *Set) HashEqual(raw interface{}) bool {
166 other, ok := raw.(*Set)
167 if !ok {
168 return false
169 }
170
171 ks1 := make([]string, 0)
172 ks2 := make([]string, 0)
173
174 for k := range s.m {
175 ks1 = append(ks1, k)
176 }
177 for k := range other.m {
178 ks2 = append(ks2, k)
179 }
180
181 sort.Strings(ks1)
182 sort.Strings(ks2)
183
184 return reflect.DeepEqual(ks1, ks2)
185}
186
156func (s *Set) GoString() string { 187func (s *Set) GoString() string {
157 return fmt.Sprintf("*Set(%#v)", s.m) 188 return fmt.Sprintf("*Set(%#v)", s.m)
158} 189}