From 43bcb41a2a65ef5cc76897b1b90066cb3a13171f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 23 Feb 2023 07:39:18 +0530 Subject: [PATCH] Nicer Set constructor --- tools/utils/set.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/utils/set.go b/tools/utils/set.go index 477fa9646..cff09034c 100644 --- a/tools/utils/set.go +++ b/tools/utils/set.go @@ -84,7 +84,7 @@ func (self *Set[T]) Subtract(other *Set[T]) (ans *Set[T]) { 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 { if !other.Has(x) { return false @@ -101,3 +101,9 @@ func NewSet[T comparable](capacity ...int) (ans *Set[T]) { } return } + +func NewSetWithItems[T comparable](items ...T) (ans *Set[T]) { + ans = NewSet[T](len(items)) + ans.AddItems(items...) + return ans +}