Skip to content

Commit

Permalink
code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
UlricQin committed Dec 3, 2018
1 parent 8207c72 commit 1db2191
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 28 deletions.
28 changes: 0 additions & 28 deletions list/list.go

This file was deleted.

54 changes: 54 additions & 0 deletions slice/sub.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package slice

// Sub: a-b=?
func SubInt64(a, b []int64) []int64 {
blen := len(b)
if blen == 0 {
return a
}

alen := len(a)
if alen == 0 {
return a
}

bset := make(map[int64]struct{}, blen)
for i := 0; i < blen; i++ {
bset[b[i]] = struct{}{}
}

ret := make([]int64, 0, alen)
for i := 0; i < alen; i++ {
if _, has := bset[a[i]]; !has {
ret = append(ret, a[i])
}
}

return ret
}

func SubString(a, b []string) []string {
blen := len(b)
if blen == 0 {
return a
}

alen := len(a)
if alen == 0 {
return a
}

bset := make(map[string]struct{}, blen)
for i := 0; i < blen; i++ {
bset[b[i]] = struct{}{}
}

ret := make([]string, 0, alen)
for i := 0; i < alen; i++ {
if _, has := bset[a[i]]; !has {
ret = append(ret, a[i])
}
}

return ret
}

0 comments on commit 1db2191

Please sign in to comment.