@param array $intervals

@return \IntervalTree\TreeNode|null
554490
protected function divide_intervals(array $intervals)
    {
        if (count($intervals) === 0) {
            return null;
        }

        $x_center = $this->center($intervals);
        $s_center = array();
        $s_left = array();
        $s_right = array();

        foreach ($intervals as $k) {
            if ($k->getStart() > $k->getEnd()) {
                throw new NegativeRangeException(
                    'Range is negative (maybe you entered the range in reverse order?)'
                );
            }
            if ($this->compare($k->getEnd(), $x_center) < 0) {
                $s_left[] = $k;
            } elseif ($this->compare($k->getStart(), $x_center) > 0) {
                $s_right[] = $k;
            } else {
                $s_center[] = $k;
            }
        }

        return new TreeNode(
            $x_center,
            $s_center,
            $this->divide_intervals($s_left),
            $this->divide_intervals($s_right)
        );
    }
1079791
private function parseElementNodes($children, $parentName = null)
    {
        $result = [];

        foreach ($children as $child) {
            $prefix = $child->prefix ?: null;
            $oname  = $this->normalizeKey($child->nodeName);
            $name   = $this->prefixKey($oname, $prefix);

            if (isset($result[$name])) {
                $this->parseSetResultNodes($child, $name, $result);
                continue;
            }

            $this->parseUnsetResultNodes($child, $name, $oname, $parentName, $result, $prefix);
        }

        return $result;
    }
317641
public function getFirstDescendantNode(...$classNames) {
        foreach ($this->getDescendantNodes() as $descendant) {
            foreach ($classNames as $className) {
                if ($descendant instanceof $className) {
                    return $descendant;
                }
            }
        }
        return null;
    }
284236
protected function loadTreeFromCache(): ?array
    {
        $cachedTree = $this->cache->getItem('ordermind.logauth.permissions');
        if ($cachedTree->isHit()) {
            return $cachedTree->get();
        }

        return null;
    }
447491
public function getTree( stdClass $params )
	{
		$this->_checkParams( $params, array( 'items' ) );

		$manager = $this->_getManager();

		$result = array();
		$items = ( !is_array( $params->items ) ? array( $params->items ) : $params->items );

		foreach( $items as $entry )
		{
			if( $entry == 'root' )
			{
				$search = $this->_manager->createSearch();
				$search->setConditions( $search->compare( '==', 'locale.site.level', 0 ) );

				$item = $this->_manager->createItem();
				$item->setLabel( 'Root' );

				foreach( $this->_manager->searchItems( $search ) as $siteItem ) {
					$item->addChild( $siteItem );
				}
			}
			else
			{
				$item = $manager->getTree( $entry, array(), MW_Tree_Manager_Abstract::LEVEL_LIST );
			}

			$result[] = $this->_createNodeArray( $item );
		}

		return array(
			'items' => ( !is_array( $params->items ) ? reset( $result ) : $result ),
			'success' => true,
		);
	}
616634
public function compute(Intervals $firstInterval, Intervals $secondInterval): Intervals
    {
        $first  = $firstInterval->getArrayCopy();
        $second = $secondInterval->getArrayCopy();
        if (0 === count($second)) {
            return $firstInterval;
        }

        $count = count($second);
        while ($count > 0) {
            $intervalToExclude = \array_shift($second);

            $newIntervals = [];

            /** @var Interval $interval */
            foreach ($first as $interval) {
                $newIntervals = \array_merge($newIntervals, $interval->exclude($intervalToExclude)->getArrayCopy());
            }

            $first                   = $newIntervals;
            $count                   = count($second);
        }

        return new Intervals($first);
    }
122736
public static function createFromArrayWithMinimumHeight(?array $array): ?BinarySearchTree {
        if (null === $array) {
            return null;
        }
        $tree = new BinarySearchTree();
        if (0 === \count($array)) {
            return $tree;
        }
        $sort = new MergeSort();
        $array = $sort->sort($array);
        $root = BinarySearchTree::_createFromArrayWithMinimumHeight($array, 0, \count($array) - 1);
        $tree = new BinarySearchTree();
        $tree->setRoot($root);
        return $tree;
    }
1241004
protected function buildNestedArray(array $nodes = [], $parentId = 0)
    {
        $branch = [];

        if (empty($nodes)) {
            $nodes = $this->allNodes();
        }

        foreach ($nodes as $node) {
            if ($node[$this->parentColumn] === $parentId) {
                $children = $this->buildNestedArray($nodes, $node[$this->getKeyName()]);

                if ($children) {
                    $node['children'] = $children;
                }

                $branch[] = $node;
            }
        }

        return $branch;
    }
193127
public static function getTree(array $columns = ['*'])
    {
        /**
         * @var Entity $instance
         */
        $instance = new static;

        return $instance->orderBy($instance->getParentIdColumn())->orderBy($instance->getPositionColumn())
            ->get($instance->prepareTreeQueryColumns($columns))->toTree();
    }
1027252
function array_sum_intervals($array_external, $intervals){

        $n_intervals=explode(";", $intervals);
        $array_amount = count($n_intervals);
        $result = 0;
        for($i=0; $i < $array_amount ; $i++){
            $result += $this->array_sum_interval($array_external, $n_intervals[$i]);
        }
        return $result;

    }
1120661
public function offsetGet($offset) {
        return isset($this->nodes[$offset]) ? $this->nodes[$offset] : null;
    }
1135783
public function getFirstChildNode(...$classNames) {
        foreach ($this::CHILD_NAMES as $name) {
            $val = $this->$name;
            foreach ($classNames as $className) {
                if (\is_array($val)) {
                    foreach ($val as $child) {
                        if ($child instanceof $className) {
                            return $child;
                        }
                    }
                    continue;
                } elseif ($val instanceof $className) {
                    return $val;
                }
            }
        }
        return null;
    }
795991
public function sub(/*\DateInterval*/ $interval) : \DateTime /*self invariant*/
    {
        // NB: Argument type hinting (\DateInterval $interval)
        // would provoke E_WARNING when cloning.
        // Catch 22: Specs say that native \DateTime method is type hinted,
        // but warning when cloning says it isn't.

        if ($this->frozen) {
            throw new \RuntimeException(get_class($this) . ' is read-only, frozen.');
        }
        return parent::sub($interval);
    }
157498
public function buildTree(Collection $nodes, $strict = true)
    {
        $refs  = []; // Reference table to store records in the construction of the tree
        $count = 0;
        $roots = new Collection();
        foreach ($nodes as &$node) {
            /* @var Tree $node */
            $node->initChildrenRelation(); // We need to init relation to avoid LAZY LOADING in future
            $refs[$node->getKey()] = &$node; // Adding to ref table (we identify after the id)
            if ($count === 0) {
                $roots->add($node);
                $count++;
            } else {
                if ($this->siblingOfRoot($node, $roots)) { // We use this condition as a factor in building subtrees
                    $roots->add($node);
                } else { // This is not a root, so add them to the parent
                    $index = $node->{$this->getTreeColumn('parent')};
                    if (!empty($refs[$index])) { // We should already have parent for our node added to refs array
                        $refs[$index]->addChildToCollection($node);
                    } else {
                        if ($strict) { // We don't want to ignore orphan nodes
                            throw new MissingParentException();
                        }
                    }
                }
            }
        }

        if (!empty($roots)) {
            if (count($roots) > 1) {
                return $roots;
            } else {
                return $roots->first();
            }
        } else {
            return false;
        }
    }
394328
public function withIntervalInSeconds($intervalInSeconds)
    {
        $this->validateInterval($intervalInSeconds);

        $this->interval = $intervalInSeconds;
        $this->intervalUnit = IntervalUnit::SECOND;

        return $this;
    }
528452
final public function setTreeMode(string $treeMode = null) : Table
    {
        if ($treeMode !== null) {
            $available = [
                self::TREE_MODE_NESTED_SET,
                self::TREE_MODE_MATERIALIZED_PATH,
            ];

            if (!in_array($treeMode, $available)) {
                throw new InvalidArgumentException('Invalid tree mode.');
            }
        }

        $this->treeMode = $treeMode;

        return $this;
    }
928717
private function getTopNodeByScore(array $nodes): ?Element {
        $topNode = null;
        $topNodeScore = 0;

        foreach ($nodes as $node) {
            $score = $this->getScore($node);

            if ($score > $topNodeScore) {
                $topNode = $node;
                $topNodeScore = $score;
            }

            if ($topNode === false) {
                $topNode = $node;
            }
        }

        if ($topNode && $this->getScore($topNode) < 20) {
            return null;
        }

        return $topNode;
    }