Skip to content

Commit 5d51eae

Browse files
authored
cleanups (#27)
1 parent d6fc2ee commit 5d51eae

2 files changed

Lines changed: 6 additions & 11 deletions

File tree

set_test.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,6 @@ func testSetConcurrency(t *testing.T, set Set[int]) {
521521
for i := range (base + 1) * 100 {
522522
set.Add(i)
523523
}
524-
finished.Done()
525524
},
526525
func(base int) {
527526
var x int
@@ -531,7 +530,6 @@ func testSetConcurrency(t *testing.T, set Set[int]) {
531530
x = set.Cardinality()
532531
}
533532
_ = x
534-
finished.Done()
535533
},
536534
func(base int) {
537535
var x bool
@@ -541,15 +539,13 @@ func testSetConcurrency(t *testing.T, set Set[int]) {
541539
x = set.Contains(i)
542540
}
543541
_ = x
544-
finished.Done()
545542
},
546543
func(base int) {
547544
started <- struct{}{}
548545
<-start
549546
for i := range (base + 1) * 100 {
550547
set.Remove(i)
551548
}
552-
finished.Done()
553549
},
554550
func(base int) {
555551
other := New[int]()
@@ -560,7 +556,6 @@ func testSetConcurrency(t *testing.T, set Set[int]) {
560556
<-start
561557
AppendSeq(other, set.Iterator)
562558
RemoveSeq(set, other.Iterator)
563-
finished.Done()
564559
},
565560
func(base int) {
566561
var x int
@@ -572,14 +567,14 @@ func testSetConcurrency(t *testing.T, set Set[int]) {
572567
}
573568
}
574569
_ = x
575-
finished.Done()
576570
},
577571
}
578572
count := 20
579573
for i := range count {
580-
finished.Add(len(goroutines))
581574
for j := range len(goroutines) {
582-
go goroutines[j](i)
575+
finished.Go(func() {
576+
goroutines[j](i)
577+
})
583578
}
584579
}
585580

sync.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (s *SyncMap[M]) Pop() (M, bool) {
6767
var m M
6868
var ok bool
6969

70-
s.m.Range(func(key, _ interface{}) bool {
70+
s.m.Range(func(key, _ any) bool {
7171
if _, ok = s.m.LoadAndDelete(key); ok {
7272
m = key.(M)
7373
ok = true
@@ -88,7 +88,7 @@ func (s *SyncMap[M]) Cardinality() int {
8888
return 0
8989
}
9090
var n int
91-
s.m.Range(func(_, _ interface{}) bool {
91+
s.m.Range(func(_, _ any) bool {
9292
n++
9393
return true
9494
})
@@ -98,7 +98,7 @@ func (s *SyncMap[M]) Cardinality() int {
9898
// Iterator yields all elements in the set. It is safe to call concurrently with other methods, but the order and
9999
// behavior is undefined, as per [sync.Map]'s `Range`.
100100
func (s *SyncMap[M]) Iterator(yield func(M) bool) {
101-
s.m.Range(func(key, _ interface{}) bool {
101+
s.m.Range(func(key, _ any) bool {
102102
return yield(key.(M))
103103
})
104104
}

0 commit comments

Comments
 (0)