aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dedo.go86
1 files changed, 43 insertions, 43 deletions
diff --git a/src/dedo.go b/src/dedo.go
index e474eaa..e711000 100644
--- a/src/dedo.go
+++ b/src/dedo.go
@@ -14,12 +14,12 @@
///
/// == Basics
///
-/// There are only a few types in Dedo: DB, Bucket, transactionT, and Cursor. The DB is
+/// There are only a few types in Dedo: DB, Bucket, transactionT, and cursorT. The DB is
/// a collection of buckets and is represented by a single file on disk. A
/// bucket is a collection of unique keys that are associated with values.
///
/// Transactions provide either read-only or read-write access to the database.
-/// Read-only transactions can retrieve key/value pairs and can use Cursors to
+/// Read-only transactions can retrieve key/value pairs and can use cursorTs to
/// iterate over the dataset sequentially. Read-write transactions can create
/// and delete buckets and can insert and remove keys. Only one read-write
/// transaction is allowed at a time.
@@ -63,7 +63,7 @@ import (
type SnapshotI interface{
Bucket([]byte) *bucketT
- Cursor() *Cursor
+ Cursor() *cursorT
ForEach(func([]byte, *bucketT) error) error
WriteTo(io.Writer) (int64, error)
@@ -72,7 +72,7 @@ type SnapshotI interface{
type TransactionI interface{
Bucket([]byte) *bucketT
- Cursor() *Cursor
+ Cursor() *cursorT
ForEach(func([]byte, *bucketT) error) error
WriteTo(io.Writer) (int64, error)
@@ -131,9 +131,9 @@ type bucketT struct {
nodes map[pgid]*node /// node cache
}
-/// Cursor represents an iterator that can traverse over all key/value pairs in
-/// a bucket in sorted order. Cursors see nested buckets with value == nil.
-/// Cursors can be obtained from a transaction and are valid as long as the
+/// cursorT represents an iterator that can traverse over all key/value pairs in
+/// a bucket in sorted order. cursorTs see nested buckets with value == nil.
+/// cursorTs can be obtained from a transaction and are valid as long as the
/// transaction is open.
///
/// Keys and values returned from the cursor are only valid for the life of the
@@ -142,7 +142,7 @@ type bucketT struct {
/// Changing data while traversing with a cursor may cause it to be invalidated
/// and return unexpected keys and/or values. You must reposition your cursor
/// after mutating data.
-type Cursor struct {
+type cursorT struct {
bucket *bucketT
stack []elemRef
}
@@ -585,8 +585,8 @@ func newBucket(tx *transactionT) bucketT {
/// bucketT.Cursor() creates a cursor associated with the bucket. The cursor is
/// only valid as long as the transaction is open. Do not use a cursor after
/// the transaction is closed.
-func (b *bucketT) Cursor() *Cursor {
- return &Cursor{
+func (b *bucketT) Cursor() *cursorT {
+ return &cursorT{
bucket: b,
stack: make([]elemRef, 0),
}
@@ -1179,11 +1179,11 @@ func cloneBytes(v []byte) []byte {
return clone
}
-/// Cursor.First() moves the cursor to the first item in the bucket and returns
+/// cursorT.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. The returned key and value are only valid for the life of the
/// transaction.
-func (c *Cursor) First() (key []byte, value []byte) {
+func (c *cursorT) First() (key []byte, value []byte) {
g.Assert(c.bucket.tx.db != nil, "tx closed")
c.stack = c.stack[:0]
p, n := c.bucket.pageNode(c.bucket.ref.root)
@@ -1204,11 +1204,11 @@ func (c *Cursor) First() (key []byte, value []byte) {
}
-/// Cursor.Last() moves the cursor to the last item in the bucket and returns
+/// cursorT.Last() moves the cursor to the last item in the bucket and returns
/// its key and value. If the bucket is empty then a nil key and value are
/// returned. The returned key and value are only valid for the life of the
/// transaction.
-func (c *Cursor) Last() (key []byte, value []byte) {
+func (c *cursorT) Last() (key []byte, value []byte) {
g.Assert(c.bucket.tx.db != nil, "tx closed")
c.stack = c.stack[:0]
p, n := c.bucket.pageNode(c.bucket.ref.root)
@@ -1223,11 +1223,11 @@ func (c *Cursor) Last() (key []byte, value []byte) {
return k, v
}
-/// Cursor.Next() moves the cursor to the next item in the bucket and returns
+/// cursorT.Next() moves the cursor to the next item in the bucket and returns
/// its key and value. If the cursor is at the end of the bucket then a nil key
/// and value are returned. The returned key and value are only valid for the
/// life of the transaction.
-func (c *Cursor) Next() (key []byte, value []byte) {
+func (c *cursorT) Next() (key []byte, value []byte) {
g.Assert(c.bucket.tx.db != nil, "tx closed")
k, v, flags := c.next()
if (flags & uint32(bucketLeafFlag)) != 0 {
@@ -1236,11 +1236,11 @@ func (c *Cursor) Next() (key []byte, value []byte) {
return k, v
}
-/// Cursor.Prev() moves the cursor to the previous item in the bucket and
+/// cursorT.Prev() moves the cursor to the previous item in the bucket and
/// returns its key and value. If the cursor is at the beginning of the bucket
/// then a nil key and value are returned. The returned key and value are only
/// valid for the life of the transaction.
-func (c *Cursor) Prev() (key []byte, value []byte) {
+func (c *cursorT) Prev() (key []byte, value []byte) {
g.Assert(c.bucket.tx.db != nil, "tx closed")
// Attempt to move back one element until we're successful.
@@ -1269,11 +1269,11 @@ func (c *Cursor) Prev() (key []byte, value []byte) {
return k, v
}
-/// Cursor.Seek() moves the cursor to a given key and returns it. If the key
+/// cursorT.Seek() moves the cursor to a given key and returns it. If the key
/// does not exist then the next key is used. If no keys follow, a nil key is
/// returned. The returned key and value are only valid for the life of the
/// transaction.
-func (c *Cursor) Seek(seek []byte) (key []byte, value []byte) {
+func (c *cursorT) Seek(seek []byte) (key []byte, value []byte) {
k, v, flags := c.seek(seek)
// If we ended up after the last element of a page then move to the next
@@ -1292,10 +1292,10 @@ func (c *Cursor) Seek(seek []byte) (key []byte, value []byte) {
}
}
-/// Cursor.Delete() removes the current key/value under the cursor from the
-/// bucket. Cursor.Delete() fails if current key/value is a bucket or if the
+/// cursorT.Delete() removes the current key/value under the cursor from the
+/// bucket. cursorT.Delete() fails if current key/value is a bucket or if the
/// transaction is not writable.
-func (c *Cursor) Delete() error {
+func (c *cursorT) Delete() error {
if c.bucket.tx.db == nil {
return ErrTxClosed
} else if !c.bucket.tx.writable {
@@ -1312,9 +1312,9 @@ func (c *Cursor) Delete() error {
return nil
}
-/// Cursor.seek() moves the cursor to a given key and returns it. If the key
+/// cursorT.seek() moves the cursor to a given key and returns it. If the key
/// does not exist then the next key is used.
-func (c *Cursor) seek(seek []byte) (key []byte, value []byte, flags uint32) {
+func (c *cursorT) seek(seek []byte) (key []byte, value []byte, flags uint32) {
g.Assert(c.bucket.tx.db != nil, "tx closed")
// Start from root page/node and traverse to correct page.
@@ -1331,9 +1331,9 @@ func (c *Cursor) seek(seek []byte) (key []byte, value []byte, flags uint32) {
return c.keyValue()
}
-/// Cursor.first() moves the cursor to the first leaf element under the last
+/// cursorT.first() moves the cursor to the first leaf element under the last
/// page in the stack.
-func (c *Cursor) first() {
+func (c *cursorT) first() {
for {
// Exit when we hit a leaf page.
ref := &c.stack[len(c.stack)-1]
@@ -1355,9 +1355,9 @@ func (c *Cursor) first() {
}
}
-/// Cursor.last() moves the cursor to the last leaf element under the last page
+/// cursorT.last() moves the cursor to the last leaf element under the last page
/// in the stack.
-func (c *Cursor) last() {
+func (c *cursorT) last() {
for {
// Exit when we hit a leaf page.
ref := &c.stack[len(c.stack)-1]
@@ -1382,10 +1382,10 @@ func (c *Cursor) last() {
}
}
-/// Cursor.next() moves to the next leaf element and returns the key and value.
+/// cursorT.next() moves to the next leaf element and returns the key and value.
/// If the cursor is at the last leaf element then it stays there and returns
/// nil.
-func (c *Cursor) next() (key []byte, value []byte, flags uint32) {
+func (c *cursorT) next() (key []byte, value []byte, flags uint32) {
for {
// Attempt to move over one element until we're successful.
// Move up the stack as we hit the end of each page in our
@@ -1421,9 +1421,9 @@ func (c *Cursor) next() (key []byte, value []byte, flags uint32) {
}
}
-/// Cursor.search() recursively performs a binary search against a given
+/// cursorT.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) {
+func (c *cursorT) search(key []byte, pgid pgid) {
p, n := c.bucket.pageNode(pgid)
if p != nil && (p.flags&(branchPageFlag|leafPageFlag)) == 0 {
panic(fmt.Sprintf("invalid page type: %d: %x", p.id, p.flags))
@@ -1444,7 +1444,7 @@ func (c *Cursor) search(key []byte, pgid pgid) {
c.searchPage(key, p)
}
-func (c *Cursor) searchNode(key []byte, n *node) {
+func (c *cursorT) searchNode(key []byte, n *node) {
var exact bool
index := sort.Search(len(n.inodes), func(i int) bool {
// TODO(benbjohnson): Optimize this range search. It's a bit
@@ -1465,7 +1465,7 @@ func (c *Cursor) searchNode(key []byte, n *node) {
c.search(key, n.inodes[index].pgid)
}
-func (c *Cursor) searchPage(key []byte, p *page) {
+func (c *cursorT) searchPage(key []byte, p *page) {
// Binary search for the correct range.
inodes := p.branchPageElements()
@@ -1489,8 +1489,8 @@ func (c *Cursor) searchPage(key []byte, p *page) {
c.search(key, inodes[index].pgid)
}
-/// Cursor.nsearch() searches the leaf node on the top of the stack for a key.
-func (c *Cursor) nsearch(key []byte) {
+/// cursorT.nsearch() searches the leaf node on the top of the stack for a key.
+func (c *cursorT) nsearch(key []byte) {
e := &c.stack[len(c.stack)-1]
p, n := e.page, e.node
@@ -1511,8 +1511,8 @@ func (c *Cursor) nsearch(key []byte) {
e.index = index
}
-/// Cursor.keyValue() returns the key and value of the current leaf element.
-func (c *Cursor) keyValue() ([]byte, []byte, uint32) {
+/// cursorT.keyValue() returns the key and value of the current leaf element.
+func (c *cursorT) keyValue() ([]byte, []byte, uint32) {
ref := &c.stack[len(c.stack)-1]
if ref.count() == 0 || ref.index >= ref.count() {
return nil, nil, 0
@@ -1529,8 +1529,8 @@ func (c *Cursor) keyValue() ([]byte, []byte, uint32) {
return elem.key(), elem.value(), elem.flags
}
-/// Cursor.node() returns the node that the cursor is currently positioned on.
-func (c *Cursor) node() *node {
+/// cursorT.node() returns the node that the cursor is currently positioned on.
+func (c *cursorT) node() *node {
g.Assert(
len(c.stack) > 0,
"accessing a node with a zero-length cursor stack",
@@ -1724,7 +1724,7 @@ func (tx *inMemoryTx) CreateBucketIfNotExists(name []byte) (*bucketT, error) {
return bucket, nil
}
-func (tx *inMemoryTx) Cursor() *Cursor {
+func (tx *inMemoryTx) Cursor() *cursorT {
return nil
}
@@ -3495,7 +3495,7 @@ func (tx *transactionT) Size() int64 {
/// the cursor will return a nil value because all root bucket keys point to
/// buckets. The cursor is only valid as long as the transaction is open. Do
/// not use a cursor after the transaction is closed.
-func (tx *transactionT) Cursor() *Cursor {
+func (tx *transactionT) Cursor() *cursorT {
return tx.root.Cursor()
}