Ejemplo n.º 1
0
 /**
  * @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);
     }
 }
Ejemplo n.º 2
0
 /**
  * @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);
     }
 }