| 119 | } |
| 120 | |
| 121 | tree_node::types::Ptrs<HierarchyEntry> LoadHierachy(std::string const & filename) |
| 122 | { |
| 123 | ankerl::unordered_dense::map<CompositeId, tree_node::types::Ptr<HierarchyEntry>> nodes; |
| 124 | for (auto const & row : coding::CSVRunner(coding::CSVReader(filename, false /* hasHeader */, kCsvDelimiter))) |
| 125 | { |
| 126 | auto entry = HierarchyEntryFromCsvRow(row); |
| 127 | auto const id = entry.m_id; |
| 128 | nodes.emplace(id, tree_node::MakeTreeNode(std::move(entry))); |
| 129 | } |
| 130 | for (auto const & pair : nodes) |
| 131 | { |
| 132 | auto const & node = pair.second; |
| 133 | auto const parentIdOpt = node->GetData().m_parentId; |
| 134 | if (parentIdOpt) |
| 135 | { |
| 136 | auto const it = nodes.find(*parentIdOpt); |
| 137 | CHECK(it != std::cend(nodes), (*it)); |
| 138 | tree_node::Link(node, it->second); |
| 139 | } |
| 140 | } |
| 141 | std::vector<tree_node::types::Ptr<HierarchyEntry>> trees; |
| 142 | base::Transform(nodes, std::back_inserter(trees), base::RetrieveSecond()); |
| 143 | base::EraseIf(trees, [](auto const & node) { return node->HasParent(); }); |
| 144 | return trees; |
| 145 | } |
| 146 | } // namespace hierarchy |
| 147 | } // namespace generator |