diff options
| author | 2026-04-02 06:23:30 +0000 | |
|---|---|---|
| committer | 2026-04-02 06:28:39 +0000 | |
| commit | a041d523de389b65b98a5373a8034041db2a8d83 (patch) | |
| tree | 7b423dc735f463be616045f2c3c2095a7737aca7 /format/commitgraph/bloom/key.go | |
| parent | research: Add dynamic pack resources (diff) | |
| signature | No signature | |
*: Remove
Diffstat (limited to 'format/commitgraph/bloom/key.go')
| -rw-r--r-- | format/commitgraph/bloom/key.go | 117 |
1 files changed, 0 insertions, 117 deletions
diff --git a/format/commitgraph/bloom/key.go b/format/commitgraph/bloom/key.go deleted file mode 100644 index a15df904..00000000 --- a/format/commitgraph/bloom/key.go +++ /dev/null @@ -1,117 +0,0 @@ -package bloom - -import "codeberg.org/lindenii/furgit/internal/intconv" - -type key struct { - hashes []uint32 -} - -func keyvec(path []byte, filter *Filter) ([]key, error) { - if len(path) == 0 { - return nil, nil - } - - count := 1 - - for _, b := range path { - if b == '/' { - count++ - } - } - - keys := make([]key, 0, count) - - full, err := keyFill(path, filter) - if err != nil { - return nil, err - } - - keys = append(keys, full) - - for i := len(path) - 1; i >= 0; i-- { - if path[i] == '/' { - k, err := keyFill(path[:i], filter) - if err != nil { - return nil, err - } - - keys = append(keys, k) - } - } - - return keys, nil -} - -func keyFill(path []byte, filter *Filter) (key, error) { - const ( - seed0 = 0x293ae76f - seed1 = 0x7e646e2c - ) - - var ( - h0 uint32 - h1 uint32 - err error - ) - - switch filter.HashVersion { - case 2: - h0, err = murmur3SeededV2(seed0, path) - if err != nil { - return key{}, err - } - - h1, err = murmur3SeededV2(seed1, path) - if err != nil { - return key{}, err - } - case 1: - h0, err = murmur3SeededV1(seed0, path) - if err != nil { - return key{}, err - } - - h1, err = murmur3SeededV1(seed1, path) - if err != nil { - return key{}, err - } - default: - return key{}, ErrInvalid - } - - hashCount, err := intconv.Uint32ToInt(filter.NumHashes) - if err != nil { - return key{}, ErrInvalid - } - - hashes := make([]uint32, hashCount) - for i := range hashCount { - iU32, err := intconv.IntToUint32(i) - if err != nil { - return key{}, ErrInvalid - } - - hashes[i] = h0 + iU32*h1 - } - - return key{hashes: hashes}, nil -} - -func filterContainsKey(filter *Filter, key key) bool { - if len(filter.Data) == 0 { - return false - } - - mod := uint64(len(filter.Data)) * 8 - for _, h := range key.hashes { - idx := uint64(h) % mod - bytePos := idx / 8 - - bit := byte(1 << (idx & 7)) - if filter.Data[bytePos]&bit == 0 { - return false - } - } - - return true -} |
