diff --git a/branch.go b/branch.go index 7cba9d4..d752ac6 100644 --- a/branch.go +++ b/branch.go @@ -8,7 +8,7 @@ import ( // branch represents a temporary in-memory branch page. type branch struct { parent *branch - items branchItems + items branchItems } // size returns the size of the branch after serialization. @@ -80,7 +80,7 @@ func (b *branch) write(p *page) { func (b *branch) split(pageSize int) []*branch { // Ignore the split if the page doesn't have at least enough nodes for // multiple pages or if the data can fit on a single page. - if len(b.items) <= (minKeysPerPage * 2) || b.size() < pageSize { + if len(b.items) <= (minKeysPerPage*2) || b.size() < pageSize { return []*branch{b} } @@ -95,7 +95,7 @@ func (b *branch) split(pageSize int) []*branch { for index, item := range b.items { nodeSize := bnodeSize + len(item.key) - if (len(current.items) >= minKeysPerPage && index < len(b.items)-minKeysPerPage && size+nodeSize > threshold) { + if len(current.items) >= minKeysPerPage && index < len(b.items)-minKeysPerPage && size+nodeSize > threshold { size = pageHeaderSize branches = append(branches, current) current = &branch{} @@ -113,10 +113,9 @@ type branchItems []branchItem type branchItem struct { pgid pgid - key []byte + key []byte } func (s branchItems) Len() int { return len(s) } func (s branchItems) Swap(i, j int) { s[i], s[j] = s[j], s[i] } func (s branchItems) Less(i, j int) bool { return bytes.Compare(s[i].key, s[j].key) == -1 } - diff --git a/bucket.go b/bucket.go index 3f80117..6cfe1ca 100644 --- a/bucket.go +++ b/bucket.go @@ -7,7 +7,7 @@ type Bucket struct { } type bucket struct { - root pgid + root pgid } // Name returns the name of the bucket. @@ -24,7 +24,7 @@ func (b *Bucket) Get(key []byte) []byte { func (b *Bucket) Cursor() *Cursor { return &Cursor{ transaction: b.transaction, - root: b.root, - stack: make([]elem, 0), + root: b.root, + stack: make([]elem, 0), } } diff --git a/cursor.go b/cursor.go index 9c2fc25..7b8c9bb 100644 --- a/cursor.go +++ b/cursor.go @@ -7,8 +7,8 @@ import ( type Cursor struct { transaction *Transaction - root pgid - stack []elem + root pgid + stack []elem } // elem represents a node on a page that's on the cursor's stack. @@ -72,7 +72,7 @@ func (c *Cursor) nsearch(key []byte, p *page) { // Binary search for the correct leaf node index. nodes := p.lnodes() - e.index = sort.Search(int(p.count), func(i int) bool { + e.index = sort.Search(int(p.count), func(i int) bool { return bytes.Compare(nodes[i].key(), key) != -1 }) } diff --git a/db.go b/db.go index 578a134..3bee89a 100644 --- a/db.go +++ b/db.go @@ -228,7 +228,7 @@ func (db *DB) RWTransaction() (*RWTransaction, error) { // Create a transaction associated with the database. t := &RWTransaction{ branches: make(map[pgid]*branch), - leafs: make(map[pgid]*leaf), + leafs: make(map[pgid]*leaf), } t.init(db, db.meta()) diff --git a/leaf.go b/leaf.go index be5d447..84cb08d 100644 --- a/leaf.go +++ b/leaf.go @@ -9,7 +9,7 @@ import ( // leaf represents an in-memory, deserialized leaf page. type leaf struct { parent *branch - items leafItems + items leafItems } // size returns the size of the leaf after serialization. @@ -78,7 +78,7 @@ func (l *leaf) write(p *page) { func (l *leaf) split(pageSize int) []*leaf { // Ignore the split if the page doesn't have at least enough nodes for // multiple pages or if the data can fit on a single page. - if len(l.items) <= (minKeysPerPage * 2) || l.size() < pageSize { + if len(l.items) <= (minKeysPerPage*2) || l.size() < pageSize { return []*leaf{l} } @@ -93,7 +93,7 @@ func (l *leaf) split(pageSize int) []*leaf { for index, item := range l.items { nodeSize := lnodeSize + len(item.key) + len(item.value) - if (len(current.items) >= minKeysPerPage && index < len(l.items)-minKeysPerPage && size+nodeSize > threshold) { + if len(current.items) >= minKeysPerPage && index < len(l.items)-minKeysPerPage && size+nodeSize > threshold { size = pageHeaderSize leafs = append(leafs, current) current = &leaf{} @@ -117,4 +117,3 @@ type leafItem struct { func (s leafItems) Len() int { return len(s) } func (s leafItems) Swap(i, j int) { s[i], s[j] = s[j], s[i] } func (s leafItems) Less(i, j int) bool { return bytes.Compare(s[i].key, s[j].key) == -1 } - diff --git a/rwtransaction.go b/rwtransaction.go index c57ebdb..2c76dbd 100644 --- a/rwtransaction.go +++ b/rwtransaction.go @@ -9,7 +9,7 @@ import ( type RWTransaction struct { Transaction branches map[pgid]*branch - leafs map[pgid]*leaf + leafs map[pgid]*leaf } // CreateBucket creates a new bucket. diff --git a/rwtransaction_test.go b/rwtransaction_test.go index 19952e8..71edc64 100644 --- a/rwtransaction_test.go +++ b/rwtransaction_test.go @@ -28,16 +28,16 @@ func TestTransactionCreateBucket(t *testing.T) { assert.NoError(t, err) /* - // Open a separate read-only transaction. - rtxn, err := db.Transaction() - assert.NotNil(t, txn) - assert.NoError(t, err) + // Open a separate read-only transaction. + rtxn, err := db.Transaction() + assert.NotNil(t, txn) + assert.NoError(t, err) - b, err := rtxn.Bucket("widgets") - assert.NoError(t, err) - if assert.NotNil(t, b) { - assert.Equal(t, b.Name(), "widgets") - } + b, err := rtxn.Bucket("widgets") + assert.NoError(t, err) + if assert.NotNil(t, b) { + assert.Equal(t, b.Name(), "widgets") + } */ }) }