public function isOffspringOf(Hierarchy $element, LoaderInterface $loader = null)
    {
        if (get_class($element) !== get_class($this))
            return 0;

        $stack = [];
        $parents = $this->getParents($loader);
        foreach ($parents as $p)
            $stack[] = [1, $p];

        $seen = [];
        $level = 0;
        while (!empty($stack))
        {
            list($level, $cur) = array_shift($stack);

            // Avoid infinite cycles
            if (isset($seen[$cur->id]))
                continue;

            // If the ancestor is the requested element, we found our answer
            if ($cur->id === $element->id)
                return $level;

            // Add all parents of this element to the stack
            $parents = $loader === null ? $cur->getParents() : $cur->getParents($loader);
            foreach ($cur->getParents($loader) as $p)
                $stack[] = [$level + 1, $p];

            // Store seen entities to avoid cycles
            $seen[$cur->id] = true;
        }

        // Nothing found
        return 0;
    }