| 677 | } |
| 678 | |
| 679 | void InsertNode(const Model& model, const string& array_id, Node* node, |
| 680 | std::vector<string> prefixes, int64* math_ops) { |
| 681 | if (prefixes.empty()) { |
| 682 | // Base case: store array in this node. |
| 683 | node->array_id = array_id; |
| 684 | *math_ops = GetArithmeticOpsCount(model, array_id); |
| 685 | } else { |
| 686 | // Insert into the sub-tree for that prefix. |
| 687 | string prefix = prefixes.back(); |
| 688 | prefixes.pop_back(); |
| 689 | if (node->children.count(prefix) == 0) { |
| 690 | // Create a new node if this prefix is unseen. |
| 691 | node->children[prefix] = absl::make_unique<Node>(); |
| 692 | } |
| 693 | InsertNode(model, array_id, node->children[prefix].get(), prefixes, |
| 694 | math_ops); |
| 695 | } |
| 696 | // Sum estimated math ops into all nodes. |
| 697 | node->math_ops += *math_ops; |
| 698 | } |
| 699 | |
| 700 | void BuildArrayTree(const Model& model, Node* tree) { |
| 701 | // Delimit array names by path "/", then place into a tree based on this path. |
no test coverage detected