From 8b55ce7264e1b81d61e69d3b5d1002a2118ed908 Mon Sep 17 00:00:00 2001 From: "M.V. Hutz" Date: Fri, 3 Apr 2026 16:24:25 +0200 Subject: [PATCH 1/2] feat: remove minimum-load option, hard-coded to 5% --- cuckoo_fuzz_test.go | 14 ++------------ settings.go | 18 +++--------------- table.go | 2 +- 3 files changed, 6 insertions(+), 28 deletions(-) diff --git a/cuckoo_fuzz_test.go b/cuckoo_fuzz_test.go index 80deea7..f849de0 100644 --- a/cuckoo_fuzz_test.go +++ b/cuckoo_fuzz_test.go @@ -3,7 +3,6 @@ package cuckoo_test import ( "fmt" "maps" - "math" "os" "testing" @@ -30,7 +29,6 @@ type fuzzStep struct { type fuzzScenario struct { seedA, seedB uint32 capacity, growthFactor uint8 - load float64 steps []fuzzStep } @@ -48,7 +46,6 @@ func FuzzInsertLookup(f *testing.F) { seedA, seedB := scenario.seedA, scenario.seedB growthFactor := max(2, int(scenario.growthFactor)) capacity := int(scenario.capacity) - minimumLoad := math.Abs(math.Mod(scenario.load, 1.0)) // If they are the same number, the hashes will clash, always causing an // error. @@ -56,14 +53,8 @@ func FuzzInsertLookup(f *testing.F) { t.Skip() } - // If the load is too high, the hashs will not be able to allocate - // properly. - if minimumLoad > 0.20 { - t.Skip() - } - - fmt.Fprintf(os.Stderr, "seedA=%d seedB=%d capacity=%d growthFactor=%d minimumLoad=%f\n", - seedA, seedB, capacity, growthFactor, minimumLoad) + fmt.Fprintf(os.Stderr, "seedA=%d seedB=%d capacity=%d growthFactor=%d\n", + seedA, seedB, capacity, growthFactor) actual := cuckoo.NewCustomTable[uint32, uint32]( offsetHash(seedA), @@ -71,7 +62,6 @@ func FuzzInsertLookup(f *testing.F) { func(a, b uint32) bool { return a == b }, cuckoo.Capacity(capacity), cuckoo.GrowthFactor(growthFactor), - cuckoo.MinimumLoad(minimumLoad), ) expected := map[uint32]uint32{} diff --git a/settings.go b/settings.go index 3301b4f..7c84ee4 100644 --- a/settings.go +++ b/settings.go @@ -12,11 +12,12 @@ const DefaultCapacity uint64 = 16 // hash table implementations use 2. const DefaultGrowthFactor uint64 = 2 -// DefaultMinimumLoad is the default lowest acceptable occupancy of a [Table]. +// MinimumLoad is the default lowest acceptable occupancy of a [Table]. The +// higher the minimum load, the more likely that a [Table.Put] will not succeed. // The value of 5% is taken from [libcuckoo]. // // [libcuckoo]: https://github.com/efficient/libcuckoo/blob/656714705a055df2b7a605eb3c71586d9da1e119/libcuckoo/cuckoohash_config.hh#L21 -const DefaultMinimumLoad float64 = 0.05 +const MinimumLoad float64 = 0.05 type settings struct { growthFactor uint64 @@ -38,19 +39,6 @@ func Capacity(value int) Option { return func(s *settings) { s.bucketSize = uint64(value) } } -// MinimumLoad modifies the [DefaultMinimumLoad] of the [Table]. The value must -// be between 0.00 and 1.00. -// -// The higher the minimum load, the more likely that a [Table.Put] will not -// succeed. Minimum loads above 20% are not tested. -func MinimumLoad(value float64) Option { - if value < 0.00 || value > 1.00 { - panic(fmt.Sprintf("go-cuckoo: MinimumLoad must be between 0.00 and 1.00, got %f", value)) - } - - return func(s *settings) { s.minLoadFactor = value } -} - // GrowthFactor controls how much the capacity of the [Table] multiplies when // it must resize. The value must be greater than 1. func GrowthFactor(value int) Option { diff --git a/table.go b/table.go index 3e2a1a6..e644daf 100644 --- a/table.go +++ b/table.go @@ -198,7 +198,7 @@ func NewCustomTable[K, V any](hashA, hashB Hash[K], compare EqualFunc[K], option settings := &settings{ growthFactor: DefaultGrowthFactor, bucketSize: DefaultCapacity, - minLoadFactor: DefaultMinimumLoad, + minLoadFactor: MinimumLoad, } for _, option := range options { -- 2.49.1 From 0bdf71fd12245e06b3bb34b2562e9558c786f310 Mon Sep 17 00:00:00 2001 From: "M.V. Hutz" Date: Fri, 3 Apr 2026 16:26:51 +0200 Subject: [PATCH 2/2] refactor: 'MinimumLoad' to 'defaultMinimumLoad' - The option does not need to be exported, since it is no longer an option. --- settings.go | 8 ++++---- table.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/settings.go b/settings.go index 7c84ee4..fe0408f 100644 --- a/settings.go +++ b/settings.go @@ -12,12 +12,12 @@ const DefaultCapacity uint64 = 16 // hash table implementations use 2. const DefaultGrowthFactor uint64 = 2 -// MinimumLoad is the default lowest acceptable occupancy of a [Table]. The -// higher the minimum load, the more likely that a [Table.Put] will not succeed. -// The value of 5% is taken from [libcuckoo]. +// defaultMinimumLoad is the default lowest acceptable occupancy of a [Table]. +// The higher the minimum load, the more likely that a [Table.Put] will not +// succeed. The value of 5% is taken from [libcuckoo]. // // [libcuckoo]: https://github.com/efficient/libcuckoo/blob/656714705a055df2b7a605eb3c71586d9da1e119/libcuckoo/cuckoohash_config.hh#L21 -const MinimumLoad float64 = 0.05 +const defaultMinimumLoad float64 = 0.05 type settings struct { growthFactor uint64 diff --git a/table.go b/table.go index e644daf..922aa81 100644 --- a/table.go +++ b/table.go @@ -198,7 +198,7 @@ func NewCustomTable[K, V any](hashA, hashB Hash[K], compare EqualFunc[K], option settings := &settings{ growthFactor: DefaultGrowthFactor, bucketSize: DefaultCapacity, - minLoadFactor: MinimumLoad, + minLoadFactor: defaultMinimumLoad, } for _, option := range options { -- 2.49.1