summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/util/generic.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/util/generic.go b/lib/util/generic.go
index 61e045b..a63a814 100644
--- a/lib/util/generic.go
+++ b/lib/util/generic.go
@@ -124,3 +124,24 @@ func (m *SyncMap[K, V]) Range(f func(key K, value V) bool) {
})
}
func (m *SyncMap[K, V]) Store(key K, value V) { m.inner.Store(key, value) }
+
+type Ordered[T interface{ Cmp(T) int }] interface {
+ Cmp(T) int
+}
+
+type NativeOrdered[T constraints.Ordered] struct {
+ Val T
+}
+
+func (a NativeOrdered[T]) Cmp(b NativeOrdered[T]) int {
+ switch {
+ case a.Val < b.Val:
+ return -1
+ case a.Val > b.Val:
+ return 1
+ default:
+ return 0
+ }
+}
+
+var _ Ordered[NativeOrdered[int]] = NativeOrdered[int]{}