StrSliceDeduplicate removes dups in slice
(s []string)
| 78 | |
| 79 | // StrSliceDeduplicate removes dups in slice |
| 80 | func StrSliceDeduplicate(s []string) []string { |
| 81 | l := len(s) |
| 82 | if l < 2 { |
| 83 | return s |
| 84 | } |
| 85 | if l == 2 { |
| 86 | if s[0] == s[1] { |
| 87 | return s[0:1] |
| 88 | } |
| 89 | return s |
| 90 | } |
| 91 | |
| 92 | found := make(map[string]bool, l) |
| 93 | j := 0 |
| 94 | for i, x := range s { |
| 95 | if !found[x] { |
| 96 | found[x] = true |
| 97 | s[j] = s[i] |
| 98 | j++ |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | return s[:j] |
| 103 | } |
| 104 | |
| 105 | // StrSlicesSubstract finds all the strings which are in l but not in r, both slices shoult be sorted |
| 106 | func StrSlicesSubstract(l, r []string) []string { |
no outgoing calls