tangled
alpha
login
or
join now
oppi.li
/
sets
0
fork
atom
a rusty set datastructure for go
0
fork
atom
overview
issues
pulls
pipelines
set: add Singleton
Signed-off-by: oppiliappan <me@oppi.li>
oppi.li
3 months ago
d0656dd7
19cc62c4
verified
This commit was signed with the committer's
known signature
.
oppi.li
SSH Key Fingerprint:
SHA256:yQs05DbrlPDC2pBXLxqOdLYEswq3oEBnHaJiBP7bOlM=
+17
2 changed files
expand all
collapse all
unified
split
set.go
set_test.go
+6
set.go
···
21
return !exists
22
}
23
0
0
0
0
0
0
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
0
0
0
0
0
0
0
0
0
0
0
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()