aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2025-02-10 14:11:37 -0300
committerEuAndreh <eu@euandre.org>2025-02-10 14:11:37 -0300
commit838c78d17ee52c99310ea4c6360518f872a7dd6a (patch)
tree93e8ac245da8391209e2d0b22762eb566b691067 /src
parentsrc/dedo.go: Move implementation of Bucket public methods into private functions (diff)
downloaddedo-838c78d17ee52c99310ea4c6360518f872a7dd6a.tar.gz
dedo-838c78d17ee52c99310ea4c6360518f872a7dd6a.tar.xz
src/dedo.go: Move implementation of Cursor public methods into private functions
Diffstat (limited to '')
-rw-r--r--src/dedo.go35
1 files changed, 29 insertions, 6 deletions
diff --git a/src/dedo.go b/src/dedo.go
index e443a44..f009279 100644
--- a/src/dedo.go
+++ b/src/dedo.go
@@ -1205,7 +1205,7 @@ func cloneBytes(v []byte) []byte {
/// 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 *cursorT) First() (key []byte, value []byte) {
+func cursorFirst(c *cursorT) ([]byte, []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,14 +1223,17 @@ func (c *cursorT) First() (key []byte, value []byte) {
return k, nil
}
return k, v
+}
+func (c *cursorT) First() ([]byte, []byte) {
+ return cursorFirst(c)
}
/// 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 *cursorT) Last() (key []byte, value []byte) {
+func cursorLast(c *cursorT) ([]byte, []byte) {
g.Assert(c.bucket.tx.db != nil, "tx closed")
c.stack = c.stack[:0]
p, n := c.bucket.pageNode(c.bucket.ref.root)
@@ -1245,11 +1248,15 @@ func (c *cursorT) Last() (key []byte, value []byte) {
return k, v
}
+func (c *cursorT) Last() ([]byte, []byte) {
+ return cursorLast(c)
+}
+
/// 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 *cursorT) Next() (key []byte, value []byte) {
+func cursorNext(c *cursorT) ([]byte, []byte) {
g.Assert(c.bucket.tx.db != nil, "tx closed")
k, v, flags := c.next()
if (flags & uint32(bucketLeafFlag)) != 0 {
@@ -1258,11 +1265,15 @@ func (c *cursorT) Next() (key []byte, value []byte) {
return k, v
}
+func (c *cursorT) Next() ([]byte, []byte) {
+ return cursorNext(c)
+}
+
/// 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 *cursorT) Prev() (key []byte, value []byte) {
+func cursorPrev(c *cursorT) ([]byte, []byte) {
g.Assert(c.bucket.tx.db != nil, "tx closed")
// Attempt to move back one element until we're successful.
@@ -1291,11 +1302,15 @@ func (c *cursorT) Prev() (key []byte, value []byte) {
return k, v
}
+func (c *cursorT) Prev() ([]byte, []byte) {
+ return cursorPrev(c)
+}
+
/// 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 *cursorT) Seek(seek []byte) (key []byte, value []byte) {
+func cursorSeek(c *cursorT, seek []byte) ([]byte, []byte) {
k, v, flags := c.seek(seek)
// If we ended up after the last element of a page then move to the next
@@ -1314,10 +1329,14 @@ func (c *cursorT) Seek(seek []byte) (key []byte, value []byte) {
}
}
+func (c *cursorT) Seek(seek []byte) ([]byte, []byte) {
+ return cursorSeek(c, seek)
+}
+
/// 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 *cursorT) Delete() error {
+func cursorDelete(c *cursorT) error {
if c.bucket.tx.db == nil {
return ErrTxClosed
} else if !c.bucket.tx.writable {
@@ -1334,6 +1353,10 @@ func (c *cursorT) Delete() error {
return nil
}
+func (c *cursorT) Delete() error {
+ return cursorDelete(c)
+}
+
/// 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 *cursorT) seek(seek []byte) (key []byte, value []byte, flags uint32) {