aboutsummaryrefslogtreecommitdiff
path: root/format/commitgraph/bloom/key.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-03-06 08:05:51 +0800
committerGravatar Runxi Yu2026-03-06 10:00:35 +0800
commite15054a4f93fc54806e84aa7036e60168e78e823 (patch)
treeb576dcb1d3368324e7ca73ca0fe79dd8865c5524 /format/commitgraph/bloom/key.go
parentinternal/intconv: Add Uint32ToUint8 (diff)
signatureNo signature
format/commitgraph: Add initial commit-graph support
Diffstat (limited to 'format/commitgraph/bloom/key.go')
-rw-r--r--format/commitgraph/bloom/key.go39
1 files changed, 25 insertions, 14 deletions
diff --git a/format/commitgraph/bloom/key.go b/format/commitgraph/bloom/key.go
index 6e49959d..a15df904 100644
--- a/format/commitgraph/bloom/key.go
+++ b/format/commitgraph/bloom/key.go
@@ -1,10 +1,12 @@
package bloom
+import "codeberg.org/lindenii/furgit/internal/intconv"
+
type key struct {
hashes []uint32
}
-func keyvec(path []byte, settings *Settings) ([]key, error) {
+func keyvec(path []byte, filter *Filter) ([]key, error) {
if len(path) == 0 {
return nil, nil
}
@@ -19,7 +21,7 @@ func keyvec(path []byte, settings *Settings) ([]key, error) {
keys := make([]key, 0, count)
- full, err := keyFill(path, settings)
+ full, err := keyFill(path, filter)
if err != nil {
return nil, err
}
@@ -28,7 +30,7 @@ func keyvec(path []byte, settings *Settings) ([]key, error) {
for i := len(path) - 1; i >= 0; i-- {
if path[i] == '/' {
- k, err := keyFill(path[:i], settings)
+ k, err := keyFill(path[:i], filter)
if err != nil {
return nil, err
}
@@ -40,7 +42,7 @@ func keyvec(path []byte, settings *Settings) ([]key, error) {
return keys, nil
}
-func keyFill(path []byte, settings *Settings) (key, error) {
+func keyFill(path []byte, filter *Filter) (key, error) {
const (
seed0 = 0x293ae76f
seed1 = 0x7e646e2c
@@ -52,7 +54,8 @@ func keyFill(path []byte, settings *Settings) (key, error) {
err error
)
- if settings.HashVersion == 2 { //nolint:nestif
+ switch filter.HashVersion {
+ case 2:
h0, err = murmur3SeededV2(seed0, path)
if err != nil {
return key{}, err
@@ -62,7 +65,7 @@ func keyFill(path []byte, settings *Settings) (key, error) {
if err != nil {
return key{}, err
}
- } else {
+ case 1:
h0, err = murmur3SeededV1(seed0, path)
if err != nil {
return key{}, err
@@ -72,21 +75,29 @@ func keyFill(path []byte, settings *Settings) (key, error) {
if err != nil {
return key{}, err
}
+ default:
+ return key{}, ErrInvalid
}
- hashes := make([]uint32, settings.NumHashes)
- for i := range settings.NumHashes {
- hashes[i] = h0 + i*h1
+ hashCount, err := intconv.Uint32ToInt(filter.NumHashes)
+ if err != nil {
+ return key{}, ErrInvalid
}
- return key{hashes: hashes}, nil
-}
+ hashes := make([]uint32, hashCount)
+ for i := range hashCount {
+ iU32, err := intconv.IntToUint32(i)
+ if err != nil {
+ return key{}, ErrInvalid
+ }
-func filterContainsKey(filter *Filter, key *key, settings *Settings) bool {
- if filter == nil || key == nil || settings == nil {
- return false
+ hashes[i] = h0 + iU32*h1
}
+ return key{hashes: hashes}, nil
+}
+
+func filterContainsKey(filter *Filter, key key) bool {
if len(filter.Data) == 0 {
return false
}