Debian Codegraph @

tools/ordered_set.go

raw symbols SCIP
1 package toolsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/
2
3 // OrderedSet is a unique set of strings that maintains insertion order.
4 type OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet# struct {
5 // s is the set of strings that we're keeping track of.
6 sscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#s. []string
7 // m is a mapping of string value "s" into the index "i" that that
8 // string is present in in the given "s".
9 mscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#m. map[string]int
10 }
11
12 // NewOrderedSet creates an ordered set with no values.
13 func NewOrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewOrderedSet().() *OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet# {
14 return NewOrderedSetWithCapacityscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewOrderedSetWithCapacity().(0)
15 }
16
17 // NewOrderedSetWithCapacity creates a new ordered set with no values. The
18 // returned ordered set can be appended to "capacity" number of times before it
19 // grows internally.
20 func NewOrderedSetWithCapacityscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewOrderedSetWithCapacity().(capacity int) *OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet# {
21 return &OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#{
22 sscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#s.: make([]string, 0, capacity),
23 mscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#m.: make(map[string]int, capacity),
24 }
25 }
26
27 // NewOrderedSetFromSlice returns a new ordered set with the elements given in
28 // the slice "s".
29 func NewOrderedSetFromSlicescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewOrderedSetFromSlice().(s []string) *OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet# {
30 set := NewOrderedSetWithCapacityscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewOrderedSetWithCapacity().(len(s))
31 for _, e := range s {
32 set.Addscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Add().(e)
33 }
34
35 return set
36 }
37
38 // Add adds the given element "i" to the ordered set, unless the element is
39 // already present. It returns whether or not the element was added.
40 func (s *OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#) Addscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Add().(i string) bool {
41 if _, ok := s.mscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#m.[i]; ok {
42 return false
43 }
44
45 s.sscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#s. = append(s.sscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#s., i)
46 s.mscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#m.[i] = len(s.sscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#s.) - 1
47
48 return true
49 }
50
51 // Contains returns whether or not the given "i" is contained in this ordered
52 // set. It is a constant-time operation.
53 func (s *OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#) Containsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Contains().(i string) bool {
54 if _, ok := s.mscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#m.[i]; ok {
55 return true
56 }
57 return false
58 }
59
60 // ContainsAll returns whether or not all of the given items in "i" are present
61 // in the ordered set.
62 func (s *OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#) ContainsAllscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#ContainsAll().(i ...string) bool {
63 for _, item := range i {
64 if !s.Containsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Contains().(item) {
65 return false
66 }
67 }
68 return true
69 }
70
71 // IsSubset returns whether other is a subset of this ordered set. In other
72 // words, it returns whether or not all of the elements in "other" are also
73 // present in this set.
74 func (s *OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#) IsSubsetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#IsSubset().(other *OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#) bool {
75 for _, i := range other.sscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#s. {
76 if !s.Containsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Contains().(i) {
77 return false
78 }
79 }
80 return true
81 }
82
83 // IsSuperset returns whether or not this set is a superset of "other". In other
84 // words, it returns whether or not all of the elements in this set are also in
85 // the set "other".
86 func (s *OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#) IsSupersetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#IsSuperset().(other *OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#) bool {
87 return other.IsSubsetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#IsSubset().(s)
88 }
89
90 // Union returns a union of this set with the given set "other". It returns the
91 // items that are in either set while maintaining uniqueness constraints. It
92 // preserves ordered within each set, and orders the elements in this set before
93 // the elements in "other".
94 //
95 // It is an O(n+m) operation.
96 func (s *OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#) Unionscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Union().(other *OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#) *OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet# {
97 union := NewOrderedSetWithCapacityscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewOrderedSetWithCapacity().(other.Cardinalityscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Cardinality().() + s.Cardinalityscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Cardinality().())
98
99 for _, e := range s.sscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#s. {
100 union.Addscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Add().(e)
101 }
102 for _, e := range other.sscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#s. {
103 union.Addscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Add().(e)
104 }
105
106 return union
107 }
108
109 // Intersect returns the elements that are in both this set and then given
110 // "ordered" set. It is an O(min(n, m)) (in other words, O(n)) operation.
111 func (s *OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#) Intersectscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Intersect().(other *OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#) *OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet# {
112 intersection := NewOrderedSetWithCapacityscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewOrderedSetWithCapacity().(min(
113 s.Cardinalityscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Cardinality().(), other.Cardinalityscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Cardinality().()))
114
115 if s.Cardinalityscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Cardinality().() < other.Cardinalityscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Cardinality().() {
116 for _, elem := range s.sscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#s. {
117 if other.Containsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Contains().(elem) {
118 intersection.Addscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Add().(elem)
119 }
120 }
121 } else {
122 for _, elem := range other.sscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#s. {
123 if s.Containsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Contains().(elem) {
124 intersection.Addscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Add().(elem)
125 }
126 }
127 }
128
129 return intersection
130 }
131
132 // Difference returns the elements that are in this set, but not included in
133 // other.
134 func (s *OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#) Differencescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Difference().(other *OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#) *OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet# {
135 diff := NewOrderedSetWithCapacityscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewOrderedSetWithCapacity().(s.Cardinalityscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Cardinality().())
136 for _, e := range s.sscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#s. {
137 if !other.Containsscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Contains().(e) {
138 diff.Addscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Add().(e)
139 }
140 }
141
142 return diff
143 }
144
145 // SymmetricDifference returns the elements that are not present in both sets.
146 func (s *OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#) SymmetricDifferencescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#SymmetricDifference().(other *OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#) *OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet# {
147 left := s.Differencescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Difference().(other)
148 right := other.Differencescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Difference().(s)
149
150 return left.Unionscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Union().(right)
151 }
152
153 // Clear removes all elements from this set.
154 func (s *OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#) Clearscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Clear().() {
155 s.sscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#s. = make([]string, 0)
156 s.mscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#m. = make(map[string]int, 0)
157 }
158
159 // Remove removes the given element "i" from this set.
160 func (s *OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#) Removescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Remove().(i string) {
161 idx, ok := s.mscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#m.[i]
162 if !ok {
163 return
164 }
165
166 rest := min(idx+1, len(s.sscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#s.)-1)
167
168 s.sscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#s. = append(s.sscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#s.[:idx], s.sscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#s.[rest:]...)
169 for _, e := range s.sscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#s.[rest:] {
170 s.mscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#m.[e] = s.mscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#m.[e] - 1
171 }
172 delete(s.mscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#m., i)
173 }
174
175 // Cardinality returns the cardinality of this set.
176 func (s *OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#) Cardinalityscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Cardinality().() int {
177 return len(s.sscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#s.)
178 }
179
180 // Iter returns a channel which yields the elements in this set in insertion
181 // order.
182 func (s *OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#) Iterscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Iter().() <-chan string {
183 c := make(chan string)
184 go func() {
185 for _, i := range s.sscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#s. {
186 c <- i
187 }
188 close(c)
189 }()
190
191 return c
192 }
193
194 // Equal returns whether this element has the same number, identity and ordering
195 // elements as given in "other".
196 func (s *OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#) Equalscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Equal().(other *OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#) bool {
197 if s.Cardinalityscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Cardinality().() != other.Cardinalityscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Cardinality().() {
198 return false
199 }
200
201 for e, i := range s.mscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#m. {
202 if ci, ok := other.mscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#m.[e]; !ok || ci != i {
203 return false
204 }
205 }
206
207 return true
208 }
209
210 // Clone returns a deep copy of this set.
211 func (s *OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#) Clonescip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Clone().() *OrderedSetscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet# {
212 clone := NewOrderedSetWithCapacityscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/NewOrderedSetWithCapacity().(s.Cardinalityscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Cardinality().())
213 for _, i := range s.sscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#s. {
214 clone.Addscip-go gomod github.com/git-lfs/git-lfs/v3 . `github.com/git-lfs/git-lfs/v3/tools`/OrderedSet#Add().(i)
215 }
216 return clone
217 }