2020-03-09 20:59:02 +00:00
|
|
|
package lib
|
|
|
|
|
|
|
|
// StringSliceEqual compares two string slices for equality. Both the existence
|
|
|
|
// of the elements and the order of those elements matter for equality. Empty
|
|
|
|
// slices are treated identically to nil slices.
|
|
|
|
func StringSliceEqual(a, b []string) bool {
|
|
|
|
if len(a) != len(b) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < len(a); i++ {
|
|
|
|
if a[i] != b[i] {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
2020-05-27 16:31:10 +00:00
|
|
|
|
|
|
|
// StringSliceMergeSorted takes two string slices that are assumed to be sorted
|
|
|
|
// and does a zipper merge of the two sorted slices, removing any cross-slice
|
|
|
|
// duplicates. If any individual slice contained duplicates those will be
|
|
|
|
// retained.
|
|
|
|
func StringSliceMergeSorted(a, b []string) []string {
|
|
|
|
if len(a) == 0 && len(b) == 0 {
|
|
|
|
return nil
|
|
|
|
} else if len(a) == 0 {
|
|
|
|
return b
|
|
|
|
} else if len(b) == 0 {
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
|
|
|
|
out := make([]string, 0, len(a)+len(b))
|
|
|
|
|
|
|
|
i, j := 0, 0
|
|
|
|
for i < len(a) && j < len(b) {
|
|
|
|
switch {
|
|
|
|
case a[i] < b[j]:
|
|
|
|
out = append(out, a[i])
|
|
|
|
i++
|
|
|
|
case a[i] > b[j]:
|
|
|
|
out = append(out, b[j])
|
|
|
|
j++
|
|
|
|
default:
|
|
|
|
out = append(out, a[i])
|
|
|
|
i++
|
|
|
|
j++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if i < len(a) {
|
|
|
|
out = append(out, a[i:]...)
|
|
|
|
}
|
|
|
|
if j < len(b) {
|
|
|
|
out = append(out, b[j:]...)
|
|
|
|
}
|
|
|
|
return out
|
|
|
|
}
|