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=
1/1
ci.yml
success
7s
+17
2 changed files
expand all
collapse all
unified
split
set.go
set_test.go
+6
set.go
···
21
21
return !exists
22
22
}
23
23
24
24
+
func Singleton[T comparable](item T) Set[T] {
25
25
+
n := New[T]()
26
26
+
_ = n.Insert(item)
27
27
+
return n
28
28
+
}
29
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
243
+
func TestPropertySingleonLen(t *testing.T) {
244
244
+
f := func(item int) bool {
245
245
+
single := Singleton(item)
246
246
+
return single.Len() == 1
247
247
+
}
248
248
+
249
249
+
if err := quick.Check(f, nil); err != nil {
250
250
+
t.Error(err)
251
251
+
}
252
252
+
}
253
253
+
243
254
func TestPropertyInsertIdempotent(t *testing.T) {
244
255
f := func(s Set[int], item int) bool {
245
256
clone := s.Clone()