mirror of
https://github.com/kovidgoyal/kitty.git
synced 2024-11-15 07:04:31 +03:00
Make a couple of other Set API functions nil-safe
This commit is contained in:
parent
2d7bbf60cc
commit
93618842ae
@ -84,7 +84,7 @@ func (self *Set[T]) Intersect(other *Set[T]) (ans *Set[T]) {
|
|||||||
func (self *Set[T]) Subtract(other *Set[T]) (ans *Set[T]) {
|
func (self *Set[T]) Subtract(other *Set[T]) (ans *Set[T]) {
|
||||||
ans = NewSet[T](self.Len())
|
ans = NewSet[T](self.Len())
|
||||||
for x := range self.items {
|
for x := range self.items {
|
||||||
if !other.Has(x) {
|
if other == nil || !other.Has(x) {
|
||||||
ans.items[x] = struct{}{}
|
ans.items[x] = struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,6 +92,9 @@ func (self *Set[T]) Subtract(other *Set[T]) (ans *Set[T]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *Set[T]) IsSubsetOf(other *Set[T]) bool {
|
func (self *Set[T]) IsSubsetOf(other *Set[T]) bool {
|
||||||
|
if other == nil {
|
||||||
|
return self.Len() == 0
|
||||||
|
}
|
||||||
for x := range self.items {
|
for x := range self.items {
|
||||||
if !other.Has(x) {
|
if !other.Has(x) {
|
||||||
return false
|
return false
|
||||||
|
Loading…
Reference in New Issue
Block a user