From af06dd6a02d41eada5ea3f15d5b74d5ace890af6 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 2 Sep 2022 14:57:49 -0600 Subject: rebuild root items this was sitting here uncommited from Wednesday --- lib/containers/set.go | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'lib/containers') 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 { -- cgit v1.2.3-2-g168b