diff --git a/helpers.go b/helpers.go index 01e37c2..2d31fb9 100644 --- a/helpers.go +++ b/helpers.go @@ -186,7 +186,7 @@ func (t Tree[T]) FprintBST(w io.Writer) error { // preorderStringify, traverse the tree, stringify the nodes in preorder func (n *node[T]) preorderStringify(w io.Writer, pad string) error { // stringify this node - if _, err := fmt.Fprintf(w, "%v [prio:%.4g] [%p|l:%p|r:%p]\n", n.item, n.prio, n, n.left, n.right); err != nil { + if _, err := fmt.Fprintf(w, "%v [prio:%.4g] [%p|l:%p|r:%p]\n", n.item, float64(n.prio)/math.MaxUint32, n, n.left, n.right); err != nil { return err } diff --git a/treap.go b/treap.go index ab7d2a2..e82b667 100644 --- a/treap.go +++ b/treap.go @@ -22,8 +22,8 @@ type node[T Interface[T]] struct { // base treap fields, in memory efficient order left *node[T] right *node[T] - prio float64 // random key for binary heap, balances the tree - item T // generic key/value + prio uint32 // random key for binary heap, balances the tree + item T // generic key/value } // Tree is the public handle to the hidden implementation. @@ -46,7 +46,7 @@ func NewTree[T Interface[T]](items ...T) Tree[T] { func makeNode[T Interface[T]](item T) *node[T] { n := new(node[T]) n.item = item - n.prio = rand.Float64() + n.prio = rand.Uint32() n.recalc() // initial calculation of finger pointers... return n