Builds a root node.

@param AbstractCategoryDocument $node
@param \ArrayIterator           $tree
@param int                      $level
423657
private function buildRootNode($node, $tree, $level)
    {
        $node->setLevel($level);
        $tree[$node->getId()] = $node;
    }
495357
public function findChildren(callable $callback, $depth = null, $level = null)
    {

        $level = $level ?: 0;

        foreach ($this->children as $child) {

            /** @var NodeInterface $child */
            if ($child->is($callback))
                yield $child;

            if ($depth === null || $level < $depth) {

                if ($child instanceof NodeInterface)
                    foreach ($child->findChildren($callback, $depth, $level + 1) as $subChild)
                        yield $subChild;
            }
        }
    }
732293
public static function mapDescendantsArray(Tree $parent, Array $map)
    {
        foreach ($map as $item) {
            $node = new static($item);
            $node->setChildOf($parent);
            if (isset($item['children'])) {
                static::mapDescendantsArray($node, $item['children']);
            }
        }

    }
917941
public function _displayTree($tree, $parent = NULL)
    {
        $outputList = TRUE;
        foreach ($tree as $name => $element) {
            if ($element->superclass() == $parent) {
                if ($outputList) echo "<ul>\n";
                echo '<li><a href="', str_repeat('../', $this->_depth), $element->asPath(), '">', $element->qualifiedName(), '</a>';
                $this->_displayTree($tree, $name);
                echo "</li>\n";
                $outputList = FALSE;
            }
        }
        if (!$outputList) echo "</ul>\n";
    }
696899
public function getRoot($parentNodeCategory = null, $recursionLevel = 3)
    {
        if ($parentNodeCategory === null) {
            if ($this->getCurrentCategoryId()) {
                $this->getRootByIds([$this->getCurrentCategoryId()]);
            }
        }

        return parent::getRoot($parentNodeCategory, $recursionLevel);
    }
716075
function( node, level ) { // root node is on level 0
            this.levelMaxDim[level] = {
                width: Math.max( this.levelMaxDim[level]? this.levelMaxDim[level].width: 0, node.width ),
                height: Math.max( this.levelMaxDim[level]? this.levelMaxDim[level].height: 0, node.height )
            };
            return this;
        }
499774
public function _buildTree(&$rootDoc, &$class, $depth = NULL)
    {
        if ($depth === NULL) {
            $start = TRUE;
            $depth = 0;
        } else {
            $start = FALSE;
        }
        $output = '';
        $undefinedClass = FALSE;
        if ($class->superclass()) {
            $superclass =& $rootDoc->classNamed($class->superclass());
            if ($superclass) {
                $result = $this->_buildTree($rootDoc, $superclass, $depth);
                $output .= $result[0];
                $depth = ++$result[1];
            } else {
                $output .= $class->superclass().'<br>';
                $output .= str_repeat('   ', $depth).' └─';
                $depth++;
                $undefinedClass = TRUE;
            }
        }
        if ($depth > 0 && !$undefinedClass) {
            $output .= str_repeat('   ', $depth).' └─';
        }
        if ($start) {
            $output .= '<strong>'.$class->name().'</strong><br />';
        } else {
            $output .= '<a href="'.str_repeat('../', $this->_depth).$class->asPath().'">'.$class->name().'</a><br>';
        }

        return array($output, $depth);
    }
146396
function (node) {
    this.level++;
    for (var i = 0, count = node.childNodes.length; i < count; i++) {
      this._visit(node.childNodes[i]);
    }
    this.level--;
  }
301864
protected function buildTree($tree_data)
    {
        $parent_key = $this->config['parent'];
        $default_root_id = $this->config['default_root_id'];

        while (count($tree_data)) {
            $beginning_with = count($tree_data);

            foreach ($tree_data as $node_id => $node) {
                $node[$this->config['childs']] = [];
                $parent = (array_key_exists($parent_key, $node)) ? $node[$parent_key] : $default_root_id;
                if ($this->add($parent, $node[$this->config['id']], $node)) {
                    unset($tree_data[$node_id]);
                }
            }

            $this->ungracefulExit($beginning_with, $tree_data);
        }
    }
1143154
protected static function arrayToXmlInternal($data, $root = null, $level = 1, $format = true)
    {
        $xml = null;
        if (is_array($data)) {
            if (!Arr::isAssoc($data)) {
                foreach ($data as $value) {
                    $xml .= self::arrayToXmlInternal($value, $root, $level, $format);
                }
            } else {
                if (Arr::isAssoc($data)) {
                    if (!empty($root)) {
                        if ($format) {
                            $xml .= str_repeat("\t", $level - 1);
                        }
                        $xml .= "<$root>";
                        if ($format) {
                            $xml .= "\n";
                        }
                    }
                    foreach ($data as $key => $value) {
                        $xml .= self::arrayToXmlInternal($value, $key, $level + 1, $format);
                    }
                    if (!empty($root)) {
                        if ($format) {
                            $xml .= str_repeat("\t", $level - 1);
                        }
                        $xml .= "</$root>";
                        if ($format) {
                            $xml .= "\n";
                        }
                    }
                } else {
                    // empty array
                    if (!empty($root)) {
                        if ($format) {
                            $xml .= str_repeat("\t", $level - 1);
                        }
                        $xml .= "<$root></$root>";
                        if ($format) {
                            $xml .= "\n";
                        }
                    }
                }
            }
        } elseif (is_object($data)) {
            if ($data instanceof Arrayable) {
                $xml .= self::arrayToXmlInternal($data->toArray(), $root, $level, $format);
            } else {
                $dataString = (string)$data;
                if (!empty($root)) {
                    if ($format) {
                        $xml .= str_repeat("\t", $level - 1);
                    }
                    $xml .= "<$root>$dataString</$root>";
                    if ($format) {
                        $xml .= "\n";
                    }
                }
            }
        } else {
            // not an array or object
            if (!empty($root)) {
                if ($format) {
                    $xml .= str_repeat("\t", $level - 1);
                }
                $xml .= "<$root>";
                if (!is_null($data)) {
                    if (is_bool($data)) {
                        $xml .= ($data) ? 'true' : 'false';
                    } else {
                        if (is_int($data) || is_float($data)) {
                            $xml .= $data;
                        } else {
                            if (is_string($data)) {
                                $htmlValue = htmlspecialchars($data, ENT_QUOTES, 'UTF-8');
                                $xml .= $htmlValue;
                            }
                        }
                    }
                }
                $xml .= "</$root>";
                if ($format) {
                    $xml .= "\n";
                }
            }
        }

        return $xml;
    }
496978
protected function buildTree(int $i = 0, array &$children = [])
    {
        $max = \count($this->trace);

        while ($i < $max) {
            $trace = $this->trace[$i];

            if ($trace instanceof Entry) {
                $ruleName = $trace->getRule();
                $rule = $this->grammar->fetch($ruleName);
                $isRule = $trace->isTransitional() === false;
                $nextTrace = $this->trace[$i + 1];
                $id = $rule->getNodeId();

                // Optimization: Skip empty trace sequence.
                if ($nextTrace instanceof Escape && $ruleName === $nextTrace->getRule()) {
                    $i += 2;

                    continue;
                }

                if ($isRule === true) {
                    $children[] = $ruleName;
                }

                if ($id !== null) {
                    $children[] = [$id];
                }

                $i = $this->buildTree($i + 1, $children);

                if ($isRule === false) {
                    continue;
                }

                $handle = [];
                $childId = null;

                do {
                    $pop = \array_pop($children);

                    if (\is_object($pop) === true) {
                        $handle[] = $pop;
                    } elseif (\is_array($pop) && $childId === null) {
                        $childId = \reset($pop);
                    } elseif ($ruleName === $pop) {
                        break;
                    }
                } while ($pop !== null);

                if ($childId === null) {
                    $childId = $rule->getDefaultId();
                }

                if ($childId === null) {
                    for ($j = \count($handle) - 1; $j >= 0; --$j) {
                        $children[] = $handle[$j];
                    }

                    continue;
                }

                $children[] = $this->getRule(
                    (string)($id ?: $childId),
                    \array_reverse($handle),
                    $trace->getOffset()
                );
            } elseif ($trace instanceof Escape) {
                return $i + 1;
            } else {
                if (! $trace->isKept()) {
                    ++$i;
                    continue;
                }

                $children[] = new Leaf($trace->getToken());
                ++$i;
            }
        }

        return $children[0];
    }
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;
        }
    }
267871
function _buildLevel(nodes) {
		var level = []
		levels.push(level)
		var parents = []
		each(nodes, function(node) {
			if (!seenPaths[node.path]) {
				seenPaths[node.path] = true
				level.push(node.path)
			}
			if (node.isRoot) { return }

			node.parent.waitingForNumChildren -= 1

			if (node.parent.waitingForNumChildren == 0) {
				parents.push(node.parent)
			}
		})
		if (!parents.length) { return }
		_buildLevel(parents)
	}
197281
protected function set_level($level) {
        $this->level = $level;
        foreach ($this->subtree as $tab) {
            $tab->set_level($level + 1);
        }
    }
434387
final public function accessLevel(Tree $tree, string $interface): int
    {
        $access_levels = app('cache.array')
            ->rememberForever('module_privacy' . $tree->id(), static function () use ($tree): Collection {
                return DB::table('module_privacy')
                    ->where('gedcom_id', '=', $tree->id())
                    ->get();
            });

        $row = $access_levels->first(function (stdClass $row) use ($interface): bool {
            return $row->interface === $interface && $row->module_name === $this->name();
        });

        return $row ? (int) $row->access_level : $this->access_level;
    }
1209240
protected function setupTree(ArrayNodeDefinition $rootNode)
    {
        $rootNode
            ->children()
                ->arrayNode('repositories')
                    ->prototype('array')
                        ->children()
                            ->scalarNode('secret')
                                ->isRequired()
                            ->end()
                            ->scalarNode('endpoint')
                                ->isRequired()
                            ->end()
                            ->booleanNode('test')
                                ->defaultFalse();
    }
185214
public function indexChildren(Node $node, $lang)
    {
        foreach ($node->getChildren() as $childNode) {
            $this->indexNode($childNode, $lang);
        }
    }