mirror of
https://github.com/crazy-max/diun.git
synced 2025-12-24 14:31:47 +01:00
Bumps [go.etcd.io/bbolt](https://github.com/etcd-io/bbolt) from 1.3.11 to 1.4.0. - [Release notes](https://github.com/etcd-io/bbolt/releases) - [Commits](https://github.com/etcd-io/bbolt/compare/v1.3.11...v1.4.0) --- updated-dependencies: - dependency-name: go.etcd.io/bbolt dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
package common
|
|
|
|
import (
|
|
"fmt"
|
|
"unsafe"
|
|
)
|
|
|
|
const BucketHeaderSize = int(unsafe.Sizeof(InBucket{}))
|
|
|
|
// InBucket represents the on-file representation of a bucket.
|
|
// This is stored as the "value" of a bucket key. If the bucket is small enough,
|
|
// then its root page can be stored inline in the "value", after the bucket
|
|
// header. In the case of inline buckets, the "root" will be 0.
|
|
type InBucket struct {
|
|
root Pgid // page id of the bucket's root-level page
|
|
sequence uint64 // monotonically incrementing, used by NextSequence()
|
|
}
|
|
|
|
func NewInBucket(root Pgid, seq uint64) InBucket {
|
|
return InBucket{
|
|
root: root,
|
|
sequence: seq,
|
|
}
|
|
}
|
|
|
|
func (b *InBucket) RootPage() Pgid {
|
|
return b.root
|
|
}
|
|
|
|
func (b *InBucket) SetRootPage(id Pgid) {
|
|
b.root = id
|
|
}
|
|
|
|
// InSequence returns the sequence. The reason why not naming it `Sequence`
|
|
// is to avoid duplicated name as `(*Bucket) Sequence()`
|
|
func (b *InBucket) InSequence() uint64 {
|
|
return b.sequence
|
|
}
|
|
|
|
func (b *InBucket) SetInSequence(v uint64) {
|
|
b.sequence = v
|
|
}
|
|
|
|
func (b *InBucket) IncSequence() {
|
|
b.sequence++
|
|
}
|
|
|
|
func (b *InBucket) InlinePage(v []byte) *Page {
|
|
return (*Page)(unsafe.Pointer(&v[BucketHeaderSize]))
|
|
}
|
|
|
|
func (b *InBucket) String() string {
|
|
return fmt.Sprintf("<pgid=%d,seq=%d>", b.root, b.sequence)
|
|
}
|