protected function buildNodeDependencies(array $nodes)
    {
        $this->nodesByPath = [];
        $this->nodesByNodeData = [];
        $this->dependenciesOutgoing = [];
        $this->dependenciesIncoming = [];
        $this->nodesWithoutIncoming = [];

        /** @var Node $node */
        foreach ($nodes as $node) {
            $this->nodesByPath[$node->getPath()][] = $node;
            $this->nodesByNodeData[spl_object_hash($node->getNodeData())] = $node;
            $this->nodesWithoutIncoming[spl_object_hash($node)] = $node;
        }

        /** @var Node $node */
        foreach ($nodes as $node) {
            $nodeHash = spl_object_hash($node);

            // Add dependencies for (direct) parents, this will also cover moved and created nodes
            if (isset($this->nodesByPath[$node->getParentPath()])) {
                /** @var Node $parentNode */
                foreach ($this->nodesByPath[$node->getParentPath()] as $parentNode) {
                    $dependencyHash = spl_object_hash($parentNode);
                    $this->dependenciesIncoming[$nodeHash][$dependencyHash] = $parentNode;
                    $this->dependenciesOutgoing[$dependencyHash][$nodeHash] = $node;
                    unset($this->nodesWithoutIncoming[$nodeHash]);
                }
            }

            // Add a dependency for a moved-to reference
            $movedToNodeData = $node->getNodeData()->getMovedTo();
            if ($movedToNodeData !== null) {
                $movedToHash = spl_object_hash($movedToNodeData);
                if (!isset($this->nodesByNodeData[$movedToHash])) {
                    throw new WorkspaceException('Cannot publish a list of nodes with missing dependency (' . $node->getPath() . ' needs ' . $movedToNodeData->getPath() . ' to be published)', 1416483470);
                }
                $dependencyHash = spl_object_hash($this->nodesByNodeData[$movedToHash]);
                $this->dependenciesIncoming[$nodeHash][$dependencyHash] = $this->nodesByNodeData[$movedToHash];
                $this->dependenciesOutgoing[$dependencyHash][$nodeHash] = $node;
                unset($this->nodesWithoutIncoming[$nodeHash]);
            }
        }
    }