From 29ba6bfd4d777aa56ff9b81a03945489e53512c7 Mon Sep 17 00:00:00 2001 From: "M.V. Hutz" Date: Thu, 16 Apr 2026 03:27:48 +0000 Subject: [PATCH] fix!: no mixed receiver types (#23) ## Description Currently, `bucket` and `Table` have mixed receiver types: some are pointer receviers, and others are value receivers. As per the Go Wiki, [you can have value and pointer receivers, just don't mix them](https://go.dev/doc/faq#methods_on_values_or_pointers). ## Changes - Replace all value receivers in `bucket` and `Table` with pointer receivers. ### Design Decisions This decision was made due to the advice on the Go wiki. ## Checklist - [x] Tests pass - [x] Docs updated Reviewed-on: https://git.maximhutz.com/tools/go-cuckoo/pulls/23 Co-authored-by: M.V. Hutz Co-committed-by: M.V. Hutz --- .golangci.yml | 5 ++++- subtable.go | 6 +++--- table.go | 6 +++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 1ec3d80..795e81b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -114,6 +114,9 @@ linters: # Reports uses of functions with replacement inside the testing package. - usetesting + # Reports mixed receiver types in structs/interfaces. + - recvcheck + settings: revive: rules: @@ -198,7 +201,7 @@ linters: # warns when initialism, variable or package naming conventions are not followed. - name: var-naming - + misspell: # Correct spellings using locale preferences for US or UK. # Setting locale to US will correct the British spelling of 'colour' to 'color'. diff --git a/subtable.go b/subtable.go index 749d16d..343fe43 100644 --- a/subtable.go +++ b/subtable.go @@ -19,11 +19,11 @@ type subtable[K, V any] struct { // location determines where in the subtable a certain key would be placed. If // the capacity is 0, this will panic. -func (t subtable[K, V]) location(key K) uint64 { +func (t *subtable[K, V]) location(key K) uint64 { return t.hash(key) % t.capacity } -func (t subtable[K, V]) get(key K) (value V, found bool) { +func (t *subtable[K, V]) get(key K) (value V, found bool) { if t.capacity == 0 { return } @@ -54,7 +54,7 @@ func (t *subtable[K, V]) resize(capacity uint64) { t.size = 0 } -func (t subtable[K, V]) update(key K, value V) (updated bool) { +func (t *subtable[K, V]) update(key K, value V) (updated bool) { if t.capacity == 0 { return } diff --git a/table.go b/table.go index b5619fb..c9dcf9f 100644 --- a/table.go +++ b/table.go @@ -97,7 +97,7 @@ func (t *Table[K, V]) shrink() error { // Get fetches the value for a key in the [Table]. Matches the comma-ok pattern // of a builtin map; see [Table.Find] for plain indexing. -func (t Table[K, V]) Get(key K) (value V, ok bool) { +func (t *Table[K, V]) Get(key K) (value V, ok bool) { if item, ok := t.tableA.get(key); ok { return item, true } @@ -111,13 +111,13 @@ func (t Table[K, V]) Get(key K) (value V, ok bool) { // Find fetches the value of a key. Matches direct indexing of a builtin map; // see [Table.Get] for a comma-ok pattern. -func (t Table[K, V]) Find(key K) (value V) { +func (t *Table[K, V]) Find(key K) (value V) { value, _ = t.Get(key) return } // Has returns true if a key has a value in the table. -func (t Table[K, V]) Has(key K) (exists bool) { +func (t *Table[K, V]) Has(key K) (exists bool) { _, exists = t.Get(key) return }