FIXME: expensive depth computation by following a path.

@return depth
164487
public int getHeight() {
    int levels = 0;
    N node = getRoot();

    while(!node.isLeaf()) {
      if(node.getNumEntries() > 0) {
        node = getNode(node.getEntry(0));
        levels++;
      }
    }
    return levels;
  }
1224369
public Iterator depthFirst() {
        return new Iterator() {
            private final List list = new LinkedList();
            private final Stack stack = new Stack();
            private Iterator iter = iterator();
            private GPathResult next = getNextByDepth();

            public boolean hasNext() {
                return this.next != null;
            }

            public Object next() {
                try {
                    return this.next;
                } finally {
                    this.next = getNextByDepth();
                }
            }

            public void remove() {
                throw new UnsupportedOperationException();
            }

            private GPathResult getNextByDepth() {
                while (this.iter.hasNext()) {
                    final GPathResult node = (GPathResult) this.iter.next();
                    this.list.add(node);
                    this.stack.push(this.iter);
                    this.iter = node.children().iterator();
                }

                if (this.list.isEmpty()) {
                    return null;
                } else {
                    GPathResult result = (GPathResult) this.list.get(0);
                    this.list.remove(0);
                    this.iter = (Iterator) this.stack.pop();
                    return result;
                }
            }
        };
    }
1182575
public function getRelativePath()
    {
        return trim(substr($this->path, strlen($this->basePath)), self::TRIM_CHARS);
    }
738956
public function _getByPath($path)
    {
        $result = null;
        $steps = $this->_pathAsArray($path);
        $depth = count($steps); // number of steps in the path
        if ($depth == 0) {
            $result = $this->data;
        } else {
            $pointer = $this->data;
            $level = 0;
            foreach ($steps as $step) {
                if (is_array($pointer)) {
                    if (isset($pointer[$step])) {
                        /* go to the next step */
                        $pointer = $pointer[$step];
                    } else {
                        /* next step is missed in the path, return null */
                        break;
                    }
                } elseif ($pointer instanceof \Flancer32\Lib\Data) {
                    if (!is_null($pointer->get($step))) {
                        /* go to the next step */
                        $pointer = $pointer->get($step);
                    } else {
                        /* next step is missed in the path, return null */
                        break;
                    }
                } elseif (is_object($pointer)) {
                    if (isset($pointer->$step)) {
                        /* go to the next step */
                        $pointer = $pointer->$step;
                    } else {
                        /* next step is missed in the path, return null */
                        break;
                    }
                } else {
                    /* we have no data for the next step */
                    break;
                }
                $level++; // one step on the path is done
            }
            if ($level >= $depth) {
                /* we have reached the end of path */
                $result = $pointer;
            }
        }
        return $result;
    }
1088943
public function unhardenedLast() {
        $path = $this->path;

        $last = array_pop($path);

        $last = str_replace("'", "", $last);

        $path[] = $last;

        return new static($path);
    }
337303
public function withAnyDistance(): self
    {
        if ($this->elements->size() < 3) {
            throw new LogicException;
        }

        $path = clone $this;
        $path->elements = $this
            ->elements
            ->dropEnd(2)
            ->add(
                $this->elements->dropEnd(1)->last()->withAnyDistance()
            )
            ->add($this->elements->last());

        return $path;
    }
552892
public function getDepth() : ?int 
    {
        if ( ! $this->hasDepth()) {
            $this->setDepth($this->getDefaultDepth());
        }
        return $this->depth;
    }
530155
private function searchTree(int $depth = 0)
    {
        $this->depth = $depth;
        foreach ($this->children->getList() as $node) {
            if ($depth > count($this->treePath)) {
                break;
            }

            if ($this->treePath[$depth] != $node->key) {
                continue;
            }

            /**
             * @var $node TreeNode
             */
            if (count($this->treePath) > $depth && $this->allowedToDiveDeeper($depth)) {
                $node->setTreePath($this->treePath);

                return $node->searchTree(++$depth);
            }
        }

        return $this;
    }
486220
public function traverse()
    {
        // If the recursive flag is passed, traverse recursively.
        if ($this->recursive) {
            $objects = new \RecursiveIteratorIterator(
                new \RecursiveDirectoryIterator($this->path), \RecursiveIteratorIterator::SELF_FIRST
            );
            foreach ($objects as $fileInfo) {
                if (($fileInfo->getFilename() != '.') && ($fileInfo->getFilename() != '..')) {
                    $this->objects[] = $fileInfo;
                    // If absolute path flag was passed, store the absolute path.
                    if ($this->absolute) {
                        $f = null;
                        if (!$this->filesOnly) {
                            $f = ($fileInfo->isDir()) ? (realpath($fileInfo->getPathname())) : realpath($fileInfo->getPathname());
                        } else if (!$fileInfo->isDir()) {
                            $f = realpath($fileInfo->getPathname());
                        }
                        if (($f !== false) && (null !== $f)) {
                            $this->files[] = $f;
                        }
                    // If relative path flag was passed, store the relative path.
                    } else if ($this->relative) {
                        $f = null;
                        if (!$this->filesOnly) {
                            $f = ($fileInfo->isDir()) ? (realpath($fileInfo->getPathname())) : realpath($fileInfo->getPathname());
                        } else if (!$fileInfo->isDir()) {
                            $f = realpath($fileInfo->getPathname());
                        }
                        if (($f !== false) && (null !== $f)) {
                            $this->files[] = substr($f, (strlen(realpath($this->path)) + 1));
                        }
                    // Else, store only the directory or file name.
                    } else {
                        if (!$this->filesOnly) {
                            $this->files[] = ($fileInfo->isDir()) ? ($fileInfo->getFilename()) : $fileInfo->getFilename();
                        } else if (!$fileInfo->isDir()) {
                            $this->files[] = $fileInfo->getFilename();
                        }
                    }
                }
            }
            // Else, only traverse the single directory that was passed.
        } else {
            foreach (new \DirectoryIterator($this->path) as $fileInfo) {
                if(!$fileInfo->isDot()) {
                    $this->objects[] = $fileInfo;
                    // If absolute path flag was passed, store the absolute path.
                    if ($this->absolute) {
                        $f = null;
                        if (!$this->filesOnly) {
                            $f = ($fileInfo->isDir()) ?
                                ($this->path . DIRECTORY_SEPARATOR . $fileInfo->getFilename() . DIRECTORY_SEPARATOR) :
                                ($this->path . DIRECTORY_SEPARATOR . $fileInfo->getFilename());
                        } else if (!$fileInfo->isDir()) {
                            $f = $this->path . DIRECTORY_SEPARATOR . $fileInfo->getFilename();
                        }
                        if (($f !== false) && (null !== $f)) {
                            $this->files[] = $f;
                        }
                    // If relative path flag was passed, store the relative path.
                    } else if ($this->relative) {
                        $f = null;
                        if (!$this->filesOnly) {
                            $f = ($fileInfo->isDir()) ?
                                ($this->path . DIRECTORY_SEPARATOR . $fileInfo->getFilename() . DIRECTORY_SEPARATOR) :
                                ($this->path . DIRECTORY_SEPARATOR . $fileInfo->getFilename());
                        } else if (!$fileInfo->isDir()) {
                            $f = $this->path . DIRECTORY_SEPARATOR . $fileInfo->getFilename();
                        }
                        if (($f !== false) && (null !== $f)) {
                            $this->files[] = substr($f, (strlen(realpath($this->path)) + 1));
                        }
                    // Else, store only the directory or file name.
                    } else {
                        if (!$this->filesOnly) {
                            $this->files[] = ($fileInfo->isDir()) ? ($fileInfo->getFilename()) : $fileInfo->getFilename();
                        } else if (!$fileInfo->isDir()) {
                            $this->files[] = $fileInfo->getFilename();
                        }
                    }
                }
            }
        }
    }
912185
public function commit()
    {
        if (!$this->nested || $this->depth <= 1) {
            parent::commit();
        } else {
            $this->depth--;
        }

        return $this;
    }
444809
protected function assemblePath() {
		$root = $this->isRelative() ? '' : '/';
		
		if ($this->path === null) {
			return $root;
		}
		
		return $root . ltrim($this->path, '/');
	}
908390
public function pwd()
    {
        if ($this->path === null) {
            $this->path = $this->Folder->slashTerm($this->Folder->pwd()) . $this->name;
        }

        return $this->path;
    }
681866
public function asEmbedPath()
    {
        $parent_entity = $this->getParent();
        if (!$parent_entity) {
            return '';
        }

        $path_parts = [];
        $current_entity = $this;
        while ($parent_entity) {
            $parent_attr_name = $current_entity->getType()->getParentAttribute()->getName();
            $path_parts[] = sprintf(
                '%s[%d]',
                $current_entity->getType()->getPrefix(),
                $parent_entity->getValue($parent_attr_name)->getKey($current_entity)
            );
            $path_parts[] = $parent_attr_name;
            if (!$parent_entity->getType()->isRoot()) {
                $path_parts[] = $parent_entity->getType()->getPrefix();
            }
            $current_entity = $parent_entity;
            $parent_entity = $parent_entity->getParent();
        }

        return implode('.', array_reverse($path_parts));
    }
643763
def depth(self):
        
        return len(self.path.rstrip(os.sep).split(os.sep))
1276827
public function getPath()
    {
        if (!$this->_path) {
            $this->_path = $this->detectPath($this->name);
        }

        return $this->_path;
    }
350358
public function getDirOutput() {
        $ds = DIRECTORY_SEPARATOR;
        $id = $this->getId();
        $documentsPath = $this->exporterManager->getOption("documents_path");
        $env = $this->exporterManager->getOption("env");
        if($this->basePath === null){
            $fullPath = $documentsPath.$ds.$env.$ds.$id;
        }else{
            $fullPath = $this->basePath;
        }
        if($this->subPath !== null){
            $fullPath .= $ds.$this->subPath;
        }
        
        if(!$this->exporterManager->getFs()->exists($fullPath)){
            $this->exporterManager->getFs()->mkdir($fullPath);
        }
        return $fullPath;
    }
477084
public function getDepth(): int
    {
        $layerDepth = 0;

        foreach ($this->items as $item) {
            $layerDepth = max($layerDepth, $item->getZ() + $item->getDepth());
        }

        return $layerDepth - $this->getStartDepth();
    }