| 1 | // Generated by: gen, modified by Steve Streeting |
| 2 | // TypeWriter: container |
| 3 | // Directive: +gen on main.string |
| 4 | |
| 5 | // See http://clipperhouse.github.io/gen for documentation |
| 6 | |
| 7 | // Set is a modification of https://github.com/deckarep/golang-set |
| 8 | // The MIT License (MIT) |
| 9 | // Copyright (c) 2013 Ralph Caraveo ([email protected]) |
| 10 | package toolsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/ |
| 11 | |
| 12 | // The primary type that represents a set |
| 13 | type StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet# map[string]struct{} |
| 14 | |
| 15 | // Creates and returns a reference to an empty set. |
| 16 | func NewStringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewStringSet().() StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet# { |
| 17 | return make(StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#) |
| 18 | } |
| 19 | |
| 20 | // Creates and returns a reference to an empty set with a capacity. |
| 21 | func NewStringSetWithCapacityscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewStringSetWithCapacity().(capacity int) StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet# { |
| 22 | return make(StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#, capacity) |
| 23 | } |
| 24 | |
| 25 | // Creates and returns a reference to a set from an existing slice |
| 26 | func NewStringSetFromSlicescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewStringSetFromSlice().(s []string) StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet# { |
| 27 | a := NewStringSetWithCapacityscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewStringSetWithCapacity().(len(s)) |
| 28 | for _, item := range s { |
| 29 | a.Addscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#Add().(item) |
| 30 | } |
| 31 | return a |
| 32 | } |
| 33 | |
| 34 | // Adds an item to the current set if it doesn't already exist in the set. |
| 35 | func (set StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#) Addscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#Add().(i string) bool { |
| 36 | _, found := set[i] |
| 37 | set[i] = struct{}{} |
| 38 | return !found //False if it e xisted already |
| 39 | } |
| 40 | |
| 41 | // Determines if a given item is already in the set. |
| 42 | func (set StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#) Containsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#Contains().(i string) bool { |
| 43 | _, found := set[i] |
| 44 | return found |
| 45 | } |
| 46 | |
| 47 | // Determines if the given items are all in the set |
| 48 | func (set StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#) ContainsAllscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#ContainsAll().(i ...string) bool { |
| 49 | allSet := NewStringSetFromSlicescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewStringSetFromSlice().(i) |
| 50 | if allSet.IsSubsetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#IsSubset().(set) { |
| 51 | return true |
| 52 | } |
| 53 | return false |
| 54 | } |
| 55 | |
| 56 | // Determines if every item in the other set is in this set. |
| 57 | func (set StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#) IsSubsetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#IsSubset().(other StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#) bool { |
| 58 | for elem := range set { |
| 59 | if !other.Containsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#Contains().(elem) { |
| 60 | return false |
| 61 | } |
| 62 | } |
| 63 | return true |
| 64 | } |
| 65 | |
| 66 | // Determines if every item of this set is in the other set. |
| 67 | func (set StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#) IsSupersetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#IsSuperset().(other StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#) bool { |
| 68 | return other.IsSubsetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#IsSubset().(set) |
| 69 | } |
| 70 | |
| 71 | // Returns a new set with all items in both sets. |
| 72 | func (set StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#) Unionscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#Union().(other StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#) StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet# { |
| 73 | unionedSet := NewStringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewStringSet().() |
| 74 | |
| 75 | for elem := range set { |
| 76 | unionedSet.Addscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#Add().(elem) |
| 77 | } |
| 78 | for elem := range other { |
| 79 | unionedSet.Addscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#Add().(elem) |
| 80 | } |
| 81 | return unionedSet |
| 82 | } |
| 83 | |
| 84 | // Returns a new set with items that exist only in both sets. |
| 85 | func (set StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#) Intersectscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#Intersect().(other StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#) StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet# { |
| 86 | intersection := NewStringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewStringSet().() |
| 87 | // loop over smaller set |
| 88 | if set.Cardinalityscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#Cardinality().() < other.Cardinalityscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#Cardinality().() { |
| 89 | for elem := range set { |
| 90 | if other.Containsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#Contains().(elem) { |
| 91 | intersection.Addscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#Add().(elem) |
| 92 | } |
| 93 | } |
| 94 | } else { |
| 95 | for elem := range other { |
| 96 | if set.Containsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#Contains().(elem) { |
| 97 | intersection.Addscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#Add().(elem) |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | return intersection |
| 102 | } |
| 103 | |
| 104 | // Returns a new set with items in the current set but not in the other set |
| 105 | func (set StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#) Differencescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#Difference().(other StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#) StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet# { |
| 106 | differencedSet := NewStringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewStringSet().() |
| 107 | for elem := range set { |
| 108 | if !other.Containsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#Contains().(elem) { |
| 109 | differencedSet.Addscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#Add().(elem) |
| 110 | } |
| 111 | } |
| 112 | return differencedSet |
| 113 | } |
| 114 | |
| 115 | // Returns a new set with items in the current set or the other set but not in both. |
| 116 | func (set StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#) SymmetricDifferencescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#SymmetricDifference().(other StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#) StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet# { |
| 117 | aDiff := set.Differencescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#Difference().(other) |
| 118 | bDiff := other.Differencescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#Difference().(set) |
| 119 | return aDiff.Unionscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#Union().(bDiff) |
| 120 | } |
| 121 | |
| 122 | // Clears the entire set to be the empty set. |
| 123 | func (set *StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#) Clearscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#Clear().() { |
| 124 | *set = make(StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#) |
| 125 | } |
| 126 | |
| 127 | // Allows the removal of a single item in the set. |
| 128 | func (set StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#) Removescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#Remove().(i string) { |
| 129 | delete(set, i) |
| 130 | } |
| 131 | |
| 132 | // Cardinality returns how many items are currently in the set. |
| 133 | func (set StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#) Cardinalityscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#Cardinality().() int { |
| 134 | return len(set) |
| 135 | } |
| 136 | |
| 137 | // Iter() returns a channel of type string that you can range over. |
| 138 | func (set StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#) Iterscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#Iter().() <-chan string { |
| 139 | ch := make(chan string) |
| 140 | go func() { |
| 141 | for elem := range set { |
| 142 | ch <- elem |
| 143 | } |
| 144 | close(ch) |
| 145 | }() |
| 146 | |
| 147 | return ch |
| 148 | } |
| 149 | |
| 150 | // Equal determines if two sets are equal to each other. |
| 151 | // If they both are the same size and have the same items they are considered equal. |
| 152 | // Order of items is not relevant for sets to be equal. |
| 153 | func (set StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#) Equalscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#Equal().(other StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#) bool { |
| 154 | if set.Cardinalityscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#Cardinality().() != other.Cardinalityscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#Cardinality().() { |
| 155 | return false |
| 156 | } |
| 157 | for elem := range set { |
| 158 | if !other.Containsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#Contains().(elem) { |
| 159 | return false |
| 160 | } |
| 161 | } |
| 162 | return true |
| 163 | } |
| 164 | |
| 165 | // Returns a clone of the set. |
| 166 | // Does NOT clone the underlying elements. |
| 167 | func (set StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#) Clonescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#Clone().() StringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet# { |
| 168 | clonedSet := NewStringSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewStringSet().() |
| 169 | for elem := range set { |
| 170 | clonedSet.Addscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/StringSet#Add().(elem) |
| 171 | } |
| 172 | return clonedSet |
| 173 | } |