github.com/jxskiss/gopkg/v2@v2.14.9-0.20240514120614-899f3e7952b4/collection/set/compat.go (about) 1 package set 2 3 // Int is an int set collection. 4 // The zero value of Int is an empty instance ready to use. A zero Int 5 // value shall not be copied, or it may result incorrect behavior. 6 // 7 // This type is mainly for compatibility with old code, the generic 8 // implementation Generic[int] is favored over this. 9 type Int struct { 10 Generic[int] 11 } 12 13 // NewInt creates an Int set instance. 14 func NewInt(vals ...int) Int { 15 return Int{New(vals...)} 16 } 17 18 // NewIntWithSize creates an Int set instance with given initial size. 19 func NewIntWithSize(size int) Int { 20 return Int{NewWithSize[int](size)} 21 } 22 23 func (s Int) Del(vals ...int) { s.Generic.Delete(vals...) } 24 func (s Int) Diff(other Int) Int { return Int{s.Generic.Diff(other.Generic)} } 25 func (s Int) DiffSlice(other []int) Int { return Int{s.Generic.DiffSlice(other)} } 26 func (s Int) FilterInclude(slice []int) []int { return s.Generic.FilterContains(slice) } 27 func (s Int) FilterExclude(slice []int) []int { return s.Generic.FilterNotContains(slice) } 28 func (s Int) Intersect(other Int) Int { return Int{s.Generic.Intersect(other.Generic)} } 29 func (s Int) IntersectSlice(other []int) Int { return Int{s.Generic.IntersectSlice(other)} } 30 func (s Int) Union(other Int) Int { return Int{s.Generic.Union(other.Generic)} } 31 func (s Int) UnionSlice(other []int) Int { return Int{s.Generic.UnionSlice(other)} } 32 33 // Int64 is an int64 set collection. 34 // The zero value of Int64 is an empty instance ready to use. A zero Int64 35 // value shall not be copied, or it may result incorrect behavior. 36 // 37 // This type is mainly for compatibility with old code, the generic 38 // implementation Generic[int64] is favored over this. 39 type Int64 struct { 40 Generic[int64] 41 } 42 43 // NewInt64 creates an Int64 set instance. 44 func NewInt64(vals ...int64) Int64 { 45 return Int64{New(vals...)} 46 } 47 48 // NewInt64WithSize creates an Int64 set instance with given initial size. 49 func NewInt64WithSize(size int) Int64 { 50 return Int64{NewWithSize[int64](size)} 51 } 52 53 func (s Int64) Del(vals ...int64) { s.Generic.Delete(vals...) } 54 func (s Int64) Diff(other Int64) Int64 { return Int64{s.Generic.Diff(other.Generic)} } 55 func (s Int64) DiffSlice(other []int64) Int64 { return Int64{s.Generic.DiffSlice(other)} } 56 func (s Int64) FilterInclude(slice []int64) []int64 { return s.Generic.FilterContains(slice) } 57 func (s Int64) FilterExclude(slice []int64) []int64 { return s.Generic.FilterNotContains(slice) } 58 func (s Int64) Intersect(other Int64) Int64 { return Int64{s.Generic.Intersect(other.Generic)} } 59 func (s Int64) IntersectSlice(other []int64) Int64 { return Int64{s.Generic.IntersectSlice(other)} } 60 func (s Int64) Union(other Int64) Int64 { return Int64{s.Generic.Union(other.Generic)} } 61 func (s Int64) UnionSlice(other []int64) Int64 { return Int64{s.Generic.UnionSlice(other)} } 62 63 // Int32 is an int32 set collection. 64 // The zero value of Int32 is an empty instance ready to use. A zero Int32 65 // value shall not be copied, or it may result incorrect behavior. 66 // 67 // This type is mainly for compatibility with old code, the generic 68 // implementation Generic[int32] is favored over this. 69 type Int32 struct { 70 Generic[int32] 71 } 72 73 // NewInt32 creates an Int32 set instance. 74 func NewInt32(vals ...int32) Int32 { 75 return Int32{New(vals...)} 76 } 77 78 // NewInt32WithSize creates an Int32 set instance with given initial size. 79 func NewInt32WithSize(size int) Int32 { 80 return Int32{NewWithSize[int32](size)} 81 } 82 83 func (s Int32) Del(vals ...int32) { s.Generic.Delete(vals...) } 84 func (s Int32) Diff(other Int32) Int32 { return Int32{s.Generic.Diff(other.Generic)} } 85 func (s Int32) DiffSlice(other []int32) Int32 { return Int32{s.Generic.DiffSlice(other)} } 86 func (s Int32) FilterInclude(slice []int32) []int32 { return s.Generic.FilterContains(slice) } 87 func (s Int32) FilterExclude(slice []int32) []int32 { return s.Generic.FilterNotContains(slice) } 88 func (s Int32) Intersect(other Int32) Int32 { return Int32{s.Generic.Intersect(other.Generic)} } 89 func (s Int32) IntersectSlice(other []int32) Int32 { return Int32{s.Generic.IntersectSlice(other)} } 90 func (s Int32) Union(other Int32) Int32 { return Int32{s.Generic.Union(other.Generic)} } 91 func (s Int32) UnionSlice(other []int32) Int32 { return Int32{s.Generic.UnionSlice(other)} } 92 93 // String is a string set collection. 94 // The zero value of String is an empty instance ready to use. A zero String 95 // value shall not be copied, or it may result incorrect behavior. 96 // 97 // This type is mainly for compatibility with old code, the generic 98 // implementation Generic[string] is favored over this. 99 type String struct { 100 Generic[string] 101 } 102 103 // NewString creates a String set instance. 104 func NewString(vals ...string) String { 105 return String{New(vals...)} 106 } 107 108 // NewStringWithSize creates a String set instance with given initial size. 109 func NewStringWithSize(size int) String { 110 return String{NewWithSize[string](size)} 111 } 112 113 func (s String) Del(vals ...string) { s.Generic.Delete(vals...) } 114 func (s String) Diff(other String) String { return String{s.Generic.Diff(other.Generic)} } 115 func (s String) DiffSlice(other []string) String { return String{s.Generic.DiffSlice(other)} } 116 func (s String) FilterInclude(slice []string) []string { return s.Generic.FilterContains(slice) } 117 func (s String) FilterExclude(slice []string) []string { return s.Generic.FilterNotContains(slice) } 118 func (s String) Intersect(other String) String { return String{s.Generic.Intersect(other.Generic)} } 119 func (s String) IntersectSlice(other []string) String { return String{s.Generic.IntersectSlice(other)} } 120 func (s String) Union(other String) String { return String{s.Generic.Union(other.Generic)} } 121 func (s String) UnionSlice(other []string) String { return String{s.Generic.UnionSlice(other)} }