aboutsummaryrefslogtreecommitdiff
path: root/cursor.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-03-08 17:01:49 -0700
committerBen Johnson <benbjohnson@yahoo.com>2014-03-08 17:04:02 -0700
commit57376f090503d7ef5bc38f138e58e64bdea284a3 (patch)
treee215bb0cf8df72a53b662ff222c24a973e7faac3 /cursor.go
parentAdd benchmarks. (diff)
downloaddedo-57376f090503d7ef5bc38f138e58e64bdea284a3.tar.gz
dedo-57376f090503d7ef5bc38f138e58e64bdea284a3.tar.xz
Rename Transaction to Tx.
I changed the Transaction/RWTransaction types to Tx/RWTx, respectively. This makes the naming more consistent with other packages such as database/sql. The txnid is changed to txid as well.
Diffstat (limited to 'cursor.go')
-rw-r--r--cursor.go20
1 files changed, 10 insertions, 10 deletions
diff --git a/cursor.go b/cursor.go
index f8e28ea..2907b84 100644
--- a/cursor.go
+++ b/cursor.go
@@ -6,18 +6,18 @@ import (
)
// Cursor represents an iterator that can traverse over all key/value pairs in a bucket in sorted order.
-// Cursors can be obtained from a Transaction and are valid as long as the Transaction is open.
+// Cursors can be obtained from a transaction and are valid as long as the transaction is open.
type Cursor struct {
- transaction *Transaction
- root pgid
- stack []elemRef
+ tx *Tx
+ root pgid
+ stack []elemRef
}
// First moves the cursor to the first item in the bucket and returns its key and value.
// If the bucket is empty then a nil key and value are returned.
func (c *Cursor) First() (key []byte, value []byte) {
c.stack = c.stack[:0]
- p, n := c.transaction.pageNode(c.root)
+ p, n := c.tx.pageNode(c.root)
c.stack = append(c.stack, elemRef{page: p, node: n, index: 0})
c.first()
return c.keyValue()
@@ -27,7 +27,7 @@ func (c *Cursor) First() (key []byte, value []byte) {
// If the bucket is empty then a nil key and value are returned.
func (c *Cursor) Last() (key []byte, value []byte) {
c.stack = c.stack[:0]
- p, n := c.transaction.pageNode(c.root)
+ p, n := c.tx.pageNode(c.root)
ref := elemRef{page: p, node: n}
ref.index = ref.count() - 1
c.stack = append(c.stack, ref)
@@ -116,7 +116,7 @@ func (c *Cursor) first() {
} else {
pgid = ref.page.branchPageElement(uint16(ref.index)).pgid
}
- p, n := c.transaction.pageNode(pgid)
+ p, n := c.tx.pageNode(pgid)
c.stack = append(c.stack, elemRef{page: p, node: n, index: 0})
}
}
@@ -137,7 +137,7 @@ func (c *Cursor) last() {
} else {
pgid = ref.page.branchPageElement(uint16(ref.index)).pgid
}
- p, n := c.transaction.pageNode(pgid)
+ p, n := c.tx.pageNode(pgid)
var nextRef = elemRef{page: p, node: n}
nextRef.index = nextRef.count() - 1
@@ -147,7 +147,7 @@ func (c *Cursor) last() {
// search recursively performs a binary search against a given page/node until it finds a given key.
func (c *Cursor) search(key []byte, pgid pgid) {
- p, n := c.transaction.pageNode(pgid)
+ p, n := c.tx.pageNode(pgid)
if p != nil {
_assert((p.flags&(branchPageFlag|leafPageFlag)) != 0, "invalid page type: "+p.typ())
}
@@ -251,7 +251,7 @@ func (c *Cursor) keyValue() ([]byte, []byte) {
}
// node returns the node that the cursor is currently positioned on.
-func (c *Cursor) node(t *RWTransaction) *node {
+func (c *Cursor) node(t *RWTx) *node {
_assert(len(c.stack) > 0, "accessing a node with a zero-length cursor stack")
// If the top of the stack is a leaf node then just return it.