| 1 |
// compile |
| 2 |
|
| 3 |
// Copyright 2025 The Go Authors. All rights reserved. |
| 4 |
// Use of this source code is governed by a BSD-style |
| 5 |
// license that can be found in the LICENSE file. |
| 6 |
|
| 7 |
package p |
| 8 |
|
| 9 |
type Backend interface { |
| 10 |
Hash(ignores func(bucketName, keyName []byte) bool) (uint32, error) |
| 11 |
} |
| 12 |
|
| 13 |
type backend struct { |
| 14 |
} |
| 15 |
|
| 16 |
func first() (key []byte, value []byte) { |
| 17 |
return |
| 18 |
} |
| 19 |
|
| 20 |
func (b *backend) View(fn func() error) error { |
| 21 |
return nil |
| 22 |
} |
| 23 |
|
| 24 |
func (b *backend) Hash(ignores func(bucketName, keyName []byte) bool) (uint32, error) { |
| 25 |
err := b.View(func() error { |
| 26 |
for next, _ := first(); next != nil; next, _ = first() { |
| 27 |
_ = next |
| 28 |
} |
| 29 |
return nil |
| 30 |
}) |
| 31 |
return 0, err |
| 32 |
} |
| 33 |
|
| 34 |
func defragdb() error { |
| 35 |
for next, _ := first(); next != nil; next, _ = first() { |
| 36 |
_ = f(next) |
| 37 |
ForEach(func(k, v []byte) error { |
| 38 |
_ = next |
| 39 |
return nil |
| 40 |
}) |
| 41 |
} |
| 42 |
|
| 43 |
return nil |
| 44 |
} |
| 45 |
|
| 46 |
func ForEach(fn func(k, v []byte) error) error { |
| 47 |
for k, v := first(); k != nil; k, v = first() { |
| 48 |
if err := fn(k, v); err != nil { |
| 49 |
return err |
| 50 |
} |
| 51 |
} |
| 52 |
return nil |
| 53 |
} |
| 54 |
|
| 55 |
//go:noinline |
| 56 |
func f(any) string { |
| 57 |
return "" |
| 58 |
} |