diff options
Diffstat (limited to 'bucket.go')
-rw-r--r-- | bucket.go | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -29,3 +29,32 @@ func (b *Bucket) cursor() *Cursor { stack: make([]pageElementRef, 0), } } + +// Stat returns stats on a bucket. +func (b *Bucket) Stat() *BucketStat { + s := &BucketStat{} + b.transaction.forEachPage(b.root, 0, func(p *page, depth int) { + if (p.flags & leafPageFlag) != 0 { + s.LeafPageCount++ + s.KeyCount += int(p.count) + } else if (p.flags & branchPageFlag) != 0 { + s.BranchPageCount++ + } + + s.OverflowPageCount += int(p.overflow) + + if depth+1 > s.MaxDepth { + s.MaxDepth = (depth + 1) + } + }) + return s +} + +// BucketStat represents stats on a bucket such as branch pages and leaf pages. +type BucketStat struct { + BranchPageCount int + LeafPageCount int + OverflowPageCount int + KeyCount int + MaxDepth int +} |