| 409 | |
| 410 | template <typename T> |
| 411 | void ShapeTree<T>::InitChildren(const Shape& shape, const T& init_value, |
| 412 | Node* node, Index* index) { |
| 413 | if (shape.IsTuple()) { |
| 414 | const int64 size = ShapeUtil::TupleElementCount(shape); |
| 415 | #ifndef NDEBUG |
| 416 | index->children_count = size; |
| 417 | #endif |
| 418 | node->is_leaf = false; |
| 419 | ShapeIndex shape_index = node->data.first; |
| 420 | shape_index.push_back(0); |
| 421 | |
| 422 | // At the end of the index_table, reserve a continuous space to hold the |
| 423 | // children of current node. In order to enforce the invariant that all |
| 424 | // children of a given node are placed together, we need to do the |
| 425 | // reservation before we recurse into any of its children. |
| 426 | int64 children_start_position = index_table_.size(); |
| 427 | index_table_.resize(index_table_.size() + size); |
| 428 | |
| 429 | for (int i = 0; i < size; ++i) { |
| 430 | shape_index[shape_index.size() - 1] = i; |
| 431 | index_table_[children_start_position + i].index = nodes_.size(); |
| 432 | // The first child of the node in the index table is placed at the end of |
| 433 | // the table. |
| 434 | index_table_[children_start_position + i].children_start = |
| 435 | index_table_.size(); |
| 436 | nodes_.emplace_back(shape_index, init_value); |
| 437 | InitChildren(shape.tuple_shapes(i), init_value, &nodes_.back(), |
| 438 | &index_table_[children_start_position + i]); |
| 439 | } |
| 440 | } else { |
| 441 | #ifndef NDEBUG |
| 442 | index->children_count = 0; |
| 443 | #endif |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | template <typename T> |
| 448 | void ShapeTree<T>::InitChildren(const Shape& shape, Node* node, Index* index) { |
nothing calls this directly
no test coverage detected