Nicer Set constructor

This commit is contained in:
Kovid Goyal 2023-02-23 07:39:18 +05:30
parent 1df3ef648c
commit 43bcb41a2a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -84,7 +84,7 @@ func (self *Set[T]) Subtract(other *Set[T]) (ans *Set[T]) {
return ans return ans
} }
func (self *Set[T]) IsSubset(other *Set[T]) bool { func (self *Set[T]) IsSubsetOf(other *Set[T]) bool {
for x := range self.items { for x := range self.items {
if !other.Has(x) { if !other.Has(x) {
return false return false
@ -101,3 +101,9 @@ func NewSet[T comparable](capacity ...int) (ans *Set[T]) {
} }
return return
} }
func NewSetWithItems[T comparable](items ...T) (ans *Set[T]) {
ans = NewSet[T](len(items))
ans.AddItems(items...)
return ans
}