3 Commits

Author SHA1 Message Date
b499fa9c05 fix: reduce minimum load in tests to <20% 2026-03-24 20:26:20 -04:00
9e936ebadb fix: prevent users from settings a growthfactor=1
- This always causes errors, it should not be possible.
2026-03-21 13:13:51 -04:00
d07f76207b feat: add options to fuzz testing
- Added the options to `fuzzScenario`.
- They are clamped to non-panic values, so it only tests viable combinations.
2026-03-21 13:07:11 -04:00
7 changed files with 57 additions and 125 deletions

View File

@@ -1,71 +0,0 @@
name: Bug Report
about: File a bug report
title: "[Bug]: "
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this bug report!
# some markdown that will only be visible once the issue has been created
- type: markdown
attributes:
value: |
This issue was created by an issue **template** :)
visible: [content]
- type: input
id: contact
attributes:
label: Contact Details
description: How can we get in touch with you if we need more info?
placeholder: ex. email@example.com
validations:
required: false
- type: textarea
id: what-happened
attributes:
label: What happened?
description: Also tell us, what did you expect to happen?
placeholder: Tell us what you see!
value: "A bug happened!"
validations:
required: true
- type: dropdown
id: version
attributes:
label: Version
description: What version of our software are you running?
options:
- 1.0.2 (Default)
- 1.0.3 (Edge)
validations:
required: true
- type: dropdown
id: browsers
attributes:
label: What browsers are you seeing the problem on?
multiple: true
options:
- Firefox
- Chrome
- Safari
- Microsoft Edge
- type: textarea
id: logs
attributes:
label: Relevant log output
description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
render: shell
- type: checkboxes
id: terms
attributes:
label: Code of Conduct
hide_label: true
description: By submitting this issue, you agree to follow our [Code of Conduct](https://example.com)
options:
- label: I agree to follow this project's Code of Conduct
required: true
- label: I have also read the CONTRIBUTION.MD
required: true
visible: [form]
- label: This is a TODO only visible after issue creation
visible: [content]

View File

@@ -1,12 +0,0 @@
---
name: "Pull Request Template"
about: "This template is for general pull requests!"
title: "<type>[optional scope]: <description>"
ref: "main"
assignees: ["user1"]
labels:
- bug
- "help needed"
---
This is the template!

View File

@@ -1,22 +0,0 @@
name: Release
on:
push:
branches: [main]
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install python-semantic-release
- run: semantic-release version --push --vcs-release
env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}

View File

@@ -1,7 +1,10 @@
package cuckoo_test package cuckoo_test
import ( import (
"fmt"
"maps" "maps"
"math"
"os"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@@ -26,6 +29,8 @@ type fuzzStep struct {
type fuzzScenario struct { type fuzzScenario struct {
seedA, seedB uint32 seedA, seedB uint32
capacity, growthFactor uint8
load float64
steps []fuzzStep steps []fuzzStep
} }
@@ -40,14 +45,33 @@ func FuzzInsertLookup(f *testing.F) {
return return
} }
if scenario.seedA == scenario.seedB { seedA, seedB := scenario.seedA, scenario.seedB
return 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.
if seedA == seedB {
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)
actual := cuckoo.NewCustomTable[uint32, uint32]( actual := cuckoo.NewCustomTable[uint32, uint32](
offsetHash(scenario.seedA), offsetHash(seedA),
offsetHash(scenario.seedB), offsetHash(seedB),
func(a, b uint32) bool { return a == b }, func(a, b uint32) bool { return a == b },
cuckoo.Capacity(capacity),
cuckoo.GrowthFactor(growthFactor),
cuckoo.MinimumLoad(minimumLoad),
) )
expected := map[uint32]uint32{} expected := map[uint32]uint32{}

View File

@@ -118,6 +118,18 @@ func TestGetMany(t *testing.T) {
} }
} }
func TestRemove(t *testing.T) {
assert := assert.New(t)
table := cuckoo.NewTable[int, bool]()
assert.False(table.Has(0))
err := table.Put(0, true)
assert.NoError(err)
assert.True(table.Has(0))
}
func TestDropExistingItem(t *testing.T) { func TestDropExistingItem(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
key, value := 0, true key, value := 0, true

View File

@@ -1,13 +0,0 @@
#:schema https://json.schemastore.org/pyproject.json
[tool.semantic_release]
commit_parser = "angular"
version_toml = []
tag_format = "v{version}"
[tool.semantic_release.remote]
type = "gitea"
domain = "git.maximhutz.com"
[tool.semantic_release.remote.token]
env = "GITEA_TOKEN"

View File

@@ -1,5 +1,7 @@
package cuckoo package cuckoo
import "fmt"
// DefaultCapacity is the initial capacity of a [Table]. It is inspired from // DefaultCapacity is the initial capacity of a [Table]. It is inspired from
// Java's [HashMap] implementation, which also uses 16. // Java's [HashMap] implementation, which also uses 16.
// //
@@ -27,19 +29,31 @@ type settings struct {
type Option func(*settings) type Option func(*settings)
// Capacity modifies the starting capacity of each bucket of the [Table]. The // Capacity modifies the starting capacity of each bucket of the [Table]. The
// value must be greater than 0. // value must be non-negative.
func Capacity(value int) Option { func Capacity(value int) Option {
if value < 0 {
panic(fmt.Sprintf("go-cuckoo: Capacity must be non-negative, got %d", value))
}
return func(s *settings) { s.bucketSize = uint64(value) } return func(s *settings) { s.bucketSize = uint64(value) }
} }
// MinimumLoad modifies the [DefaultMinimumLoad] of the [Table]. The value must // MinimumLoad modifies the [DefaultMinimumLoad] of the [Table]. The value must
// be between 0.00 and 1.00. // be between 0.00 and 1.00.
func MinimumLoad(value float64) Option { 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 } return func(s *settings) { s.minLoadFactor = value }
} }
// GrowthFactor controls how much the capacity of the [Table] multiplies when // GrowthFactor controls how much the capacity of the [Table] multiplies when
// it must resize. The value must be greater than 1. // it must resize. The value must be greater than 1.
func GrowthFactor(value int) Option { func GrowthFactor(value int) Option {
if value < 2 {
panic(fmt.Sprintf("go-cuckoo: GrowthFactor must be greater than 1, got %d", value))
}
return func(s *settings) { s.growthFactor = uint64(value) } return func(s *settings) { s.growthFactor = uint64(value) }
} }