aboutsummaryrefslogtreecommitdiff
path: root/transaction.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-02-21 09:23:19 -0700
committerBen Johnson <benbjohnson@yahoo.com>2014-02-21 09:23:19 -0700
commit62912a4c2ebe4a79062816b589914f8fa4b0d4f4 (patch)
tree23a98baa3e3ab8a6fbc6f5876432b97e7ffbb797 /transaction.go
parentMerge pull request #47 from benbjohnson/bidirectional-cursor (diff)
parentBucket stats. (diff)
downloaddedo-62912a4c2ebe4a79062816b589914f8fa4b0d4f4.tar.gz
dedo-62912a4c2ebe4a79062816b589914f8fa4b0d4f4.tar.xz
Merge pull request #48 from benbjohnson/bucket-stat
Bucket stats
Diffstat (limited to 'transaction.go')
-rw-r--r--transaction.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/transaction.go b/transaction.go
index 3951cd8..6e9ca8f 100644
--- a/transaction.go
+++ b/transaction.go
@@ -134,3 +134,19 @@ func (t *Transaction) page(id pgid) *page {
// Otherwise return directly from the mmap.
return t.db.page(id)
}
+
+// forEachPage iterates over every page within a given page and executes a function.
+func (t *Transaction) forEachPage(pgid pgid, depth int, fn func(*page, int)) {
+ p := t.page(pgid)
+
+ // Execute function.
+ fn(p, depth)
+
+ // Recursively loop over children.
+ if (p.flags & branchPageFlag) != 0 {
+ for i := 0; i < int(p.count); i++ {
+ elem := p.branchPageElement(uint16(i))
+ t.forEachPage(elem.pgid, depth+1, fn)
+ }
+ }
+}