From 1028d571d8c7507435d986d8544cea1fec20c396 Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Fri, 21 Feb 2014 09:20:45 -0700 Subject: Bucket stats. --- bucket.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'bucket.go') diff --git a/bucket.go b/bucket.go index a973f0e..6653389 100644 --- a/bucket.go +++ b/bucket.go @@ -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 +} -- cgit v1.2.3