aboutsummaryrefslogtreecommitdiff
path: root/src/dedo.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/dedo.go')
-rw-r--r--src/dedo.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/dedo.go b/src/dedo.go
index e69dbd4..92317da 100644
--- a/src/dedo.go
+++ b/src/dedo.go
@@ -40,6 +40,7 @@ package dedo
import (
"bytes"
+ "encoding/binary"
"errors"
"flag"
"fmt"
@@ -828,6 +829,30 @@ func (b *Bucket) Delete(key []byte) error {
return nil
}
+func bytesLE(num uint64) []byte {
+ arr := make([]byte, 8)
+ binary.LittleEndian.PutUint64(arr, uint64(num))
+ return arr
+}
+
+func (b *Bucket) NextID() []byte {
+ if b.tx.db == nil {
+ panic(ErrTxClosed)
+ } else if !b.tx.writable {
+ panic(ErrTxNotWritable)
+ }
+
+ // Materialize the root node if it hasn't been already so that the
+ // bucket will be saved during commit.
+ if b.rootNode == nil {
+ _ = b.node(b.ref.root, nil)
+ }
+
+ // Increment and return the sequence.
+ b.ref.sequence++
+ return bytesLE(b.ref.sequence)
+}
+
/// Bucket.NextSequence() returns an autoincrementing integer for the bucket.
func (b *Bucket) NextSequence() (uint64, error) {
if b.tx.db == nil {