mirror of
https://github.com/luxfi/container.git
synced 2026-09-24 00:24:34 +00:00
chore: sync dependencies and format code
This commit is contained in:
+2
-4
@@ -9,8 +9,6 @@ import (
|
||||
"errors"
|
||||
"maps"
|
||||
"slices"
|
||||
|
||||
"github.com/luxfi/utils"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -94,7 +92,7 @@ func (m *BiMap[_, V]) HasValue(val V) bool {
|
||||
func (m *BiMap[K, V]) DeleteKey(key K) (V, bool) {
|
||||
val, ok := m.keyToValue[key]
|
||||
if !ok {
|
||||
return utils.Zero[V](), false
|
||||
return zero[V](), false
|
||||
}
|
||||
delete(m.keyToValue, key)
|
||||
delete(m.valueToKey, val)
|
||||
@@ -105,7 +103,7 @@ func (m *BiMap[K, V]) DeleteKey(key K) (V, bool) {
|
||||
func (m *BiMap[K, V]) DeleteValue(val V) (K, bool) {
|
||||
key, ok := m.valueToKey[val]
|
||||
if !ok {
|
||||
return utils.Zero[K](), false
|
||||
return zero[K](), false
|
||||
}
|
||||
delete(m.keyToValue, key)
|
||||
delete(m.valueToKey, val)
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
||||
// See the file LICENSE for licensing terms.
|
||||
|
||||
package bimap
|
||||
|
||||
func zero[T any]() T {
|
||||
var z T
|
||||
return z
|
||||
}
|
||||
@@ -5,8 +5,6 @@ package buffer
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/luxfi/utils"
|
||||
)
|
||||
|
||||
var _ BlockingDeque[int] = (*unboundedBlockingDeque[int])(nil)
|
||||
@@ -61,7 +59,7 @@ func (q *unboundedBlockingDeque[T]) PopRight() (T, bool) {
|
||||
|
||||
for {
|
||||
if q.closed {
|
||||
return utils.Zero[T](), false
|
||||
return zero[T](), false
|
||||
}
|
||||
if q.Deque.Len() != 0 {
|
||||
return q.Deque.PopRight()
|
||||
@@ -75,7 +73,7 @@ func (q *unboundedBlockingDeque[T]) PeekRight() (T, bool) {
|
||||
defer q.lock.RUnlock()
|
||||
|
||||
if q.closed {
|
||||
return utils.Zero[T](), false
|
||||
return zero[T](), false
|
||||
}
|
||||
return q.Deque.PeekRight()
|
||||
}
|
||||
@@ -104,7 +102,7 @@ func (q *unboundedBlockingDeque[T]) PopLeft() (T, bool) {
|
||||
|
||||
for {
|
||||
if q.closed {
|
||||
return utils.Zero[T](), false
|
||||
return zero[T](), false
|
||||
}
|
||||
if q.Deque.Len() != 0 {
|
||||
return q.Deque.PopLeft()
|
||||
@@ -118,7 +116,7 @@ func (q *unboundedBlockingDeque[T]) PeekLeft() (T, bool) {
|
||||
defer q.lock.RUnlock()
|
||||
|
||||
if q.closed {
|
||||
return utils.Zero[T](), false
|
||||
return zero[T](), false
|
||||
}
|
||||
return q.Deque.PeekLeft()
|
||||
}
|
||||
@@ -128,7 +126,7 @@ func (q *unboundedBlockingDeque[T]) Index(i int) (T, bool) {
|
||||
defer q.lock.RUnlock()
|
||||
|
||||
if q.closed {
|
||||
return utils.Zero[T](), false
|
||||
return zero[T](), false
|
||||
}
|
||||
return q.Deque.Index(i)
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
|
||||
package buffer
|
||||
|
||||
import "github.com/luxfi/utils"
|
||||
|
||||
const defaultInitSize = 32
|
||||
|
||||
// An unbounded deque (double-ended queue).
|
||||
@@ -88,12 +86,12 @@ func (b *unboundedSliceDeque[T]) PushLeft(elt T) bool {
|
||||
|
||||
func (b *unboundedSliceDeque[T]) PopLeft() (T, bool) {
|
||||
if b.size == 0 {
|
||||
return utils.Zero[T](), false
|
||||
return zero[T](), false
|
||||
}
|
||||
idx := b.leftmostEltIdx()
|
||||
elt := b.data[idx]
|
||||
// Zero out to prevent memory leak.
|
||||
b.data[idx] = utils.Zero[T]()
|
||||
b.data[idx] = zero[T]()
|
||||
b.size--
|
||||
b.left++
|
||||
b.left %= len(b.data)
|
||||
@@ -102,7 +100,7 @@ func (b *unboundedSliceDeque[T]) PopLeft() (T, bool) {
|
||||
|
||||
func (b *unboundedSliceDeque[T]) PeekLeft() (T, bool) {
|
||||
if b.size == 0 {
|
||||
return utils.Zero[T](), false
|
||||
return zero[T](), false
|
||||
}
|
||||
idx := b.leftmostEltIdx()
|
||||
return b.data[idx], true
|
||||
@@ -110,12 +108,12 @@ func (b *unboundedSliceDeque[T]) PeekLeft() (T, bool) {
|
||||
|
||||
func (b *unboundedSliceDeque[T]) PopRight() (T, bool) {
|
||||
if b.size == 0 {
|
||||
return utils.Zero[T](), false
|
||||
return zero[T](), false
|
||||
}
|
||||
idx := b.rightmostEltIdx()
|
||||
elt := b.data[idx]
|
||||
// Zero out to prevent memory leak.
|
||||
b.data[idx] = utils.Zero[T]()
|
||||
b.data[idx] = zero[T]()
|
||||
b.size--
|
||||
b.right--
|
||||
if b.right < 0 {
|
||||
@@ -126,7 +124,7 @@ func (b *unboundedSliceDeque[T]) PopRight() (T, bool) {
|
||||
|
||||
func (b *unboundedSliceDeque[T]) PeekRight() (T, bool) {
|
||||
if b.size == 0 {
|
||||
return utils.Zero[T](), false
|
||||
return zero[T](), false
|
||||
}
|
||||
idx := b.rightmostEltIdx()
|
||||
return b.data[idx], true
|
||||
@@ -134,7 +132,7 @@ func (b *unboundedSliceDeque[T]) PeekRight() (T, bool) {
|
||||
|
||||
func (b *unboundedSliceDeque[T]) Index(idx int) (T, bool) {
|
||||
if idx < 0 || idx >= b.size {
|
||||
return utils.Zero[T](), false
|
||||
return zero[T](), false
|
||||
}
|
||||
leftmostIdx := b.leftmostEltIdx()
|
||||
idx = (leftmostIdx + idx) % len(b.data)
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
||||
// See the file LICENSE for licensing terms.
|
||||
|
||||
package buffer
|
||||
|
||||
func zero[T any]() T {
|
||||
var z T
|
||||
return z
|
||||
}
|
||||
@@ -8,7 +8,7 @@ require (
|
||||
github.com/luxfi/ids v1.2.9
|
||||
github.com/luxfi/math v1.2.3
|
||||
github.com/luxfi/timer v1.0.1
|
||||
github.com/luxfi/utils v1.1.1
|
||||
github.com/luxfi/utils v1.1.0
|
||||
github.com/stretchr/testify v1.11.1
|
||||
github.com/thepudds/fzgen v0.4.3
|
||||
go.uber.org/mock v0.6.0
|
||||
@@ -18,17 +18,18 @@ require (
|
||||
require (
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/cloudflare/circl v1.6.2 // indirect
|
||||
github.com/cloudflare/circl v1.6.3 // indirect
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||
github.com/dgraph-io/badger/v4 v4.9.0 // indirect
|
||||
github.com/dgraph-io/ristretto/v2 v2.3.0 // indirect
|
||||
github.com/dgraph-io/ristretto/v2 v2.4.0 // indirect
|
||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
||||
github.com/fsnotify/fsnotify v1.9.0 // indirect
|
||||
github.com/go-logr/logr v1.4.3 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/golang/snappy v1.0.0 // indirect
|
||||
github.com/google/flatbuffers v25.12.19+incompatible // indirect
|
||||
github.com/holiman/uint256 v1.3.2 // indirect
|
||||
github.com/klauspost/compress v1.18.2 // indirect
|
||||
github.com/klauspost/compress v1.18.3 // indirect
|
||||
github.com/luxfi/cache v1.1.0 // indirect
|
||||
github.com/luxfi/compress v0.0.2 // indirect
|
||||
github.com/luxfi/concurrent v0.0.2 // indirect
|
||||
@@ -59,10 +60,10 @@ require (
|
||||
go.uber.org/zap v1.27.1 // indirect
|
||||
go.yaml.in/yaml/v2 v2.4.3 // indirect
|
||||
go.yaml.in/yaml/v3 v3.0.4 // indirect
|
||||
golang.org/x/crypto v0.46.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20251219203646-944ab1f22d93 // indirect
|
||||
golang.org/x/net v0.48.0 // indirect
|
||||
golang.org/x/sys v0.39.0 // indirect
|
||||
golang.org/x/crypto v0.47.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20260112195511-716be5621a96 // indirect
|
||||
golang.org/x/net v0.49.0 // indirect
|
||||
golang.org/x/sys v0.40.0 // indirect
|
||||
google.golang.org/protobuf v1.36.11 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
|
||||
@@ -7,8 +7,8 @@ github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
|
||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
||||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
||||
github.com/cloudflare/circl v1.6.2 h1:hL7VBpHHKzrV5WTfHCaBsgx/HGbBYlgrwvNXEVDYYsQ=
|
||||
github.com/cloudflare/circl v1.6.2/go.mod h1:2eXP6Qfat4O/Yhh8BznvKnJ+uzEoTQ6jVKJRn81BiS4=
|
||||
github.com/cloudflare/circl v1.6.3 h1:9GPOhQGF9MCYUeXyMYlqTR6a5gTrgR/fBLXvUgtVcg8=
|
||||
github.com/cloudflare/circl v1.6.3/go.mod h1:2eXP6Qfat4O/Yhh8BznvKnJ+uzEoTQ6jVKJRn81BiS4=
|
||||
github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
@@ -18,16 +18,17 @@ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 h1:NMZiJj8QnKe1LgsbDayM4UoHwbvw
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40=
|
||||
github.com/dgraph-io/badger/v4 v4.9.0 h1:tpqWb0NewSrCYqTvywbcXOhQdWcqephkVkbBmaaqHzc=
|
||||
github.com/dgraph-io/badger/v4 v4.9.0/go.mod h1:5/MEx97uzdPUHR4KtkNt8asfI2T4JiEiQlV7kWUo8c0=
|
||||
github.com/dgraph-io/ristretto/v2 v2.3.0 h1:qTQ38m7oIyd4GAed/QkUZyPFNMnvVWyazGXRwvOt5zk=
|
||||
github.com/dgraph-io/ristretto/v2 v2.3.0/go.mod h1:gpoRV3VzrEY1a9dWAYV6T1U7YzfgttXdd/ZzL1s9OZM=
|
||||
github.com/dgraph-io/ristretto/v2 v2.4.0 h1:I/w09yLjhdcVD2QV192UJcq8dPBaAJb9pOuMyNy0XlU=
|
||||
github.com/dgraph-io/ristretto/v2 v2.4.0/go.mod h1:0KsrXtXvnv0EqnzyowllbVJB8yBonswa2lTCK2gGo9E=
|
||||
github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da h1:aIftn67I1fkbMa512G+w+Pxci9hJPB8oMnkcP3iZF38=
|
||||
github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
|
||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
|
||||
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
|
||||
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
|
||||
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
|
||||
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
@@ -61,8 +62,8 @@ github.com/holiman/uint256 v1.3.2 h1:a9EgMPSC1AAaj1SZL5zIQD3WbwTuHrMGOerLjGmM/TA
|
||||
github.com/holiman/uint256 v1.3.2/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||
github.com/klauspost/compress v1.18.2 h1:iiPHWW0YrcFgpBYhsA6D1+fqHssJscY/Tm/y2Uqnapk=
|
||||
github.com/klauspost/compress v1.18.2/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
|
||||
github.com/klauspost/compress v1.18.3 h1:9PJRvfbmTabkOX8moIpXPbMMbYN60bWImDDU7L+/6zw=
|
||||
github.com/klauspost/compress v1.18.3/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
@@ -101,8 +102,8 @@ github.com/luxfi/sampler v1.0.0 h1:k8Sf6otW83w4pQp0jXLA+g3J/joB7w7SqXQsWmNTOV0=
|
||||
github.com/luxfi/sampler v1.0.0/go.mod h1:f96/ozlj9vFfZj+akLtrHn4VpulQahwB+MQQhpeIekk=
|
||||
github.com/luxfi/timer v1.0.1 h1:3lRf3j0L/fA3Ud0j67cm/BW2In1kz+jxd1HqgKyglYY=
|
||||
github.com/luxfi/timer v1.0.1/go.mod h1:PQ15H3AEUfvWVf0kv5WhIGPWmhr9BxBv/VKLyyekpk4=
|
||||
github.com/luxfi/utils v1.1.1 h1:pbzLLmwt+FPZX23sPur4FHfe0TodnGIj0FK7G/mIxf0=
|
||||
github.com/luxfi/utils v1.1.1/go.mod h1:DL7634uXEcCu2tCBll0bmX0SVnMJeABbmhm5NkLMu78=
|
||||
github.com/luxfi/utils v1.1.0 h1:ti7HvjNwJd4ILDMERJtOAWE9mF8l+zqDVkgWnF7Agic=
|
||||
github.com/luxfi/utils v1.1.0/go.mod h1:ABqhBdGNig0CaDcnNYldv1byS0BTNi5IKPbJSPF1p98=
|
||||
github.com/luxfi/vm v1.0.2 h1:JnMm6QTh1nwWKXFy4Qf9Ej38KyXzFeprcy3Rp8/516s=
|
||||
github.com/luxfi/vm v1.0.2/go.mod h1:cRmy9WL9keIkl5XgGcP1w/RbwiMSYucjGdQ3LrSF0aQ=
|
||||
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
|
||||
@@ -176,10 +177,10 @@ go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.46.0 h1:cKRW/pmt1pKAfetfu+RCEvjvZkA9RimPbh7bhFjGVBU=
|
||||
golang.org/x/crypto v0.46.0/go.mod h1:Evb/oLKmMraqjZ2iQTwDwvCtJkczlDuTmdJXoZVzqU0=
|
||||
golang.org/x/exp v0.0.0-20251219203646-944ab1f22d93 h1:fQsdNF2N+/YewlRZiricy4P1iimyPKZ/xwniHj8Q2a0=
|
||||
golang.org/x/exp v0.0.0-20251219203646-944ab1f22d93/go.mod h1:EPRbTFwzwjXj9NpYyyrvenVh9Y+GFeEvMNh7Xuz7xgU=
|
||||
golang.org/x/crypto v0.47.0 h1:V6e3FRj+n4dbpw86FJ8Fv7XVOql7TEwpHapKoMJ/GO8=
|
||||
golang.org/x/crypto v0.47.0/go.mod h1:ff3Y9VzzKbwSSEzWqJsJVBnWmRwRSHt/6Op5n9bQc4A=
|
||||
golang.org/x/exp v0.0.0-20260112195511-716be5621a96 h1:Z/6YuSHTLOHfNFdb8zVZomZr7cqNgTJvA8+Qz75D8gU=
|
||||
golang.org/x/exp v0.0.0-20260112195511-716be5621a96/go.mod h1:nzimsREAkjBCIEFtHiYkrJyT+2uy9YZJB7H1k68CXZU=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
@@ -189,8 +190,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY
|
||||
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
|
||||
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/net v0.0.0-20220607020251-c690dde0001d/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.48.0 h1:zyQRTTrjc33Lhh0fBgT/H3oZq9WuvRR5gPC70xpDiQU=
|
||||
golang.org/x/net v0.48.0/go.mod h1:+ndRgGjkh8FGtu1w1FGbEC31if4VrNVMuKTgcAAnQRY=
|
||||
golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o=
|
||||
golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
@@ -212,16 +213,16 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk=
|
||||
golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||
golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ=
|
||||
golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.32.0 h1:ZD01bjUt1FQ9WJ0ClOL5vxgxOI/sVCNgX1YtKwcY0mU=
|
||||
golang.org/x/text v0.32.0/go.mod h1:o/rUWzghvpD5TXrTIBuJU77MTaN0ljMWE47kxGJQ7jY=
|
||||
golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE=
|
||||
golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
|
||||
+5
-7
@@ -5,8 +5,6 @@ package heap
|
||||
|
||||
import (
|
||||
"container/heap"
|
||||
|
||||
"github.com/luxfi/utils"
|
||||
)
|
||||
|
||||
var _ heap.Interface = (*indexedQueue[int, int])(nil)
|
||||
@@ -47,12 +45,12 @@ func (m *Map[K, V]) Push(k K, v V) (V, bool) {
|
||||
}
|
||||
|
||||
heap.Push(m.queue, entry[K, V]{k: k, v: v})
|
||||
return utils.Zero[V](), false
|
||||
return zero[V](), false
|
||||
}
|
||||
|
||||
func (m *Map[K, V]) Pop() (K, V, bool) {
|
||||
if m.Len() == 0 {
|
||||
return utils.Zero[K](), utils.Zero[V](), false
|
||||
return zero[K](), zero[V](), false
|
||||
}
|
||||
|
||||
popped := heap.Pop(m.queue).(entry[K, V])
|
||||
@@ -61,7 +59,7 @@ func (m *Map[K, V]) Pop() (K, V, bool) {
|
||||
|
||||
func (m *Map[K, V]) Peek() (K, V, bool) {
|
||||
if m.Len() == 0 {
|
||||
return utils.Zero[K](), utils.Zero[V](), false
|
||||
return zero[K](), zero[V](), false
|
||||
}
|
||||
|
||||
entry := m.queue.entries[0]
|
||||
@@ -77,7 +75,7 @@ func (m *Map[K, V]) Remove(k K) (V, bool) {
|
||||
removed := heap.Remove(m.queue, i).(entry[K, V])
|
||||
return removed.v, true
|
||||
}
|
||||
return utils.Zero[V](), false
|
||||
return zero[V](), false
|
||||
}
|
||||
|
||||
func (m *Map[K, V]) Contains(k K) bool {
|
||||
@@ -90,7 +88,7 @@ func (m *Map[K, V]) Get(k K) (V, bool) {
|
||||
got := m.queue.entries[i]
|
||||
return got.v, true
|
||||
}
|
||||
return utils.Zero[V](), false
|
||||
return zero[V](), false
|
||||
}
|
||||
|
||||
func (m *Map[K, V]) Fix(k K) {
|
||||
|
||||
+3
-5
@@ -5,8 +5,6 @@ package heap
|
||||
|
||||
import (
|
||||
"container/heap"
|
||||
|
||||
"github.com/luxfi/utils"
|
||||
)
|
||||
|
||||
var _ heap.Interface = (*queue[int])(nil)
|
||||
@@ -44,7 +42,7 @@ func (q *Queue[T]) Push(t T) {
|
||||
|
||||
func (q *Queue[T]) Pop() (T, bool) {
|
||||
if q.Len() == 0 {
|
||||
return utils.Zero[T](), false
|
||||
return zero[T](), false
|
||||
}
|
||||
|
||||
return heap.Pop(q.queue).(T), true
|
||||
@@ -52,7 +50,7 @@ func (q *Queue[T]) Pop() (T, bool) {
|
||||
|
||||
func (q *Queue[T]) Peek() (T, bool) {
|
||||
if q.Len() == 0 {
|
||||
return utils.Zero[T](), false
|
||||
return zero[T](), false
|
||||
}
|
||||
|
||||
return q.queue.entries[0], true
|
||||
@@ -87,7 +85,7 @@ func (q *queue[T]) Pop() any {
|
||||
end := len(q.entries) - 1
|
||||
|
||||
popped := q.entries[end]
|
||||
q.entries[end] = utils.Zero[T]()
|
||||
q.entries[end] = zero[T]()
|
||||
q.entries = q.entries[:end]
|
||||
|
||||
return popped
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
||||
// See the file LICENSE for licensing terms.
|
||||
|
||||
package heap
|
||||
|
||||
func zero[T any]() T {
|
||||
var z T
|
||||
return z
|
||||
}
|
||||
+1
-3
@@ -3,8 +3,6 @@
|
||||
|
||||
package iterator
|
||||
|
||||
import "github.com/luxfi/utils"
|
||||
|
||||
var _ Iterator[any] = Empty[any]{}
|
||||
|
||||
// Empty is an iterator with no elements.
|
||||
@@ -15,7 +13,7 @@ func (Empty[_]) Next() bool {
|
||||
}
|
||||
|
||||
func (Empty[T]) Value() T {
|
||||
return utils.Zero[T]()
|
||||
return zero[T]()
|
||||
}
|
||||
|
||||
func (Empty[_]) Release() {}
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/luxfi/ids"
|
||||
"github.com/luxfi/container/iterator"
|
||||
"github.com/luxfi/ids"
|
||||
)
|
||||
|
||||
func TestMerge(t *testing.T) {
|
||||
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
"github.com/google/btree"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/luxfi/ids"
|
||||
"github.com/luxfi/container/iterator"
|
||||
"github.com/luxfi/ids"
|
||||
)
|
||||
|
||||
var defaultTreeDegree = 2
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
||||
// See the file LICENSE for licensing terms.
|
||||
|
||||
package iterator
|
||||
|
||||
func zero[T any]() T {
|
||||
var z T
|
||||
return z
|
||||
}
|
||||
+7
-9
@@ -3,8 +3,6 @@
|
||||
|
||||
package linked
|
||||
|
||||
import "github.com/luxfi/utils"
|
||||
|
||||
type keyValue[K, V any] struct {
|
||||
key K
|
||||
value V
|
||||
@@ -66,7 +64,7 @@ func (lh *Hashmap[K, V]) Get(key K) (V, bool) {
|
||||
if e, ok := lh.entryMap[key]; ok {
|
||||
return e.Value.value, true
|
||||
}
|
||||
return utils.Zero[V](), false
|
||||
return zero[V](), false
|
||||
}
|
||||
|
||||
func (lh *Hashmap[K, V]) Delete(key K) bool {
|
||||
@@ -99,14 +97,14 @@ func (lh *Hashmap[K, V]) Oldest() (K, V, bool) {
|
||||
if e := lh.entryList.Front(); e != nil {
|
||||
return e.Value.key, e.Value.value, true
|
||||
}
|
||||
return utils.Zero[K](), utils.Zero[V](), false
|
||||
return zero[K](), zero[V](), false
|
||||
}
|
||||
|
||||
func (lh *Hashmap[K, V]) Newest() (K, V, bool) {
|
||||
if e := lh.entryList.Back(); e != nil {
|
||||
return e.Value.key, e.Value.value, true
|
||||
}
|
||||
return utils.Zero[K](), utils.Zero[V](), false
|
||||
return zero[K](), zero[V](), false
|
||||
}
|
||||
|
||||
func (lh *Hashmap[K, V]) NewIterator() *Iterator[K, V] {
|
||||
@@ -127,8 +125,8 @@ type Iterator[K comparable, V any] struct {
|
||||
func (it *Iterator[K, V]) Next() bool {
|
||||
// If the iterator has been exhausted, there is no next value.
|
||||
if it.exhausted {
|
||||
it.key = utils.Zero[K]()
|
||||
it.value = utils.Zero[V]()
|
||||
it.key = zero[K]()
|
||||
it.value = zero[V]()
|
||||
it.next = nil
|
||||
return false
|
||||
}
|
||||
@@ -139,8 +137,8 @@ func (it *Iterator[K, V]) Next() bool {
|
||||
oldest := it.lh.entryList.Front()
|
||||
if oldest == nil {
|
||||
it.exhausted = true
|
||||
it.key = utils.Zero[K]()
|
||||
it.value = utils.Zero[V]()
|
||||
it.key = zero[K]()
|
||||
it.value = zero[V]()
|
||||
it.next = nil
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
||||
// See the file LICENSE for licensing terms.
|
||||
|
||||
package linked
|
||||
|
||||
func zero[T any]() T {
|
||||
var z T
|
||||
return z
|
||||
}
|
||||
@@ -5,8 +5,6 @@ package linkedhashmap
|
||||
|
||||
import (
|
||||
"container/list"
|
||||
|
||||
"github.com/luxfi/utils"
|
||||
)
|
||||
|
||||
var _ Iter[int, struct{}] = (*iterator[int, struct{}])(nil)
|
||||
@@ -33,8 +31,8 @@ type iterator[K comparable, V any] struct {
|
||||
func (it *iterator[K, V]) Next() bool {
|
||||
// If the iterator has been exhausted, there is no next value.
|
||||
if it.exhausted {
|
||||
it.key = utils.Zero[K]()
|
||||
it.value = utils.Zero[V]()
|
||||
it.key = zero[K]()
|
||||
it.value = zero[V]()
|
||||
it.next = nil
|
||||
return false
|
||||
}
|
||||
@@ -48,8 +46,8 @@ func (it *iterator[K, V]) Next() bool {
|
||||
oldest := it.lh.entryList.Front()
|
||||
if oldest == nil {
|
||||
it.exhausted = true
|
||||
it.key = utils.Zero[K]()
|
||||
it.value = utils.Zero[V]()
|
||||
it.key = zero[K]()
|
||||
it.value = zero[V]()
|
||||
it.next = nil
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@ package linkedhashmap
|
||||
import (
|
||||
"container/list"
|
||||
"sync"
|
||||
|
||||
"github.com/luxfi/utils"
|
||||
)
|
||||
|
||||
var _ LinkedHashmap[int, struct{}] = (*linkedHashmap[int, struct{}])(nil)
|
||||
@@ -111,7 +109,7 @@ func (lh *linkedHashmap[K, V]) get(key K) (V, bool) {
|
||||
kv := e.Value.(keyValue[K, V])
|
||||
return kv.value, true
|
||||
}
|
||||
return utils.Zero[V](), false
|
||||
return zero[V](), false
|
||||
}
|
||||
|
||||
func (lh *linkedHashmap[K, V]) delete(key K) bool {
|
||||
@@ -132,7 +130,7 @@ func (lh *linkedHashmap[K, V]) oldest() (K, V, bool) {
|
||||
kv := val.Value.(keyValue[K, V])
|
||||
return kv.key, kv.value, true
|
||||
}
|
||||
return utils.Zero[K](), utils.Zero[V](), false
|
||||
return zero[K](), zero[V](), false
|
||||
}
|
||||
|
||||
func (lh *linkedHashmap[K, V]) newest() (K, V, bool) {
|
||||
@@ -140,7 +138,7 @@ func (lh *linkedHashmap[K, V]) newest() (K, V, bool) {
|
||||
kv := val.Value.(keyValue[K, V])
|
||||
return kv.key, kv.value, true
|
||||
}
|
||||
return utils.Zero[K](), utils.Zero[V](), false
|
||||
return zero[K](), zero[V](), false
|
||||
}
|
||||
|
||||
func (lh *linkedHashmap[K, V]) NewIterator() Iter[K, V] {
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
||||
// See the file LICENSE for licensing terms.
|
||||
|
||||
package linkedhashmap
|
||||
|
||||
func zero[T any]() T {
|
||||
var z T
|
||||
return z
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
||||
// See the file LICENSE for licensing terms.
|
||||
|
||||
package sampler
|
||||
|
||||
import "slices"
|
||||
|
||||
func sortByCompare[T interface{ Compare(T) int }](s []T) {
|
||||
slices.SortFunc(s, func(a, b T) int {
|
||||
return a.Compare(b)
|
||||
})
|
||||
}
|
||||
@@ -54,7 +54,7 @@ func (s *weightedArray) Initialize(weights []uint64) error {
|
||||
}
|
||||
|
||||
// Optimize so that the array is closer to the uniform distribution
|
||||
utils.Sort(s.arr)
|
||||
sortByCompare(s.arr)
|
||||
|
||||
maxIndex := len(s.arr) - 1
|
||||
oneIfOdd := 1 & maxIndex
|
||||
|
||||
@@ -60,7 +60,7 @@ func (s *weightedHeap) Initialize(weights []uint64) error {
|
||||
}
|
||||
|
||||
// Optimize so that the most probable values are at the top of the heap
|
||||
utils.Sort(s.heap)
|
||||
sortByCompare(s.heap)
|
||||
|
||||
// Initialize the heap
|
||||
for i := len(s.heap) - 1; i > 0; i-- {
|
||||
|
||||
@@ -52,7 +52,7 @@ func (s *weightedLinear) Initialize(weights []uint64) error {
|
||||
}
|
||||
|
||||
// Optimize so that the most probable values are at the front of the array
|
||||
utils.Sort(s.arr)
|
||||
sortByCompare(s.arr)
|
||||
|
||||
for i := 1; i < len(s.arr); i++ {
|
||||
newWeight, err := math.Add64(
|
||||
|
||||
+1
-2
@@ -5,7 +5,6 @@ package setmap
|
||||
|
||||
import (
|
||||
"github.com/luxfi/math/set"
|
||||
"github.com/luxfi/utils"
|
||||
)
|
||||
|
||||
type Entry[K any, V comparable] struct {
|
||||
@@ -106,7 +105,7 @@ func (m *SetMap[K, V]) DeleteKey(key K) (set.Set[V], bool) {
|
||||
func (m *SetMap[K, V]) DeleteValue(val V) (K, set.Set[V], bool) {
|
||||
key, ok := m.valueToKey[val]
|
||||
if !ok {
|
||||
return utils.Zero[K](), nil, false
|
||||
return zero[K](), nil, false
|
||||
}
|
||||
set, _ := m.DeleteKey(key)
|
||||
return key, set, true
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
||||
// See the file LICENSE for licensing terms.
|
||||
|
||||
package setmap
|
||||
|
||||
func zero[T any]() T {
|
||||
var z T
|
||||
return z
|
||||
}
|
||||
+1
-2
@@ -7,7 +7,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/luxfi/utils"
|
||||
"github.com/luxfi/container/buffer"
|
||||
"github.com/luxfi/timer/mockable"
|
||||
)
|
||||
@@ -83,7 +82,7 @@ func (w *window[T]) Oldest() (T, bool) {
|
||||
|
||||
oldest, ok := w.elements.PeekLeft()
|
||||
if !ok {
|
||||
return utils.Zero[T](), false
|
||||
return zero[T](), false
|
||||
}
|
||||
return oldest.value, true
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
||||
// See the file LICENSE for licensing terms.
|
||||
|
||||
package window
|
||||
|
||||
func zero[T any]() T {
|
||||
var z T
|
||||
return z
|
||||
}
|
||||
Reference in New Issue
Block a user