/** * @param callable $comparator * @param BinarySearchTree $tree */ function __construct(callable $comparator = null, BinarySearchTree $tree = null) { if ($tree !== null) { assert($tree->isEmpty()); $this->bst = $tree; if ($comparator !== null) { $tree->setCompare($comparator); } } else { $this->bst = new AvlTree($comparator); } }
/** * @param callable $comparator * @param BinarySearchTree $tree * @throws StateException */ function __construct(callable $comparator = null, BinarySearchTree $tree = null) { if ($tree !== null) { if (!$tree->isEmpty()) { throw new StateException('The BinarySearchTree provided to SortedSet was not empty'); } $this->bst = $tree; if ($comparator !== null) { $tree->setCompare($comparator); } } else { $this->bst = new AvlTree($comparator); } }