2 Commits

Author SHA1 Message Date
f35583e079 fix!: removed all 'mixed pointer'-edness
All checks were successful
CI / Check PR Title (pull_request) Successful in 31s
CI / Makefile Lint (pull_request) Successful in 45s
CI / Markdown Lint (pull_request) Successful in 34s
CI / Unit Tests (pull_request) Successful in 41s
CI / Go Lint (pull_request) Successful in 56s
CI / Fuzz Tests (pull_request) Successful in 1m39s
CI / Mutation Tests (pull_request) Successful in 1m5s
2026-04-15 22:59:31 -04:00
ce41d4fba2 feat: add recvcheck linter 2026-04-15 22:58:14 -04:00
3 changed files with 16 additions and 13 deletions

View File

@@ -114,6 +114,9 @@ linters:
# Reports uses of functions with replacement inside the testing package. # Reports uses of functions with replacement inside the testing package.
- usetesting - usetesting
# Reports mixed receiver types in structs/interfaces.
- recvcheck
settings: settings:
revive: revive:
rules: rules:

View File

@@ -19,11 +19,11 @@ type bucket[K, V any] struct {
// location determines where in the bucket a certain key would be placed. If the // location determines where in the bucket a certain key would be placed. If the
// capacity is 0, this will panic. // capacity is 0, this will panic.
func (b bucket[K, V]) location(key K) uint64 { func (b *bucket[K, V]) location(key K) uint64 {
return b.hash(key) % b.capacity return b.hash(key) % b.capacity
} }
func (b bucket[K, V]) get(key K) (value V, found bool) { func (b *bucket[K, V]) get(key K) (value V, found bool) {
if b.capacity == 0 { if b.capacity == 0 {
return return
} }
@@ -54,7 +54,7 @@ func (b *bucket[K, V]) resize(capacity uint64) {
b.size = 0 b.size = 0
} }
func (b bucket[K, V]) update(key K, value V) (updated bool) { func (b *bucket[K, V]) update(key K, value V) (updated bool) {
if b.capacity == 0 { if b.capacity == 0 {
return return
} }

View File

@@ -27,12 +27,12 @@ type Table[K, V any] struct {
// TotalCapacity returns the number of slots allocated for the [Table]. To get the // TotalCapacity returns the number of slots allocated for the [Table]. To get the
// number of slots filled, look at [Table.Size]. // number of slots filled, look at [Table.Size].
func (t Table[K, V]) TotalCapacity() uint64 { func (t *Table[K, V]) TotalCapacity() uint64 {
return t.bucketA.capacity + t.bucketB.capacity return t.bucketA.capacity + t.bucketB.capacity
} }
// Size returns how many slots are filled in the [Table]. // Size returns how many slots are filled in the [Table].
func (t Table[K, V]) Size() int { func (t *Table[K, V]) Size() int {
return int(t.bucketA.size + t.bucketB.size) return int(t.bucketA.size + t.bucketB.size)
} }
@@ -40,11 +40,11 @@ func log2(n uint64) (m int) {
return max(0, bits.Len64(n)-1) return max(0, bits.Len64(n)-1)
} }
func (t Table[K, V]) maxEvictions() int { func (t *Table[K, V]) maxEvictions() int {
return 3 * log2(t.TotalCapacity()) return 3 * log2(t.TotalCapacity())
} }
func (t Table[K, V]) load() float64 { func (t *Table[K, V]) load() float64 {
// When there are no slots in the table, we still treat the load as 100%. // When there are no slots in the table, we still treat the load as 100%.
// Every slot in the table is full. // Every slot in the table is full.
if t.TotalCapacity() == 0 { if t.TotalCapacity() == 0 {
@@ -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 // 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. // 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.bucketA.get(key); ok { if item, ok := t.bucketA.get(key); ok {
return item, true 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; // Find fetches the value of a key. Matches direct indexing of a builtin map;
// see [Table.Get] for a comma-ok pattern. // 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) value, _ = t.Get(key)
return return
} }
// Has returns true if a key has a value in the table. // 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) _, exists = t.Get(key)
return return
} }
@@ -168,7 +168,7 @@ func (t *Table[K, V]) Drop(key K) (err error) {
} }
// Entries returns an unordered sequence of all key-value pairs in the table. // Entries returns an unordered sequence of all key-value pairs in the table.
func (t Table[K, V]) Entries() iter.Seq2[K, V] { func (t *Table[K, V]) Entries() iter.Seq2[K, V] {
return func(yield func(K, V) bool) { return func(yield func(K, V) bool) {
for _, slot := range t.bucketA.slots { for _, slot := range t.bucketA.slots {
if slot.occupied { if slot.occupied {
@@ -190,7 +190,7 @@ func (t Table[K, V]) Entries() iter.Seq2[K, V] {
// String returns the entries of the table as a string in the format: // String returns the entries of the table as a string in the format:
// "table[k1:v1 h2:v2 ...]". // "table[k1:v1 h2:v2 ...]".
func (t Table[K, V]) String() string { func (t *Table[K, V]) String() string {
var sb strings.Builder var sb strings.Builder
sb.WriteString("table[") sb.WriteString("table[")