diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2022-09-02 14:57:49 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2022-09-02 14:57:49 -0600 |
commit | af06dd6a02d41eada5ea3f15d5b74d5ace890af6 (patch) | |
tree | 34b1bb192dfc9f8abc7082d210d3d5b7903b17d0 /lib/containers/set.go | |
parent | ecb13992b042460889a908f32a0505dda5fe206f (diff) |
rebuild root items
this was sitting here uncommited from Wednesday
Diffstat (limited to 'lib/containers/set.go')
-rw-r--r-- | lib/containers/set.go | 35 |
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 { |