UniqueSlice returns a slice containing the unique items from the specified string slice. The items in the output slice are in the order in which they occur in the input slice.
(items []string)
| 24 | // string slice. The items in the output slice are in the order in which they |
| 25 | // occur in the input slice. |
| 26 | func UniqueSlice(items []string) []string { |
| 27 | var uniq []string |
| 28 | registry := map[string]struct{}{} |
| 29 | |
| 30 | for _, item := range items { |
| 31 | if _, ok := registry[item]; ok { |
| 32 | continue |
| 33 | } |
| 34 | |
| 35 | registry[item] = struct{}{} |
| 36 | uniq = append(uniq, item) |
| 37 | } |
| 38 | |
| 39 | return uniq |
| 40 | } |
| 41 | |
| 42 | // SliceContains returns true if terms contains q, or false otherwise. |
| 43 | func SliceContains(terms []string, q string) bool { |
no outgoing calls
searching dependent graphs…