Create image reference cache.

Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
Lantao Liu
2018-07-26 08:05:44 +00:00
parent cfdf872493
commit 953d67d250
22 changed files with 640 additions and 456 deletions

View File

@@ -41,3 +41,19 @@ func SubtractStringSlice(ss []string, str string) []string {
}
return res
}
// MergeStringSlices merges 2 string slices into one and remove duplicated elements.
func MergeStringSlices(a []string, b []string) []string {
set := map[string]struct{}{}
for _, s := range a {
set[s] = struct{}{}
}
for _, s := range b {
set[s] = struct{}{}
}
var ss []string
for s := range set {
ss = append(ss, s)
}
return ss
}

View File

@@ -46,3 +46,14 @@ func TestSubtractStringSlice(t *testing.T) {
assert.Empty(t, SubtractStringSlice(nil, "hij"))
assert.Empty(t, SubtractStringSlice([]string{}, "hij"))
}
func TestMergeStringSlices(t *testing.T) {
s1 := []string{"abc", "def", "ghi"}
s2 := []string{"def", "jkl", "mno"}
expect := []string{"abc", "def", "ghi", "jkl", "mno"}
result := MergeStringSlices(s1, s2)
assert.Len(t, result, len(expect))
for _, s := range expect {
assert.Contains(t, result, s)
}
}