From 73fb99286583a0ac1f82efabf9172e06ec796968 Mon Sep 17 00:00:00 2001 From: stephenmk Date: Sun, 22 Jan 2023 14:32:45 -0600 Subject: [PATCH] Add intersection and union functions for string arrays --- common.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/common.go b/common.go index ec331d6..5f2dab3 100644 --- a/common.go +++ b/common.go @@ -262,6 +262,39 @@ func hasString(needle string, haystack []string) bool { 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) { switch filepath.Ext(path) { case ".sqlite":