From 3b0d815749f943fc856aad66d0c23174bf9ada60 Mon Sep 17 00:00:00 2001 From: Christian Haudum Date: Mon, 16 Dec 2024 12:14:32 +0100 Subject: [PATCH] fix(deps): Downgrade hyperloglog to 0.2.0 (#15424) (#15426) Co-authored-by: Shantanu Alshi --- go.mod | 3 +- go.sum | 6 +- .../axiomhq/hyperloglog/hyperloglog.go | 34 +- .../github.com/axiomhq/hyperloglog/sparse.go | 59 +-- vendor/github.com/kamstrup/intmap/.gitignore | 1 - vendor/github.com/kamstrup/intmap/LICENSE | 23 - vendor/github.com/kamstrup/intmap/README.md | 52 --- vendor/github.com/kamstrup/intmap/map64.go | 442 ------------------ vendor/github.com/kamstrup/intmap/set.go | 59 --- vendor/modules.txt | 7 +- 10 files changed, 39 insertions(+), 647 deletions(-) delete mode 100644 vendor/github.com/kamstrup/intmap/.gitignore delete mode 100644 vendor/github.com/kamstrup/intmap/LICENSE delete mode 100644 vendor/github.com/kamstrup/intmap/README.md delete mode 100644 vendor/github.com/kamstrup/intmap/map64.go delete mode 100644 vendor/github.com/kamstrup/intmap/set.go diff --git a/go.mod b/go.mod index b73e6dc71ad77..ed49760f3c000 100644 --- a/go.mod +++ b/go.mod @@ -116,7 +116,7 @@ require ( github.com/DmitriyVTitov/size v1.5.0 github.com/IBM/go-sdk-core/v5 v5.18.3 github.com/IBM/ibm-cos-sdk-go v1.12.0 - github.com/axiomhq/hyperloglog v0.2.1 + github.com/axiomhq/hyperloglog v0.2.0 github.com/buger/jsonparser v1.1.1 github.com/d4l3k/messagediff v1.2.1 github.com/dolthub/swiss v0.2.1 @@ -171,7 +171,6 @@ require ( github.com/gorilla/handlers v1.5.2 // indirect github.com/hashicorp/golang-lru v0.6.0 // indirect github.com/imdario/mergo v0.3.16 // indirect - github.com/kamstrup/intmap v0.5.0 // indirect github.com/lufia/plan9stats v0.0.0-20220913051719-115f729f3c8c // indirect github.com/moby/docker-image-spec v1.3.1 // indirect github.com/moby/sys/userns v0.1.0 // indirect diff --git a/go.sum b/go.sum index e1660fc3c7fb0..df31d6a0b9abf 100644 --- a/go.sum +++ b/go.sum @@ -1006,8 +1006,8 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.16.1 h1:xsOtPAvHqhvQvBza5ohaUcfq1Lce github.com/aws/aws-sdk-go-v2/service/sts v1.16.1/go.mod h1:Aq2/Qggh2oemSfyHH+EO4UBbgWG6zFCXLHYI4ILTY7w= github.com/aws/smithy-go v1.11.1 h1:IQ+lPZVkSM3FRtyaDox41R8YS6iwPMYIreejOgPW49g= github.com/aws/smithy-go v1.11.1/go.mod h1:3xHYmszWVx2c0kIwQeEVf9uSm4fYZt67FBJnwub1bgM= -github.com/axiomhq/hyperloglog v0.2.1 h1:z+rouIlYdpZ+DVfnQigBimhQL6OKHIL3e8+hMiud5/c= -github.com/axiomhq/hyperloglog v0.2.1/go.mod h1:WCdOZ8PNJKNcBw3xFZ7iHlnUn1nDVHK/XToLjjmySh4= +github.com/axiomhq/hyperloglog v0.2.0 h1:u1XT3yyY1rjzlWuP6NQIrV4bRYHOaqZaovqjcBEvZJo= +github.com/axiomhq/hyperloglog v0.2.0/go.mod h1:GcgMjz9gaDKZ3G0UMS6Fq/VkZ4l7uGgcJyxA7M+omIM= github.com/baidubce/bce-sdk-go v0.9.206 h1:1nmKLHWCkPzpmVATiC15+4q/lYkx4PdXd2qKfYUzTes= github.com/baidubce/bce-sdk-go v0.9.206/go.mod h1:zbYJMQwE4IZuyrJiFO8tO8NbtYiKTFTbwh4eIsqjVdg= github.com/bboreham/go-loser v0.0.0-20230920113527-fcc2c21820a3 h1:6df1vn4bBlDDo4tARvBm7l6KA9iVMnE3NWizDeWSrps= @@ -2030,8 +2030,6 @@ github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4d github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/jung-kurt/gofpdf v1.0.0/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes= github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes= -github.com/kamstrup/intmap v0.5.0 h1:WY7OJQeG7Ujc9zpPTO6PraDGSveG9js9wCPoI2q8wJQ= -github.com/kamstrup/intmap v0.5.0/go.mod h1:gWUVWHKzWj8xpJVFf5GC0O26bWmv3GqdnIX/LMT6Aq4= github.com/kardianos/service v1.0.0/go.mod h1:8CzDhVuCuugtsHyZoTvsOBuvonN/UDBvl0kH+BUxvbo= github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4= github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA= diff --git a/vendor/github.com/axiomhq/hyperloglog/hyperloglog.go b/vendor/github.com/axiomhq/hyperloglog/hyperloglog.go index 24b39e43562aa..638b291cd23a9 100644 --- a/vendor/github.com/axiomhq/hyperloglog/hyperloglog.go +++ b/vendor/github.com/axiomhq/hyperloglog/hyperloglog.go @@ -18,7 +18,7 @@ type Sketch struct { p uint8 m uint32 alpha float64 - tmpSet *set + tmpSet set sparseList *compressedList regs []uint8 } @@ -45,7 +45,7 @@ func NewSketch(precision uint8, sparse bool) (*Sketch, error) { alpha: alpha(float64(m)), } if sparse { - s.tmpSet = newSet(0) + s.tmpSet = set{} s.sparseList = newCompressedList(0) } else { s.regs = make([]uint8, m) @@ -65,7 +65,7 @@ func (sk *Sketch) Clone() *Sketch { } func (sk *Sketch) maybeToNormal() { - if uint32(sk.tmpSet.Len())*100 > sk.m { + if uint32(len(sk.tmpSet))*100 > sk.m { sk.mergeSparse() if uint32(sk.sparseList.Len()) > sk.m { sk.toNormal() @@ -90,7 +90,9 @@ func (sk *Sketch) Merge(other *Sketch) error { } func (sk *Sketch) mergeSparseSketch(other *Sketch) { - sk.tmpSet.Merge(other.tmpSet) + for k := range other.tmpSet { + sk.tmpSet.add(k) + } for iter := other.sparseList.Iter(); iter.HasNext(); { sk.tmpSet.add(iter.Next()) } @@ -103,10 +105,10 @@ func (sk *Sketch) mergeDenseSketch(other *Sketch) { } if other.sparse() { - other.tmpSet.ForEach(func(k uint32) { + for k := range other.tmpSet { i, r := decodeHash(k, other.p, pp) sk.insert(i, r) - }) + } for iter := other.sparseList.Iter(); iter.HasNext(); { i, r := decodeHash(iter.Next(), other.p, pp) sk.insert(i, r) @@ -121,7 +123,7 @@ func (sk *Sketch) mergeDenseSketch(other *Sketch) { } func (sk *Sketch) toNormal() { - if sk.tmpSet.Len() > 0 { + if len(sk.tmpSet) > 0 { sk.mergeSparse() } @@ -163,17 +165,17 @@ func (sk *Sketch) Estimate() uint64 { } func (sk *Sketch) mergeSparse() { - if sk.tmpSet.Len() == 0 { + if len(sk.tmpSet) == 0 { return } - keys := make(uint64Slice, 0, sk.tmpSet.Len()) - sk.tmpSet.ForEach(func(k uint32) { + keys := make(uint64Slice, 0, len(sk.tmpSet)) + for k := range sk.tmpSet { keys = append(keys, k) - }) + } sort.Sort(keys) - newList := newCompressedList(4*sk.tmpSet.Len() + sk.sparseList.Len()) + newList := newCompressedList(4*len(sk.tmpSet) + len(sk.sparseList.b)) for iter, i := sk.sparseList.Iter(), 0; iter.HasNext() || i < len(keys); { if !iter.HasNext() { newList.Append(keys[i]) @@ -199,7 +201,7 @@ func (sk *Sketch) mergeSparse() { } sk.sparseList = newList - sk.tmpSet = newSet(0) + sk.tmpSet = set{} } // MarshalBinary implements the encoding.BinaryMarshaler interface. @@ -275,7 +277,7 @@ func (sk *Sketch) UnmarshalBinary(data []byte) error { sparse := data[3] == byte(1) // Make a newSketch Sketch if the precision doesn't match or if the Sketch was used - if sk.p != p || sk.regs != nil || sk.tmpSet.Len() > 0 || (sk.sparseList != nil && sk.sparseList.Len() > 0) { + if sk.p != p || sk.regs != nil || len(sk.tmpSet) > 0 || (sk.sparseList != nil && sk.sparseList.Len() > 0) { newh, err := NewSketch(p, sparse) if err != nil { return err @@ -290,14 +292,14 @@ func (sk *Sketch) UnmarshalBinary(data []byte) error { // Unmarshal the tmp_set. tssz := binary.BigEndian.Uint32(data[4:8]) - sk.tmpSet = newSet(int(tssz)) + sk.tmpSet = make(map[uint32]struct{}, tssz) // We need to unmarshal tssz values in total, and each value requires us // to read 4 bytes. tsLastByte := int((tssz * 4) + 8) for i := 8; i < tsLastByte; i += 4 { k := binary.BigEndian.Uint32(data[i : i+4]) - sk.tmpSet.add(k) + sk.tmpSet[k] = struct{}{} } // Unmarshal the sparse Sketch. diff --git a/vendor/github.com/axiomhq/hyperloglog/sparse.go b/vendor/github.com/axiomhq/hyperloglog/sparse.go index 0151740df9859..8c457d3278224 100644 --- a/vendor/github.com/axiomhq/hyperloglog/sparse.go +++ b/vendor/github.com/axiomhq/hyperloglog/sparse.go @@ -2,8 +2,6 @@ package hyperloglog import ( "math/bits" - - "github.com/kamstrup/intmap" ) func getIndex(k uint32, p, pp uint8) uint32 { @@ -36,61 +34,37 @@ func decodeHash(k uint32, p, pp uint8) (uint32, uint8) { return getIndex(k, p, pp), r } -type set struct { - m *intmap.Set[uint32] -} - -func newSet(size int) *set { - return &set{m: intmap.NewSet[uint32](size)} -} - -func (s *set) ForEach(fn func(v uint32)) { - s.m.ForEach(func(v uint32) bool { - fn(v) - return true - }) -} - -func (s *set) Merge(other *set) { - other.m.ForEach(func(v uint32) bool { - s.m.Add(v) - return true - }) -} - -func (s *set) Len() int { - return s.m.Len() -} +type set map[uint32]struct{} -func (s *set) add(v uint32) bool { - if s.m.Has(v) { +func (s set) add(v uint32) bool { + _, ok := s[v] + if ok { return false } - s.m.Add(v) + s[v] = struct{}{} return true } -func (s *set) Clone() *set { +func (s set) Clone() set { if s == nil { return nil } - newS := intmap.NewSet[uint32](s.m.Len()) - s.m.ForEach(func(v uint32) bool { - newS.Add(v) - return true - }) - return &set{m: newS} + newS := make(map[uint32]struct{}, len(s)) + for k, v := range s { + newS[k] = v + } + return newS } -func (s *set) MarshalBinary() (data []byte, err error) { +func (s set) MarshalBinary() (data []byte, err error) { // 4 bytes for the size of the set, and 4 bytes for each key. // list. - data = make([]byte, 0, 4+(4*s.m.Len())) + data = make([]byte, 0, 4+(4*len(s))) // Length of the set. We only need 32 bits because the size of the set // couldn't exceed that on 32 bit architectures. - sl := s.m.Len() + sl := len(s) data = append(data, []byte{ byte(sl >> 24), byte(sl >> 16), @@ -99,15 +73,14 @@ func (s *set) MarshalBinary() (data []byte, err error) { }...) // Marshal each element in the set. - s.m.ForEach(func(k uint32) bool { + for k := range s { data = append(data, []byte{ byte(k >> 24), byte(k >> 16), byte(k >> 8), byte(k), }...) - return true - }) + } return data, nil } diff --git a/vendor/github.com/kamstrup/intmap/.gitignore b/vendor/github.com/kamstrup/intmap/.gitignore deleted file mode 100644 index 1377554ebea6f..0000000000000 --- a/vendor/github.com/kamstrup/intmap/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.swp diff --git a/vendor/github.com/kamstrup/intmap/LICENSE b/vendor/github.com/kamstrup/intmap/LICENSE deleted file mode 100644 index 1eac633b0cd30..0000000000000 --- a/vendor/github.com/kamstrup/intmap/LICENSE +++ /dev/null @@ -1,23 +0,0 @@ -Copyright (c) 2016, Brent Pedersen - Bioinformatics -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/kamstrup/intmap/README.md b/vendor/github.com/kamstrup/intmap/README.md deleted file mode 100644 index e1a1e7003aff8..0000000000000 --- a/vendor/github.com/kamstrup/intmap/README.md +++ /dev/null @@ -1,52 +0,0 @@ -Fast hashmap with integer keys for Golang - -[![GoDoc](https://godoc.org/github.com/kamstrup/intmap?status.svg)](https://godoc.org/github.com/kamstrup/intmap) -[![Go Report Card](https://goreportcard.com/badge/github.com/kamstrup/intmap)](https://goreportcard.com/report/github.com/kamstrup/intmap) - -# intmap - - import "github.com/kamstrup/intmap" - -Package intmap is a fast hashmap implementation for Golang, specialized for maps with integer type keys. -The values can be of any type. - -It is a full port of https://github.com/brentp/intintmap to use type parameters (aka generics). - -It interleaves keys and values in the same underlying array to improve locality. -This is also known as open addressing with linear probing. - -It is up to 3X faster than the builtin map: -``` -name time/op -Map64Fill-8 201ms ± 5% -IntIntMapFill-8 207ms ±31% -StdMapFill-8 371ms ±11% -Map64Get10PercentHitRate-8 148µs ±40% -IntIntMapGet10PercentHitRate-8 171µs ±50% -StdMapGet10PercentHitRate-8 171µs ±33% -Map64Get100PercentHitRate-8 4.50ms ± 5% -IntIntMapGet100PercentHitRate-8 4.82ms ± 6% -StdMapGet100PercentHitRate-8 15.5ms ±32% -``` - -## Usage - -```go -m := intmap.New[int64,int64](32768) -m.Put(int64(1234), int64(-222)) -m.Put(int64(123), int64(33)) - -v, ok := m.Get(int64(222)) -v, ok := m.Get(int64(333)) - -m.Del(int64(222)) -m.Del(int64(333)) - -fmt.Println(m.Len()) - -m.ForEach(func(k int64, v int64) { - fmt.Printf("key: %d, value: %d\n", k, v) -}) - -m.Clear() // all gone, but buffers kept -``` diff --git a/vendor/github.com/kamstrup/intmap/map64.go b/vendor/github.com/kamstrup/intmap/map64.go deleted file mode 100644 index ec8084db9f776..0000000000000 --- a/vendor/github.com/kamstrup/intmap/map64.go +++ /dev/null @@ -1,442 +0,0 @@ -// Package intmap contains a fast hashmap implementation for maps with keys of any integer type -package intmap - -import ( - "iter" - "math" -) - -// IntKey is a type constraint for values that can be used as keys in Map -type IntKey interface { - ~int | ~uint | ~int64 | ~uint64 | ~int32 | ~uint32 | ~int16 | ~uint16 | ~int8 | ~uint8 | ~uintptr -} - -type pair[K IntKey, V any] struct { - K K - V V -} - -const fillFactor64 = 0.7 - -func phiMix64(x int) int { - h := x * 0x9E3779B9 - return h ^ (h >> 16) -} - -// Map is a hashmap where the keys are some any integer type. -// It is valid to call methods that read a nil map, similar to a standard Go map. -// Methods valid on a nil map are Has, Get, Len, and ForEach. -type Map[K IntKey, V any] struct { - data []pair[K, V] // key-value pairs - size int - - zeroVal V // value of 'zero' key - hasZeroKey bool // do we have 'zero' key in the map? -} - -// New creates a new map with keys being any integer subtype. -// The map can store up to the given capacity before reallocation and rehashing occurs. -func New[K IntKey, V any](capacity int) *Map[K, V] { - return &Map[K, V]{ - data: make([]pair[K, V], arraySize(capacity, fillFactor64)), - } -} - -// Has checks if the given key exists in the map. -// Calling this method on a nil map will return false. -func (m *Map[K, V]) Has(key K) bool { - if m == nil { - return false - } - - if key == K(0) { - return m.hasZeroKey - } - - idx := m.startIndex(key) - p := m.data[idx] - - if p.K == K(0) { // end of chain already - return false - } - if p.K == key { // we check zero prior to this call - return true - } - - // hash collision, seek next hash match, bailing on first empty - for { - idx = m.nextIndex(idx) - p = m.data[idx] - if p.K == K(0) { - return false - } - if p.K == key { - return true - } - } -} - -// Get returns the value if the key is found. -// If you just need to check for existence it is easier to use Has. -// Calling this method on a nil map will return the zero value for V and false. -func (m *Map[K, V]) Get(key K) (V, bool) { - if m == nil { - var zero V - return zero, false - } - - if key == K(0) { - if m.hasZeroKey { - return m.zeroVal, true - } - var zero V - return zero, false - } - - idx := m.startIndex(key) - p := m.data[idx] - - if p.K == K(0) { // end of chain already - var zero V - return zero, false - } - if p.K == key { // we check zero prior to this call - return p.V, true - } - - // hash collision, seek next hash match, bailing on first empty - for { - idx = m.nextIndex(idx) - p = m.data[idx] - if p.K == K(0) { - var zero V - return zero, false - } - if p.K == key { - return p.V, true - } - } -} - -// Put adds or updates key with value val. -func (m *Map[K, V]) Put(key K, val V) { - if key == K(0) { - if !m.hasZeroKey { - m.size++ - } - m.zeroVal = val - m.hasZeroKey = true - return - } - - idx := m.startIndex(key) - p := &m.data[idx] - - if p.K == K(0) { // end of chain already - p.K = key - p.V = val - if m.size >= m.sizeThreshold() { - m.rehash() - } else { - m.size++ - } - return - } else if p.K == key { // overwrite existing value - p.V = val - return - } - - // hash collision, seek next empty or key match - for { - idx = m.nextIndex(idx) - p = &m.data[idx] - - if p.K == K(0) { - p.K = key - p.V = val - if m.size >= m.sizeThreshold() { - m.rehash() - } else { - m.size++ - } - return - } else if p.K == key { - p.V = val - return - } - } -} - -// PutIfNotExists adds the key-value pair only if the key does not already exist -// in the map, and returns the current value associated with the key and a boolean -// indicating whether the value was newly added or not. -func (m *Map[K, V]) PutIfNotExists(key K, val V) (V, bool) { - if key == K(0) { - if m.hasZeroKey { - return m.zeroVal, false - } - m.zeroVal = val - m.hasZeroKey = true - m.size++ - return val, true - } - - idx := m.startIndex(key) - p := &m.data[idx] - - if p.K == K(0) { // end of chain already - p.K = key - p.V = val - m.size++ - if m.size >= m.sizeThreshold() { - m.rehash() - } - return val, true - } else if p.K == key { - return p.V, false - } - - // hash collision, seek next hash match, bailing on first empty - for { - idx = m.nextIndex(idx) - p = &m.data[idx] - - if p.K == K(0) { - p.K = key - p.V = val - m.size++ - if m.size >= m.sizeThreshold() { - m.rehash() - } - return val, true - } else if p.K == key { - return p.V, false - } - } -} - -// ForEach iterates through key-value pairs in the map while the function f returns true. -// This method returns immediately if invoked on a nil map. -// -// The iteration order of a Map is not defined, so please avoid relying on it. -func (m *Map[K, V]) ForEach(f func(K, V) bool) { - if m == nil { - return - } - - if m.hasZeroKey && !f(K(0), m.zeroVal) { - return - } - forEach64(m.data, f) -} - -// All returns an iterator over key-value pairs from m. -// The iterator returns immediately if invoked on a nil map. -// -// The iteration order of a Map is not defined, so please avoid relying on it. -func (m *Map[K, V]) All() iter.Seq2[K, V] { - return m.ForEach -} - -// Keys returns an iterator over keys in m. -// The iterator returns immediately if invoked on a nil map. -// -// The iteration order of a Map is not defined, so please avoid relying on it. -func (m *Map[K, V]) Keys() iter.Seq[K] { - return func(yield func(k K) bool) { - if m == nil { - return - } - - if m.hasZeroKey && !yield(K(0)) { - return - } - - for _, p := range m.data { - if p.K != K(0) && !yield(p.K) { - return - } - } - } -} - -// Values returns an iterator over values in m. -// The iterator returns immediately if invoked on a nil map. -// -// The iteration order of a Map is not defined, so please avoid relying on it. -func (m *Map[K, V]) Values() iter.Seq[V] { - return func(yield func(v V) bool) { - if m == nil { - return - } - - if m.hasZeroKey && !yield(m.zeroVal) { - return - } - - for _, p := range m.data { - if p.K != K(0) && !yield(p.V) { - return - } - } - } -} - -// Clear removes all items from the map, but keeps the internal buffers for reuse. -func (m *Map[K, V]) Clear() { - var zero V - m.hasZeroKey = false - m.zeroVal = zero - - // compiles down to runtime.memclr() - for i := range m.data { - m.data[i] = pair[K, V]{} - } - - m.size = 0 -} - -func (m *Map[K, V]) rehash() { - oldData := m.data - m.data = make([]pair[K, V], 2*len(m.data)) - - // reset size - if m.hasZeroKey { - m.size = 1 - } else { - m.size = 0 - } - - forEach64(oldData, func(k K, v V) bool { - m.Put(k, v) - return true - }) -} - -// Len returns the number of elements in the map. -// The length of a nil map is defined to be zero. -func (m *Map[K, V]) Len() int { - if m == nil { - return 0 - } - - return m.size -} - -func (m *Map[K, V]) sizeThreshold() int { - return int(math.Floor(float64(len(m.data)) * fillFactor64)) -} - -func (m *Map[K, V]) startIndex(key K) int { - return phiMix64(int(key)) & (len(m.data) - 1) -} - -func (m *Map[K, V]) nextIndex(idx int) int { - return (idx + 1) & (len(m.data) - 1) -} - -func forEach64[K IntKey, V any](pairs []pair[K, V], f func(k K, v V) bool) { - for _, p := range pairs { - if p.K != K(0) && !f(p.K, p.V) { - return - } - } -} - -// Del deletes a key and its value, returning true iff the key was found -func (m *Map[K, V]) Del(key K) bool { - if key == K(0) { - if m.hasZeroKey { - m.hasZeroKey = false - m.size-- - return true - } - return false - } - - idx := m.startIndex(key) - p := m.data[idx] - - if p.K == key { - // any keys that were pushed back needs to be shifted nack into the empty slot - // to avoid breaking the chain - m.shiftKeys(idx) - m.size-- - return true - } else if p.K == K(0) { // end of chain already - return false - } - - for { - idx = m.nextIndex(idx) - p = m.data[idx] - - if p.K == key { - // any keys that were pushed back needs to be shifted nack into the empty slot - // to avoid breaking the chain - m.shiftKeys(idx) - m.size-- - return true - } else if p.K == K(0) { - return false - } - - } -} - -func (m *Map[K, V]) shiftKeys(idx int) int { - // Shift entries with the same hash. - // We need to do this on deletion to ensure we don't have zeroes in the hash chain - for { - var p pair[K, V] - lastIdx := idx - idx = m.nextIndex(idx) - for { - p = m.data[idx] - if p.K == K(0) { - m.data[lastIdx] = pair[K, V]{} - return lastIdx - } - - slot := m.startIndex(p.K) - if lastIdx <= idx { - if lastIdx >= slot || slot > idx { - break - } - } else { - if lastIdx >= slot && slot > idx { - break - } - } - idx = m.nextIndex(idx) - } - m.data[lastIdx] = p - } -} - -func nextPowerOf2(x uint32) uint32 { - if x == math.MaxUint32 { - return x - } - - if x == 0 { - return 1 - } - - x-- - x |= x >> 1 - x |= x >> 2 - x |= x >> 4 - x |= x >> 8 - x |= x >> 16 - - return x + 1 -} - -func arraySize(exp int, fill float64) int { - s := nextPowerOf2(uint32(math.Ceil(float64(exp) / fill))) - if s < 2 { - s = 2 - } - return int(s) -} diff --git a/vendor/github.com/kamstrup/intmap/set.go b/vendor/github.com/kamstrup/intmap/set.go deleted file mode 100644 index b81ce224b6036..0000000000000 --- a/vendor/github.com/kamstrup/intmap/set.go +++ /dev/null @@ -1,59 +0,0 @@ -package intmap - -import "iter" - -// Set is a specialization of Map modelling a set of integers. -// Like Map, methods that read from the set are valid on the nil Set. -// This include Has, Len, and ForEach. -type Set[K IntKey] Map[K, struct{}] - -// NewSet creates a new Set with a given initial capacity. -func NewSet[K IntKey](capacity int) *Set[K] { - return (*Set[K])(New[K, struct{}](capacity)) -} - -// Add an element to the set. Returns true if the element was not already present. -func (s *Set[K]) Add(k K) bool { - _, found := (*Map[K, struct{}])(s).PutIfNotExists(k, struct{}{}) - return found -} - -// Del deletes a key, returning true iff the key was found -func (s *Set[K]) Del(k K) bool { - return (*Map[K, struct{}])(s).Del(k) -} - -// Clear removes all items from the Set, but keeps the internal buffers for reuse. -func (s *Set[K]) Clear() { - (*Map[K, struct{}])(s).Clear() -} - -// Has returns true if the key is in the set. -// If the set is nil this method always return false. -func (s *Set[K]) Has(k K) bool { - return (*Map[K, struct{}])(s).Has(k) -} - -// Len returns the number of elements in the set. -// If the set is nil this method return 0. -func (s *Set[K]) Len() int { - return (*Map[K, struct{}])(s).Len() -} - -// ForEach iterates over the elements in the set while the visit function returns true. -// This method returns immediately if the set is nil. -// -// The iteration order of a Set is not defined, so please avoid relying on it. -func (s *Set[K]) ForEach(visit func(k K) bool) { - (*Map[K, struct{}])(s).ForEach(func(k K, _ struct{}) bool { - return visit(k) - }) -} - -// All returns an iterator over keys from the set. -// The iterator returns immediately if the set is nil. -// -// The iteration order of a Set is not defined, so please avoid relying on it. -func (s *Set[K]) All() iter.Seq[K] { - return s.ForEach -} diff --git a/vendor/modules.txt b/vendor/modules.txt index 76cdea7f2deba..324644a5de3fb 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -462,8 +462,8 @@ github.com/aws/smithy-go/rand github.com/aws/smithy-go/time github.com/aws/smithy-go/transport/http github.com/aws/smithy-go/transport/http/internal/io -# github.com/axiomhq/hyperloglog v0.2.1 -## explicit; go 1.23 +# github.com/axiomhq/hyperloglog v0.2.0 +## explicit; go 1.21 github.com/axiomhq/hyperloglog # github.com/baidubce/bce-sdk-go v0.9.206 ## explicit; go 1.11 @@ -1169,9 +1169,6 @@ github.com/json-iterator/go # github.com/julienschmidt/httprouter v1.3.0 ## explicit; go 1.7 github.com/julienschmidt/httprouter -# github.com/kamstrup/intmap v0.5.0 -## explicit; go 1.23 -github.com/kamstrup/intmap # github.com/klauspost/compress v1.17.11 ## explicit; go 1.21 github.com/klauspost/compress