2 Copyright The Kubernetes Authors.
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
17 // Code generated by set-gen. DO NOT EDIT.
26 // sets.Byte is a set of bytes, implemented via map[byte]struct{} for minimal memory consumption.
27 type Byte map[byte]Empty
29 // NewByte creates a Byte from a list of values.
30 func NewByte(items ...byte) Byte {
36 // ByteKeySet creates a Byte from a keys of a map[byte](? extends interface{}).
37 // If the value passed in is not actually a map, this will panic.
38 func ByteKeySet(theMap interface{}) Byte {
39 v := reflect.ValueOf(theMap)
42 for _, keyValue := range v.MapKeys() {
43 ret.Insert(keyValue.Interface().(byte))
48 // Insert adds items to the set.
49 func (s Byte) Insert(items ...byte) {
50 for _, item := range items {
55 // Delete removes all items from the set.
56 func (s Byte) Delete(items ...byte) {
57 for _, item := range items {
62 // Has returns true if and only if item is contained in the set.
63 func (s Byte) Has(item byte) bool {
64 _, contained := s[item]
68 // HasAll returns true if and only if all items are contained in the set.
69 func (s Byte) HasAll(items ...byte) bool {
70 for _, item := range items {
78 // HasAny returns true if any items are contained in the set.
79 func (s Byte) HasAny(items ...byte) bool {
80 for _, item := range items {
88 // Difference returns a set of objects that are not in s2
91 // s2 = {a1, a2, a4, a5}
92 // s1.Difference(s2) = {a3}
93 // s2.Difference(s1) = {a4, a5}
94 func (s Byte) Difference(s2 Byte) Byte {
104 // Union returns a new set which includes items in either s1 or s2.
108 // s1.Union(s2) = {a1, a2, a3, a4}
109 // s2.Union(s1) = {a1, a2, a3, a4}
110 func (s1 Byte) Union(s2 Byte) Byte {
112 for key := range s1 {
115 for key := range s2 {
121 // Intersection returns a new set which includes the item in BOTH s1 and s2
125 // s1.Intersection(s2) = {a2}
126 func (s1 Byte) Intersection(s2 Byte) Byte {
129 if s1.Len() < s2.Len() {
136 for key := range walk {
144 // IsSuperset returns true if and only if s1 is a superset of s2.
145 func (s1 Byte) IsSuperset(s2 Byte) bool {
146 for item := range s2 {
154 // Equal returns true if and only if s1 is equal (as a set) to s2.
155 // Two sets are equal if their membership is identical.
156 // (In practice, this means same elements, order doesn't matter)
157 func (s1 Byte) Equal(s2 Byte) bool {
158 return len(s1) == len(s2) && s1.IsSuperset(s2)
161 type sortableSliceOfByte []byte
163 func (s sortableSliceOfByte) Len() int { return len(s) }
164 func (s sortableSliceOfByte) Less(i, j int) bool { return lessByte(s[i], s[j]) }
165 func (s sortableSliceOfByte) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
167 // List returns the contents as a sorted byte slice.
168 func (s Byte) List() []byte {
169 res := make(sortableSliceOfByte, 0, len(s))
171 res = append(res, key)
177 // UnsortedList returns the slice with contents in random order.
178 func (s Byte) UnsortedList() []byte {
179 res := make([]byte, 0, len(s))
181 res = append(res, key)
186 // Returns a single element from the set.
187 func (s Byte) PopAny() (byte, bool) {
193 return zeroValue, false
196 // Len returns the size of the set.
197 func (s Byte) Len() int {
201 func lessByte(lhs, rhs byte) bool {