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 21 return !exists 22 22 } 23 23 24 + func Singleton[T comparable](item T) Set[T] { 25 + n := New[T]() 26 + _ = n.Insert(item) 27 + return n 28 + } 29 + 24 30 func (s *Set[T]) Remove(item T) bool { 25 31 _, exists := s.data[item] 26 32 if exists {
+11
set_test.go
··· 240 240 } 241 241 } 242 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 + 243 254 func TestPropertyInsertIdempotent(t *testing.T) { 244 255 f := func(s Set[int], item int) bool { 245 256 clone := s.Clone()