diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-02-21 09:20:45 -0700 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-02-21 09:20:45 -0700 |
commit | 1028d571d8c7507435d986d8544cea1fec20c396 (patch) | |
tree | 23a98baa3e3ab8a6fbc6f5876432b97e7ffbb797 /bucket.go | |
parent | Merge pull request #47 from benbjohnson/bidirectional-cursor (diff) | |
download | dedo-1028d571d8c7507435d986d8544cea1fec20c396.tar.gz dedo-1028d571d8c7507435d986d8544cea1fec20c396.tar.xz |
Bucket stats.
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 +} |