aboutsummaryrefslogtreecommitdiff
path: root/sets.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2023-01-29 21:16:36 -0700
committerGitHub <noreply@github.com>2023-01-29 21:16:36 -0700
commit590e6a681ee3707d1f9d864828d370b90314629d (patch)
tree1a4bdedc9fc17535130f58551fadc3511630372b /sets.go
parentMerge pull request #41 from benbjohnson/retract-v0.4.2 (diff)
parentUpdate documentation (diff)
downloadpds-590e6a681ee3707d1f9d864828d370b90314629d.tar.gz
pds-590e6a681ee3707d1f9d864828d370b90314629d.tar.xz
Merge pull request #38 from BarrensZeppelin/master
Widen key constraint to 'any' for maps and sets
Diffstat (limited to 'sets.go')
-rw-r--r--sets.go20
1 files changed, 10 insertions, 10 deletions
diff --git a/sets.go b/sets.go
index d610c15..c8ce39f 100644
--- a/sets.go
+++ b/sets.go
@@ -4,7 +4,7 @@ package immutable
// to generate hashes and check for equality of key values.
//
// Internally, the Set stores values as keys of a Map[T,struct{}]
-type Set[T comparable] struct {
+type Set[T any] struct {
m *Map[T, struct{}]
}
@@ -13,7 +13,7 @@ type Set[T comparable] struct {
// If hasher is nil, a default hasher implementation will automatically be chosen based on the first key added.
// Default hasher implementations only exist for int, string, and byte slice types.
// NewSet can also take some initial values as varargs.
-func NewSet[T comparable](hasher Hasher[T], values ...T) Set[T] {
+func NewSet[T any](hasher Hasher[T], values ...T) Set[T] {
m := NewMap[T, struct{}](hasher)
for _, value := range values {
m = m.set(value, struct{}{}, true)
@@ -64,7 +64,7 @@ func (s Set[T]) Iterator() *SetIterator[T] {
// SetIterator represents an iterator over a set.
// Iteration can occur in natural or reverse order based on use of Next() or Prev().
-type SetIterator[T comparable] struct {
+type SetIterator[T any] struct {
mi *MapIterator[T, struct{}]
}
@@ -84,11 +84,11 @@ func (itr *SetIterator[T]) Next() (val T, ok bool) {
return
}
-type SetBuilder[T comparable] struct {
+type SetBuilder[T any] struct {
s Set[T]
}
-func NewSetBuilder[T comparable](hasher Hasher[T]) *SetBuilder[T] {
+func NewSetBuilder[T any](hasher Hasher[T]) *SetBuilder[T] {
return &SetBuilder[T]{s: NewSet(hasher)}
}
@@ -108,7 +108,7 @@ func (s SetBuilder[T]) Len() int {
return s.s.Len()
}
-type SortedSet[T comparable] struct {
+type SortedSet[T any] struct {
m *SortedMap[T, struct{}]
}
@@ -118,7 +118,7 @@ type SortedSet[T comparable] struct {
// a default comparer is set after the first key is inserted. Default comparers
// exist for int, string, and byte slice keys.
// NewSortedSet can also take some initial values as varargs.
-func NewSortedSet[T comparable](comparer Comparer[T], values ...T) SortedSet[T] {
+func NewSortedSet[T any](comparer Comparer[T], values ...T) SortedSet[T] {
m := NewSortedMap[T, struct{}](comparer)
for _, value := range values {
m = m.set(value, struct{}{}, true)
@@ -169,7 +169,7 @@ func (s SortedSet[T]) Iterator() *SortedSetIterator[T] {
// SortedSetIterator represents an iterator over a sorted set.
// Iteration can occur in natural or reverse order based on use of Next() or Prev().
-type SortedSetIterator[T comparable] struct {
+type SortedSetIterator[T any] struct {
mi *SortedMapIterator[T, struct{}]
}
@@ -208,11 +208,11 @@ func (itr *SortedSetIterator[T]) Seek(val T) {
itr.mi.Seek(val)
}
-type SortedSetBuilder[T comparable] struct {
+type SortedSetBuilder[T any] struct {
s SortedSet[T]
}
-func NewSortedSetBuilder[T comparable](comparer Comparer[T]) *SortedSetBuilder[T] {
+func NewSortedSetBuilder[T any](comparer Comparer[T]) *SortedSetBuilder[T] {
return &SortedSetBuilder[T]{s: NewSortedSet(comparer)}
}