public function build(array $items)
    {
        $this->graph = array(); // Reset all previous data

        foreach ($items as $id => $item) {

            $this->graph[$id]['edges'] = array();

            if (empty($item['dependencies'])) {
                continue;
            }

            foreach ($item['dependencies'] as $did => $ddata) {
                $this->graph[$id]['edges'][$did] = $ddata;
            }
        }

        $this->search();

        foreach ($this->graph as $id => $data) {
            $items[$id]['required_by'] = isset($data['reverse_paths']) ? $data['reverse_paths'] : array();
            $items[$id]['requires'] = isset($data['paths']) ? $data['paths'] : array();
            $items[$id]['sort'] = $data['weight'];
        }

        return $items;
    }