Retrieves the node with the maximum key in a subtree

@param RedBlackNode $node The subtree root

@return RedBlackNode
554670
protected function nodeMax(RedBlackNode $node): RedBlackNode
    {
        if ($node->right() === null) {
            return $node;
        }

        return $this->nodeMax($node->right());
    }
114949
private function nodeRequiredIfEnabled($node)
    {
        return function ($value) use ($node) {
            if (!$value['enabled']) {
                return false;
            }

            if (isset($value[$node]) && !empty($value[$node])) {
                return false;
            }

            return true;
        };
    }
483414
protected function nodeSet($key, $value, ?RedBlackNode $node): RedBlackNode
    {
        if ($node === null) {
            return new RedBlackNode($key, $value, 1, RedBlackNode::RED);
        }

        $comp = $this->comparator->compare($key, $node->key());

        if ($comp < 0) {
            $node->setLeft($this->nodeSet($key, $value, $node->left()));
        } elseif ($comp > 0) {
            $node->setRight($this->nodeSet($key, $value, $node->right()));
        } else {
            $node->setValue($value);
        }

        return $this->balanceOnInsert($node);
    }
1327163
private function getNodes($node)
    {
        $this->logger->info('[Get Nodes] Retrieving nodes...');

        $stripUnlikelyCandidates = $this->configuration->getStripUnlikelyCandidates();

        $elementsToScore = [];

        /*
         * First, node prepping. Trash nodes that look cruddy (like ones with the
         * class name "comment", etc), and turn divs into P tags where they have been
         * used inappropriately (as in, where they contain no other block level elements.)
         */

        while ($node) {
            // Remove DOMComments nodes as we don't need them and mess up children counting
            if ($node->nodeType === XML_COMMENT_NODE) {
                $this->logger->debug(sprintf('[Get Nodes] Found comment node, removing... Node content was: \'%s\'', substr($node->nodeValue, 0, 128)));
                $node = NodeUtility::removeAndGetNext($node);
                continue;
            }

            $matchString = $node->getAttribute('class') . ' ' . $node->getAttribute('id');

            if (!$node->isProbablyVisible()) {
                $this->logger->debug(sprintf('[Get Nodes] Removing hidden node... Match string was: \'%s\'', $matchString));
                $node = NodeUtility::removeAndGetNext($node);
                continue;
            }

            // Check to see if this node is a byline, and remove it if it is.
            if ($this->checkByline($node, $matchString)) {
                $this->logger->debug(sprintf('[Get Nodes] Found byline, removing... Node content was: \'%s\'', substr($node->nodeValue, 0, 128)));
                $node = NodeUtility::removeAndGetNext($node);
                continue;
            }

            // Remove unlikely candidates
            if ($stripUnlikelyCandidates) {
                if (
                    preg_match(NodeUtility::$regexps['unlikelyCandidates'], $matchString) &&
                    !preg_match(NodeUtility::$regexps['okMaybeItsACandidate'], $matchString) &&
                    $node->nodeName !== 'body' &&
                    $node->nodeName !== 'a'
                ) {
                    $this->logger->debug(sprintf('[Get Nodes] Removing unlikely candidate. Node content was: \'%s\'', substr($node->nodeValue, 0, 128)));
                    $node = NodeUtility::removeAndGetNext($node);
                    continue;
                }
            }

            // Remove DIV, SECTION, and HEADER nodes without any content(e.g. text, image, video, or iframe).
            if (($node->nodeName === 'div' || $node->nodeName === 'section' || $node->nodeName === 'header' ||
                    $node->nodeName === 'h1' || $node->nodeName === 'h2' || $node->nodeName === 'h3' ||
                    $node->nodeName === 'h4' || $node->nodeName === 'h5' || $node->nodeName === 'h6' ||
                    $node->nodeName === 'p') &&
                $node->isElementWithoutContent()) {
                $this->logger->debug(sprintf('[Get Nodes] Removing empty \'%s\' node.', $node->nodeName));
                $node = NodeUtility::removeAndGetNext($node);
                continue;
            }

            if (in_array(strtolower($node->nodeName), $this->defaultTagsToScore)) {
                $this->logger->debug(sprintf('[Get Nodes] Adding node to score list, node content is: \'%s\'', substr($node->nodeValue, 0, 128)));
                $elementsToScore[] = $node;
            }

            // Turn all divs that don't have children block level elements into p's
            if ($node->nodeName === 'div') {
                // Put phrasing content into paragraphs.
                $p = null;
                $childNode = $node->firstChild;
                while ($childNode) {
                    $nextSibling = $childNode->nextSibling;
                    if ($childNode->isPhrasingContent()) {
                        if ($p !== null) {
                            $p->appendChild($childNode);
                        } elseif (!$childNode->isWhitespace()) {
                            $p = $this->dom->createElement('p');
                            $node->replaceChild($p, $childNode);
                            $p->appendChild($childNode);
                        }
                    } elseif ($p !== null) {
                        while ($p->lastChild && $p->lastChild->isWhitespace()) {
                            $p->removeChild($p->lastChild);
                        }
                        $p = null;
                    }
                    $childNode = $nextSibling;
                }

                /*
                 * Sites like http://mobile.slate.com encloses each paragraph with a DIV
                 * element. DIVs with only a P element inside and no text content can be
                 * safely converted into plain P elements to avoid confusing the scoring
                 * algorithm with DIVs with are, in practice, paragraphs.
                 */
                if ($node->hasSingleTagInsideElement('p') && $node->getLinkDensity() < 0.25) {
                    $this->logger->debug(sprintf('[Get Nodes] Found DIV with a single P node, removing DIV. Node content is: \'%s\'', substr($node->nodeValue, 0, 128)));
                    $pNode = $node->getChildren(true)[0];
                    $node->parentNode->replaceChild($pNode, $node);
                    $node = $pNode;
                    $elementsToScore[] = $node;
                } elseif (!$node->hasSingleChildBlockElement()) {
                    $this->logger->debug(sprintf('[Get Nodes] Found DIV with a single child block element, converting to a P node. Node content is: \'%s\'', substr($node->nodeValue, 0, 128)));
                    $node = NodeUtility::setNodeTag($node, 'p');
                    $elementsToScore[] = $node;
                }
            }

            $node = NodeUtility::getNextNode($node);
        }

        return $elementsToScore;
    }
1322020
public static function fromNode( $node )
	{
		$result = new PathStep();
		$result->nodeTest = null;
		$result->type = XPath2ExprType::Expr;
		$result->node = $node;
		return $result;
	}
291640
protected function detachFromTree(AbstractNestedNode $node)
    {
        if (true === $node->isRoot()) {
            return $this;
        }

        $this->refreshExistingNode($node)
                ->createQueryBuilder('n')
                ->set('n._leftnode', 'n._leftnode - :delta_node')
                ->set('n._rightnode', 'n._rightnode - :delta_node')
                ->set('n._level', 'n._level - :delta_level')
                ->set('n._root', ':node')
                ->andIsDescendantOf($node)
                ->setParameter('delta_node', $node->getLeftnode() - 1)
                ->setParameter('delta_level', $node->getLevel())
                ->setParameter('node', $node)
                ->update()
                ->getQuery()
                ->execute();

        $this->shiftRlValues($node, $node->getLeftnode(), - $node->getWeight());

        $node->setRightnode($node->getWeight())
                ->setLeftnode(1)
                ->setLevel(0)
                ->setRoot($node);

        return $this;
    }
676688
private function getNodeIndex( $node )
	{
		for( $i=0; $i<$this->count(); $i++ )
			if( $this->nodes[$i] == $node )
				return $i;
		return NULL;
	}
163712
public function getLastChild(AbstractNestedNode $node)
    {
        $children = $this->getDescendants($node, 1);
        if (0 < count($children)) {
            return $children[count($children) - 1];
        }

        return;
    }
485681
protected function moveRedRight(RedBlackNode $node): RedBlackNode
    {
        $this->flipColors($node);
        if ($this->isRed($node->left()->left())) {
            $node = $this->rotateRight($node);
            $this->flipColors($node);
        }

        return $node;
    }
1296471
protected function nodeCeiling($key, ?RedBlackNode $node): ?RedBlackNode
    {
        if ($node === null) {
            return null;
        }

        $comp = $this->comparator->compare($key, $node->key());

        if ($comp === 0) {
            return $node;
        }
        if ($comp > 0) {
            return $this->nodeCeiling($key, $node->right());
        }
        $left = $this->nodeCeiling($key, $node->left());
        if ($left !== null) {
            return $left;
        }

        return $node;
    }
1341014
public function getPath($node) {
    // ACTIVE ?
    
    $qb = $this->createQueryBuilder('node');
    $qb
        ->where($qb->expr()->lte('node.lft', $node->getLft()))
        ->andWhere($qb->expr()->gte('node.rgt', $node->getRgt()))
        ->andWhere('node.context = :context')
        ->orderBy('node.lft', 'ASC')
    ;
    
    /*
    if (isset($config['root'])) {
        $rootId = $wrapped->getPropertyValue($config['root']);
        $qb->andWhere($rootId === null ?
            $qb->expr()->isNull('node.'.$config['root']) :
            $qb->expr()->eq('node.'.$config['root'], is_string($rootId) ? $qb->expr()->literal($rootId) : $rootId)
        );
    }
    */
    $query = $qb->getQuery()->setParameter('context', $node->getContext());
    
    return $query->getResult();
  }
1250778
protected function nodeRemoveMin(RedBlackNode $node): ?RedBlackNode
    {
        if ($node->left() === null) {
            return null;
        }

        if (!$this->isRed($node->left()) && !$this->isRed($node->left()->left())) {
            $node = $this->moveRedLeft($node);
        }

        $node->setLeft($this->nodeRemoveMin($node->left()));

        return $this->balanceOnRemove($node);
    }
202854
public Node<T> getMax() {
		if (size == 0) return null;
		Node<RedBlackTreeLong<T>> e = ranges.getMax();
		return e.getElement().getMax();
	}
1012033
public function getNextPossibleIdInContext(Node $node)
    {
        if (!isset($this->idList[$node->id])) {
            return $node->id;
        }

        $newId = false;
        $id    = $node->id;
        for ($i = 0; $newId == false; $i++) {
            $newId = rtrim($id, $node->keyDelimiter) . Node::MULTIPLE_ID_ENTRY_DELIMITER . "$i{$node->keyDelimiter}";

            if ($id > 100) {
                throw new \Exception('Are you crazy? 1000 child elements with the same ID ?');
            }
        }

        return $newId;
    }
518383
protected function getValueFromNode($node)
	{
		switch ($node['type'])
		{
			case 'integer':
				$value = (string) $node;
				return (int) $value;
				break;
			case 'string':
				return (string) $node;
				break;
			case 'boolean':
				$value = (string) $node;
				return (bool) $value;
				break;
			case 'double':
				$value = (string) $node;
				return (float) $value;
				break;
			case 'array':
				$value = array();
				foreach ($node->children() as $child)
				{
					$value[(string) $child['name']] = $this->getValueFromNode($child);
				}
				break;
			default:
				$value = new stdClass;
				foreach ($node->children() as $child)
				{
					$value->{$child['name']} = $this->getValueFromNode($child);
				}
				break;
		}

		return $value;
	}
1205083
protected function getInner(\DOMNode $node)
    {
        $c14n = $node->C14N();
        $begin = strpos($c14n, '>');
        $end   = strrpos($c14n, '<');

        $content = substr($c14n, $begin + 1, $end - $begin - 1);

        return $content;
    }
538996
public function enterNode(Node $node)
    {
        if ($node instanceof ConstFetch || $node instanceof FuncCall) {
            $node->name = null;
        }

        if ($node instanceof FullyQualified) {
            $this->names[] = $node->toString();
        }

        return $node;
    }