a rusty set datastructure for go

set: add Singleton

Signed-off-by: oppiliappan <me@oppi.li>

oppi.li d0656dd7 19cc62c4

verified
Changed files
+17
+6
set.go
··· 21 return !exists 22 } 23 24 func (s *Set[T]) Remove(item T) bool { 25 _, exists := s.data[item] 26 if exists {
··· 21 return !exists 22 } 23 24 + func Singleton[T comparable](item T) Set[T] { 25 + n := New[T]() 26 + _ = n.Insert(item) 27 + return n 28 + } 29 + 30 func (s *Set[T]) Remove(item T) bool { 31 _, exists := s.data[item] 32 if exists {
+11
set_test.go
··· 240 } 241 } 242 243 func TestPropertyInsertIdempotent(t *testing.T) { 244 f := func(s Set[int], item int) bool { 245 clone := s.Clone()
··· 240 } 241 } 242 243 + func TestPropertySingleonLen(t *testing.T) { 244 + f := func(item int) bool { 245 + single := Singleton(item) 246 + return single.Len() == 1 247 + } 248 + 249 + if err := quick.Check(f, nil); err != nil { 250 + t.Error(err) 251 + } 252 + } 253 + 254 func TestPropertyInsertIdempotent(t *testing.T) { 255 f := func(s Set[int], item int) bool { 256 clone := s.Clone()