Skip to content

Commit

Permalink
Merge pull request #192 from rsc/no-uuid
Browse files Browse the repository at this point in the history
btree: remove dependency on github.com/satori/go.uuid
  • Loading branch information
brianshannan-wf authored May 25, 2018
2 parents 01f52d4 + 655baf1 commit 511e373
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
23 changes: 17 additions & 6 deletions btree/immutable/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,22 @@ limitations under the License.
package btree

import (
"crypto/rand"
"io"
"sort"

"github.com/satori/go.uuid"
)

func newID() []byte {
id := make([]byte, 16)
_, err := io.ReadFull(rand.Reader, id)
if err != nil {
// This can't happen unless the system is badly
// configured, like /dev/urandom isn't readable.
panic("reading random: " + err.Error())
}
return id
}

// ID exists because i'm tired of writing []byte
type ID []byte

Expand Down Expand Up @@ -120,7 +131,7 @@ func (n *Node) copy() *Node {
copy(cpKeys, n.ChildKeys)

return &Node{
ID: uuid.NewV4().Bytes(),
ID: newID(),
IsLeaf: n.IsLeaf,
ChildValues: cpValues,
ChildKeys: cpKeys,
Expand Down Expand Up @@ -297,7 +308,7 @@ func (n *Node) deleteKeyAt(i int) {
func (n *Node) splitLeafAt(i int) (interface{}, *Node) {
left := newNode()
left.IsLeaf = n.IsLeaf
left.ID = uuid.NewV4().Bytes()
left.ID = newID()

value := n.ChildValues[i]
leftValues := make([]interface{}, i+1)
Expand All @@ -320,7 +331,7 @@ func (n *Node) splitLeafAt(i int) (interface{}, *Node) {
func (n *Node) splitInternalAt(i int) (interface{}, *Node) {
left := newNode()
left.IsLeaf = n.IsLeaf
left.ID = uuid.NewV4().Bytes()
left.ID = newID()
value := n.ChildValues[i]
leftValues := make([]interface{}, i)
copy(leftValues, n.ChildValues[:i])
Expand Down Expand Up @@ -421,7 +432,7 @@ func nodeFromBytes(t *Tr, data []byte) (*Node, error) {
// IsLeaf is false by default.
func newNode() *Node {
return &Node{
ID: uuid.NewV4().Bytes(),
ID: newID(),
}
}

Expand Down
10 changes: 3 additions & 7 deletions btree/immutable/rt.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ limitations under the License.

package btree

import (
"sync"

"github.com/satori/go.uuid"
)
import "sync"

// context is used to keep track of the nodes in this mutable
// that have been created. This is basically any node that had
Expand Down Expand Up @@ -149,7 +145,7 @@ func (t *Tr) Len() int {
func (t *Tr) AsMutable() MutableTree {
return &Tr{
Count: t.Count,
UUID: uuid.NewV4().Bytes(),
UUID: newID(),
Root: t.Root,
config: t.config,
cacher: t.cacher,
Expand Down Expand Up @@ -197,7 +193,7 @@ func treeFromBytes(p Persister, data []byte, comparator Comparator) (*Tr, error)
func newTree(cfg Config) *Tr {
return &Tr{
config: cfg,
UUID: uuid.NewV4().Bytes(),
UUID: newID(),
cacher: newCacher(cfg.Persister),
}
}
Expand Down
3 changes: 1 addition & 2 deletions btree/immutable/rt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"testing"
"time"

"github.com/satori/go.uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -220,7 +219,7 @@ func generateRandomQuery() (interface{}, interface{}) {
func newItem(value interface{}) *Item {
return &Item{
Value: value,
Payload: uuid.NewV4().Bytes(),
Payload: newID(),
}
}

Expand Down
2 changes: 0 additions & 2 deletions glide.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package: github.com/Workiva/go-datastructures
import:
- package: github.com/satori/go.uuid
version: ^1.1.0
- package: github.com/stretchr/testify
version: ^1.1.4
subpackages:
Expand Down

0 comments on commit 511e373

Please sign in to comment.