Skip to content

Commit

Permalink
feat: improve Add performance
Browse files Browse the repository at this point in the history
  • Loading branch information
orisano authored and deckarep committed Mar 29, 2022
1 parent abcdb7d commit 29bd72c
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions threadunsafe.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,9 @@ func newThreadUnsafeSet[T comparable]() threadUnsafeSet[T] {
}

func (s *threadUnsafeSet[T]) Add(v T) bool {
_, found := (*s)[v]
if found {
return false //False if it existed already
}

prevLen := len(*s)
(*s)[v] = struct{}{}
return true
return prevLen != len(*s)
}

func (s *threadUnsafeSet[T]) Cardinality() int {
Expand Down

0 comments on commit 29bd72c

Please sign in to comment.