Skip to content

Commit 145ff18

Browse files
authored
feat: Support uint Keys (#463)
**Description** This adds support for the `uint` primitive as a cache key.
1 parent f225870 commit 145ff18

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ adhere to [Semantic Versioning](http://semver.org/spec/v2.0.0.html) starting v1.
1111

1212
- Remove dependency: github.com/pkg/errors (#443)
1313
- Add public Cache.RemainingCost() method
14+
- Add support for uint keys
1415

1516
**Fixed**
1617

z/z.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
)
1414

1515
type Key interface {
16-
uint64 | string | []byte | byte | int | int32 | uint32 | int64
16+
uint64 | string | []byte | byte | int | uint | int32 | uint32 | int64
1717
}
1818

1919
// TODO: Figure out a way to re-use memhash for the second uint64 hash,
@@ -34,6 +34,8 @@ func KeyToHash[K Key](key K) (uint64, uint64) {
3434
return MemHash(k), xxhash.Sum64(k)
3535
case byte:
3636
return uint64(k), 0
37+
case uint:
38+
return uint64(k), 0
3739
case int:
3840
return uint64(k), 0
3941
case int32:

z/z_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ func TestKeyToHash(t *testing.T) {
2424
key, conflict = KeyToHash(uint64(1))
2525
verifyHashProduct(t, 1, 0, key, conflict)
2626

27+
key, conflict = KeyToHash(uint(1))
28+
verifyHashProduct(t, 1, 0, key, conflict)
29+
2730
key, conflict = KeyToHash(1)
2831
verifyHashProduct(t, 1, 0, key, conflict)
2932

0 commit comments

Comments
 (0)