@@ -19,11 +19,22 @@ limitations under the License.
1919package btree
2020
2121import (
22+ "crypto/rand"
23+ "io"
2224 "sort"
23-
24- "github.com/satori/go.uuid"
2525)
2626
27+ func newID () []byte {
28+ id := make ([]byte , 16 )
29+ _ , err := io .ReadFull (rand .Reader , id )
30+ if err != nil {
31+ // This can't happen unless the system is badly
32+ // configured, like /dev/urandom isn't readable.
33+ panic ("reading random: " + err .Error ())
34+ }
35+ return id
36+ }
37+
2738// ID exists because i'm tired of writing []byte
2839type ID []byte
2940
@@ -120,7 +131,7 @@ func (n *Node) copy() *Node {
120131 copy (cpKeys , n .ChildKeys )
121132
122133 return & Node {
123- ID : uuid . NewV4 (). Bytes (),
134+ ID : newID (),
124135 IsLeaf : n .IsLeaf ,
125136 ChildValues : cpValues ,
126137 ChildKeys : cpKeys ,
@@ -297,7 +308,7 @@ func (n *Node) deleteKeyAt(i int) {
297308func (n * Node ) splitLeafAt (i int ) (interface {}, * Node ) {
298309 left := newNode ()
299310 left .IsLeaf = n .IsLeaf
300- left .ID = uuid . NewV4 (). Bytes ()
311+ left .ID = newID ()
301312
302313 value := n .ChildValues [i ]
303314 leftValues := make ([]interface {}, i + 1 )
@@ -320,7 +331,7 @@ func (n *Node) splitLeafAt(i int) (interface{}, *Node) {
320331func (n * Node ) splitInternalAt (i int ) (interface {}, * Node ) {
321332 left := newNode ()
322333 left .IsLeaf = n .IsLeaf
323- left .ID = uuid . NewV4 (). Bytes ()
334+ left .ID = newID ()
324335 value := n .ChildValues [i ]
325336 leftValues := make ([]interface {}, i )
326337 copy (leftValues , n .ChildValues [:i ])
@@ -421,7 +432,7 @@ func nodeFromBytes(t *Tr, data []byte) (*Node, error) {
421432// IsLeaf is false by default.
422433func newNode () * Node {
423434 return & Node {
424- ID : uuid . NewV4 (). Bytes (),
435+ ID : newID (),
425436 }
426437}
427438
0 commit comments