this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

set: introduce basic set operations

introduces New, Add, Remove and Size

Signed-off-by: oppiliappan <me@oppi.li>

authored by

oppiliappan and committed by
Tangled
71c625e2 5561a54d

+20
+20
set.go
··· 1 1 package hashset 2 2 3 3 type Set[T comparable] map[T]struct{} 4 + 5 + // New creates and returns a new empty Set. 6 + func New[T comparable]() Set[T] { 7 + return make(Set[T]) 8 + } 9 + 10 + // Add inserts an element into the set. 11 + func (s Set[T]) Add(value T) { 12 + s[value] = struct{}{} 13 + } 14 + 15 + // Remove deletes an element from the set. 16 + func (s Set[T]) Remove(value T) { 17 + delete(s, value) 18 + } 19 + 20 + // Size returns the number of elements in the set. 21 + func (s Set[T]) Size() int { 22 + return len(s) 23 + }