func (n *Treap[T]) Split(v T, c CompareFn[T]) (left, mid, right *Treap[T]) {
	leftp, rightp := &left, &right
	for {
		if n == nil {
			*leftp = nil
			*rightp = nil
			return left, nil, right
		}

		root := &Treap[T]{n.Value, n.Priority, nil, nil}
		diff := c(n.Value, v)
		switch {
		case diff < 0:
			*leftp = root
			root.Left = n.Left
			leftp = &root.Right
			n = n.Right
		case diff > 0:
			*rightp = root
			root.Right = n.Right
			rightp = &root.Left
			n = n.Left
		default:
			*leftp = n.Left
			*rightp = n.Right
			return left, root, right
		}
	}
}
// Split splits the treap into all nodes that compare less-than, equal
// and greater-than the provided value.  The resulting values are
// properly formed treaps or nil if they contain no values.
Split splits the treap into all nodes that compare less-than, equal
and greater-than the provided value.  The resulting values are
properly formed treaps or nil if they contain no values.
// Split splits the treap into all nodes that compare less - than equal // and greater - than the provided value . The resulting values are // properly formed treaps or nil if they contain no values .
func (n *Treap[T]) Split(v T, c CompareFn[T]) (left, mid, right *Treap[T]) {
	leftp, rightp := &left, &right
	for {
		if n == nil {
			*leftp = nil
			*rightp = nil
			return left, nil, right
		}
		root := &Treap[T]{n.Value, n.Priority, nil, nil}
		diff := c(n.Value, v)
		switch {
		case diff < 0:
			*leftp = root
			root.Left = n.Left
			leftp = &root.Right
			n = n.Right
		case diff > 0:
			*rightp = root
			root.Right = n.Right
			rightp = &root.Left
			n = n.Left
		default:
			*leftp = n.Left
			*rightp = n.Right
			return left, root, right
		}
	}
}
func ( n * Treap [ T ] ) Split ( v T , c CompareFn [ T ] ) ( left , mid , right * Treap [ T ] ) { leftp , rightp := & left , & right for { if n == nil { * leftp = nil * rightp = nil return left , nil , right } root := & Treap [ T ] { n . Value , n . Priority , nil , nil } diff := c ( n . Value , v ) switch { case diff < 0 : * leftp = root root . Left = n . Left leftp = & root . Right n = n . Right case diff > 0 : * rightp = root root . Right = n . Right rightp = & root . Left n = n . Left default : * leftp = n . Left * rightp = n . Right return left , root , right } } }
Split splits the treap into all nodes that compare less-than, equal
and greater-than the provided value.
Split splits the treap into all nodes that compare less - than equal and greater - than the provided value .