func (n *Treap[T]) Union(other *Treap[T], c CompareFn[T], overwrite bool) *Treap[T] {
	if n == nil {
		return other
	}
	if other == nil {
		return n
	}

	if n.Priority < other.Priority {
		other, n, overwrite = n, other, !overwrite
	}

	left, dupe, right := other.Split(n.Value, c)
	value := n.Value
	if overwrite && dupe != nil {
		value = dupe.Value
	}
	left = n.Left.Union(left, c, overwrite)
	right = n.Right.Union(right, c, overwrite)
	return &Treap[T]{value, n.Priority, left, right}
}
// Union combines any two treaps. In case of duplicates, the overwrite
// field controls whether the union keeps the original value or
// whether it is updated based on value in the "other" arg
Union combines any two treaps. In case of duplicates, the overwrite
field controls whether the union keeps the original value or
whether it is updated based on value in the "other" arg
// Union combines any two treaps . In case of duplicates the overwrite // field controls whether the union keeps the original value or // whether it is updated based on value in the " other " arg
func (n *Treap[T]) Union(other *Treap[T], c CompareFn[T], overwrite bool) *Treap[T] {
	if n == nil {
		return other
	}
	if other == nil {
		return n
	}
	if n.Priority < other.Priority {
		other, n, overwrite = n, other, !overwrite
	}
	left, dupe, right := other.Split(n.Value, c)
	value := n.Value
	if overwrite && dupe != nil {
		value = dupe.Value
	}
	left = n.Left.Union(left, c, overwrite)
	right = n.Right.Union(right, c, overwrite)
	return &Treap[T]{value, n.Priority, left, right}
}
func ( n * Treap [ T ] ) Union ( other * Treap [ T ] , c CompareFn [ T ] , overwrite bool ) * Treap [ T ] { if n == nil { return other } if other == nil { return n } if n . Priority < other . Priority { other , n , overwrite = n , other , ! overwrite } left , dupe , right := other . Split ( n . Value , c ) value := n . Value if overwrite && dupe != nil { value = dupe . Value } left = n . Left . Union ( left , c , overwrite ) right = n . Right . Union ( right , c , overwrite ) return & Treap [ T ] { value , n . Priority , left , right } }
Union combines any two treaps.
Union combines any two treaps .