Skip to content
This repository has been archived by the owner on Mar 9, 2019. It is now read-only.

Commit

Permalink
Merge pull request #2 from benbjohnson/master
Browse files Browse the repository at this point in the history
gofmt
  • Loading branch information
benbjohnson committed Jan 30, 2014
2 parents 342464b + 8d5757e commit d087fb4
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 27 deletions.
9 changes: 4 additions & 5 deletions branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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}
}

Expand All @@ -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{}
Expand All @@ -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 }

6 changes: 3 additions & 3 deletions bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type Bucket struct {
}

type bucket struct {
root pgid
root pgid
}

// Name returns the name of the bucket.
Expand All @@ -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),
}
}
6 changes: 3 additions & 3 deletions cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
})
}
Expand Down
2 changes: 1 addition & 1 deletion db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
7 changes: 3 additions & 4 deletions leaf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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}
}

Expand All @@ -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{}
Expand All @@ -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 }

2 changes: 1 addition & 1 deletion rwtransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 10 additions & 10 deletions rwtransaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
b, err := rtxn.Bucket("widgets")
assert.NoError(t, err)
if assert.NotNil(t, b) {
assert.Equal(t, b.Name(), "widgets")
}
// 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")
}
*/
})
}
Expand Down

0 comments on commit d087fb4

Please sign in to comment.