aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--go.mod4
-rw-r--r--go.sum4
-rw-r--r--stmutil/containers.go31
3 files changed, 21 insertions, 18 deletions
diff --git a/go.mod b/go.mod
index 5c2b32a..1d58eb9 100644
--- a/go.mod
+++ b/go.mod
@@ -7,9 +7,8 @@ require (
github.com/anacrolix/envpprof v1.1.0
github.com/anacrolix/missinggo v1.3.0
github.com/anacrolix/missinggo/v2 v2.7.1
- github.com/benbjohnson/immutable v0.4.0
+ github.com/benbjohnson/immutable v0.4.1-0.20221220213129-8932b999621d
github.com/stretchr/testify v1.4.0
- golang.org/x/exp v0.0.0-20221026004748-78e5e7837ae6
)
require (
@@ -18,5 +17,6 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
+ golang.org/x/exp v0.0.0-20221026004748-78e5e7837ae6 // indirect
gopkg.in/yaml.v2 v2.2.5 // indirect
)
diff --git a/go.sum b/go.sum
index 4ddd91a..18fed41 100644
--- a/go.sum
+++ b/go.sum
@@ -39,8 +39,8 @@ github.com/anacrolix/tagflag v1.0.0/go.mod h1:1m2U/K6ZT+JZG0+bdMK6qauP49QT4wE5pm
github.com/anacrolix/tagflag v1.1.0/go.mod h1:Scxs9CV10NQatSmbyjqmqmeQNwGzlNe0CMUMIxqHIG8=
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
github.com/benbjohnson/immutable v0.2.0/go.mod h1:uc6OHo6PN2++n98KHLxW8ef4W42ylHiQSENghE1ezxI=
-github.com/benbjohnson/immutable v0.4.0 h1:CTqXbEerYso8YzVPxmWxh2gnoRQbbB9X1quUC8+vGZA=
-github.com/benbjohnson/immutable v0.4.0/go.mod h1:iAr8OjJGLnLmVUr9MZ/rz4PWUy6Ouc2JLYuMArmvAJM=
+github.com/benbjohnson/immutable v0.4.1-0.20221220213129-8932b999621d h1:2qVb9bsAMtmAfnxXltm+6eBzrrS7SZ52c3SedsulaMI=
+github.com/benbjohnson/immutable v0.4.1-0.20221220213129-8932b999621d/go.mod h1:iAr8OjJGLnLmVUr9MZ/rz4PWUy6Ouc2JLYuMArmvAJM=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
diff --git a/stmutil/containers.go b/stmutil/containers.go
index 75a6c48..62765ad 100644
--- a/stmutil/containers.go
+++ b/stmutil/containers.go
@@ -3,13 +3,16 @@ package stmutil
import (
"unsafe"
- "github.com/benbjohnson/immutable"
- "golang.org/x/exp/constraints"
-
"github.com/anacrolix/missinggo/v2/iter"
+ "github.com/benbjohnson/immutable"
)
-type Settish[K constraints.Ordered] interface {
+// This is the type constraint for keys passed through from github.com/benbjohnson/immutable.
+type KeyConstraint interface {
+ comparable
+}
+
+type Settish[K KeyConstraint] interface {
Add(K) Settish[K]
Delete(K) Settish[K]
Contains(K) bool
@@ -18,11 +21,11 @@ type Settish[K constraints.Ordered] interface {
Len() int
}
-type mapToSet[K constraints.Ordered, V any] struct {
+type mapToSet[K KeyConstraint, V any] struct {
m Mappish[K, V]
}
-type interhash[K constraints.Ordered] struct{}
+type interhash[K KeyConstraint] struct{}
func (interhash[K]) Hash(x K) uint32 {
return uint32(nilinterhash(unsafe.Pointer(&x), 0))
@@ -32,11 +35,11 @@ func (interhash[K]) Equal(i, j K) bool {
return i == j
}
-func NewSet[K constraints.Ordered]() Settish[K] {
+func NewSet[K KeyConstraint]() Settish[K] {
return mapToSet[K, struct{}]{NewMap[K, struct{}]()}
}
-func NewSortedSet[K constraints.Ordered, V any](lesser lessFunc[K]) Settish[K] {
+func NewSortedSet[K KeyConstraint, V any](lesser lessFunc[K]) Settish[K] {
return mapToSet[K, V]{NewSortedMap[K, V](lesser)}
}
@@ -72,11 +75,11 @@ func (s mapToSet[K, V]) Iter(cb iter.Callback) {
})
}
-type Map[K constraints.Ordered, V any] struct {
+type Map[K KeyConstraint, V any] struct {
*immutable.Map[K, V]
}
-func NewMap[K constraints.Ordered, V any]() Mappish[K, V] {
+func NewMap[K KeyConstraint, V any]() Mappish[K, V] {
return Map[K, V]{immutable.NewMap[K, V](interhash[K]{})}
}
@@ -109,7 +112,7 @@ func (sm Map[K, V]) Iter(cb iter.Callback) {
})
}
-type SortedMap[K constraints.Ordered, V any] struct {
+type SortedMap[K KeyConstraint, V any] struct {
*immutable.SortedMap[K, V]
}
@@ -142,9 +145,9 @@ func (sm SortedMap[K, V]) Iter(cb iter.Callback) {
})
}
-type lessFunc[T constraints.Ordered] func(l, r T) bool
+type lessFunc[T KeyConstraint] func(l, r T) bool
-type comparer[K constraints.Ordered] struct {
+type comparer[K KeyConstraint] struct {
less lessFunc[K]
}
@@ -158,7 +161,7 @@ func (me comparer[K]) Compare(i, j K) int {
}
}
-func NewSortedMap[K constraints.Ordered, V any](less lessFunc[K]) Mappish[K, V] {
+func NewSortedMap[K KeyConstraint, V any](less lessFunc[K]) Mappish[K, V] {
return SortedMap[K, V]{
SortedMap: immutable.NewSortedMap[K, V](comparer[K]{less}),
}