func (n *Treap[T]) join(other *Treap[T]) *Treap[T] {
	var result *Treap[T]
	resultp := &result
	for {
		if n == nil {
			*resultp = other
			return result
		}
		if other == nil {
			*resultp = n
			return result
		}

		if n.Priority <= other.Priority {
			root := &Treap[T]{n.Value, n.Priority, n.Left, nil}
			*resultp = root
			resultp = &root.Right
			n = n.Right
		} else {
			root := &Treap[T]{other.Value, other.Priority, nil, other.Right}
			*resultp = root
			resultp = &root.Left
			other = other.Left
		}
	}
}
// see https://www.cs.cmu.edu/~scandal/papers/treaps-spaa98.pdf
// "Fast Set Operations Using Treaps"
//   by Guy E Blelloch and Margaret Reid-Miller.
//
// The algorithm is a very slight variation on that provided there.
//
// Note that all nodes in n have priority <= that of "other" for
// this call to work correctly.  It traverses  the right spine of n
// and left-spine of other, merging things along the way
//
// The algorithm is not that  different from zipping up a spine


The algorithm is a very slight variation on that provided there.

Note that all nodes in n have priority <= that of "other" for
this call to work correctly.  It traverses  the right spine of n
and left-spine of other, merging things along the way

The algorithm is not that  different from zipping up a spine
// see https : // www . cs . cmu . edu / ~scandal / papers / treaps - spaa98 . pdf // " Fast Set Operations Using Treaps " // by Guy E Blelloch and Margaret Reid - Miller . // // The algorithm is a very slight variation on that provided there . // // Note that all nodes in n have priority < = that of " other " for // this call to work correctly . It traverses the right spine of n // and left - spine of other merging things along the way // // The algorithm is not that different from zipping up a spine
func (n *Treap[T]) join(other *Treap[T]) *Treap[T] {
	var result *Treap[T]
	resultp := &result
	for {
		if n == nil {
			*resultp = other
			return result
		}
		if other == nil {
			*resultp = n
			return result
		}
		if n.Priority <= other.Priority {
			root := &Treap[T]{n.Value, n.Priority, n.Left, nil}
			*resultp = root
			resultp = &root.Right
			n = n.Right
		} else {
			root := &Treap[T]{other.Value, other.Priority, nil, other.Right}
			*resultp = root
			resultp = &root.Left
			other = other.Left
		}
	}
}
func ( n * Treap [ T ] ) join ( other * Treap [ T ] ) * Treap [ T ] { var result * Treap [ T ] resultp := & result for { if n == nil { * resultp = other return result } if other == nil { * resultp = n return result } if n . Priority <= other . Priority { root := & Treap [ T ] { n . Value , n . Priority , n . Left , nil } * resultp = root resultp = & root . Right n = n . Right } else { root := & Treap [ T ] { other . Value , other . Priority , nil , other . Right } * resultp = root resultp = & root . Left other = other . Left } } }