MakeStringSet makes a new StringSet with the given strings.
(strs ...string)
| 12 | |
| 13 | // MakeStringSet makes a new StringSet with the given strings. |
| 14 | func MakeStringSet(strs ...string) StringSet { |
| 15 | if len(strs) <= 0 { |
| 16 | return nil |
| 17 | } |
| 18 | result := make([]string, len(strs)) |
| 19 | copy(result, strs) |
| 20 | sort.Strings(result) |
| 21 | for i := 1; i < len(result); { // shuffle down any duplicates |
| 22 | if result[i-1] == result[i] { |
| 23 | result = append(result[:i-1], result[i:]...) |
| 24 | continue |
| 25 | } |
| 26 | i++ |
| 27 | } |
| 28 | return StringSet(result) |
| 29 | } |
| 30 | |
| 31 | // Contains returns true if the string set includes the given string |
| 32 | func (s StringSet) Contains(str string) bool { |
searching dependent graphs…