-
Notifications
You must be signed in to change notification settings - Fork 22
/
set.go
35 lines (26 loc) · 970 Bytes
/
set.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package set
import (
"github.com/iotaledger/hive.go/core/datastructure/set"
"github.com/iotaledger/hive.go/core/serix"
)
// Set is a collection of elements.
type Set[T comparable] interface {
// Add adds a new element to the Set and returns true if the element was not present in the set before.
Add(element T) bool
// Delete removes the element from the Set and returns true if it did exist.
Delete(element T) bool
// Has returns true if the element exists in the Set.
Has(element T) bool
// ForEach iterates through the set and calls the callback for every element.
ForEach(callback func(element T))
// Clear removes all elements from the Set.
Clear()
// Size returns the size of the Set.
Size() int
serix.Serializable
serix.Deserializable
}
// New returns a new Set that is thread safe if the optional threadSafe parameter is set to true.
func New[T comparable](threadSafe ...bool) Set[T] {
return newGenericSet[T](set.New(threadSafe...))
}