summaryrefslogtreecommitdiff
path: root/lib/containers/set.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/containers/set.go')
-rw-r--r--lib/containers/set.go35
1 files changed, 23 insertions, 12 deletions
diff --git a/lib/containers/set.go b/lib/containers/set.go
index 8cd700a..42e5ad2 100644
--- a/lib/containers/set.go
+++ b/lib/containers/set.go
@@ -45,27 +45,38 @@ func (o *Set[T]) DecodeJSON(r io.RuneScanner) error {
})
}
-func (o *Set[T]) Insert(v T) {
- if *o == nil {
- *o = Set[T]{}
+func (o Set[T]) Insert(v T) {
+ o[v] = struct{}{}
+}
+
+func (o Set[T]) InsertFrom(p Set[T]) {
+ for v := range p {
+ o[v] = struct{}{}
}
- (*o)[v] = struct{}{}
}
-func (o *Set[T]) InsertFrom(p Set[T]) {
- if *o == nil {
- *o = Set[T]{}
+func (o Set[T]) Delete(v T) {
+ if o == nil {
+ return
+ }
+ delete(o, v)
+}
+
+func (o Set[T]) DeleteFrom(p Set[T]) {
+ if o == nil {
+ return
}
for v := range p {
- (*o)[v] = struct{}{}
+ delete(o, v)
}
}
-func (o *Set[T]) Delete(v T) {
- if *o == nil {
- return
+func (o Set[T]) TakeOne() T {
+ for v := range o {
+ return v
}
- delete(*o, v)
+ var zero T
+ return zero
}
func (small Set[T]) HasIntersection(big Set[T]) bool {