fn: Add Size and IsEmpty methods to Set

This commit is contained in:
ziggie 2024-10-04 00:32:27 +02:00
parent 9f0cc159ea
commit 42e8a43375
No known key found for this signature in database
GPG Key ID: 1AFF9C4DCED6D666

View File

@ -31,6 +31,16 @@ func (s Set[T]) Contains(e T) bool {
return ok
}
// IsEmpty returns true if the set is empty.
func (s Set[T]) IsEmpty() bool {
return len(s) == 0
}
// Size returns the number of elements in the set.
func (s Set[T]) Size() uint {
return uint(len(s))
}
// Diff returns the difference between two sets.
func (s Set[T]) Diff(other Set[T]) Set[T] {
diff := make(Set[T])