1

Add intersection and union functions for string arrays

This commit is contained in:
stephenmk 2023-01-22 14:32:45 -06:00
parent 56f9895967
commit 73fb992865
No known key found for this signature in database
GPG Key ID: B6DA730DB06235F1

View File

@ -262,6 +262,39 @@ func hasString(needle string, haystack []string) bool {
return false return false
} }
func intersection(s1, s2 []string) []string {
s := []string{}
m := make(map[string]bool)
for _, e := range s1 {
m[e] = true
}
for _, e := range s2 {
if m[e] {
s = append(s, e)
m[e] = false
}
}
return s
}
func union(s1, s2 []string) []string {
s := []string{}
m := make(map[string]bool)
for _, e := range s1 {
if !m[e] {
s = append(s, e)
m[e] = true
}
}
for _, e := range s2 {
if !m[e] {
s = append(s, e)
m[e] = true
}
}
return s
}
func detectFormat(path string) (string, error) { func detectFormat(path string) (string, error) {
switch filepath.Ext(path) { switch filepath.Ext(path) {
case ".sqlite": case ".sqlite":