Feat: Get file for oss handler
This commit is contained in:
@@ -71,3 +71,38 @@ func BuildConcat(str1, str2 string, DBType string) string {
|
||||
return str1 + "||" + str2
|
||||
}
|
||||
}
|
||||
|
||||
// SliceIntersect 求两个切片交集
|
||||
func SliceIntersect(slice1, slice2 []string) []string {
|
||||
m := make(map[string]int)
|
||||
nn := make([]string, 0)
|
||||
for _, v := range slice1 {
|
||||
m[v]++
|
||||
}
|
||||
|
||||
for _, v := range slice2 {
|
||||
times, _ := m[v]
|
||||
if times == 1 {
|
||||
nn = append(nn, v)
|
||||
}
|
||||
}
|
||||
return nn
|
||||
}
|
||||
|
||||
// SliceDifference 求两个切片差集
|
||||
func SliceDifference(slice1, slice2 []string) []string {
|
||||
m := make(map[string]int)
|
||||
nn := make([]string, 0)
|
||||
inter := SliceIntersect(slice1, slice2)
|
||||
for _, v := range inter {
|
||||
m[v]++
|
||||
}
|
||||
|
||||
for _, value := range slice1 {
|
||||
times, _ := m[value]
|
||||
if times == 0 {
|
||||
nn = append(nn, value)
|
||||
}
|
||||
}
|
||||
return nn
|
||||
}
|
||||
|
||||
@@ -68,3 +68,31 @@ func TestBuildConcat(t *testing.T) {
|
||||
asserts.Equal("CONCAT(1,2)", BuildConcat("1", "2", "mysql"))
|
||||
asserts.Equal("1||2", BuildConcat("1", "2", "sqlite3"))
|
||||
}
|
||||
|
||||
func TestSliceDifference(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
|
||||
{
|
||||
s1 := []string{"1", "2", "3", "4"}
|
||||
s2 := []string{"2", "4"}
|
||||
asserts.Equal([]string{"1", "3"}, SliceDifference(s1, s2))
|
||||
}
|
||||
|
||||
{
|
||||
s2 := []string{"1", "2", "3", "4"}
|
||||
s1 := []string{"2", "4"}
|
||||
asserts.Equal([]string{}, SliceDifference(s1, s2))
|
||||
}
|
||||
|
||||
{
|
||||
s1 := []string{"1", "2", "3", "4"}
|
||||
s2 := []string{"1", "2", "3", "4"}
|
||||
asserts.Equal([]string{}, SliceDifference(s1, s2))
|
||||
}
|
||||
|
||||
{
|
||||
s1 := []string{"1", "2", "3", "4"}
|
||||
s2 := []string{}
|
||||
asserts.Equal([]string{"1", "2", "3", "4"}, SliceDifference(s1, s2))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user