| 328 | int16_t rep_level() const { return rep_level_; } |
| 329 | |
| 330 | IterationResult Run(ElementRange* range, ElementRange* child_range, |
| 331 | PathWriteContext* context) { |
| 332 | if (range->Empty()) { |
| 333 | return kDone; |
| 334 | } |
| 335 | // Find the first non-empty list (skipping a run of empties). |
| 336 | int64_t empty_elements = 0; |
| 337 | do { |
| 338 | // Retrieve the range of elements that this list contains. |
| 339 | *child_range = selector_.GetRange(range->start); |
| 340 | if (!child_range->Empty()) { |
| 341 | break; |
| 342 | } |
| 343 | ++empty_elements; |
| 344 | ++range->start; |
| 345 | } while (!range->Empty()); |
| 346 | |
| 347 | // Post condition: |
| 348 | // * range is either empty (we are done processing at this node) |
| 349 | // or start corresponds a non-empty list. |
| 350 | // * If range is non-empty child_range contains |
| 351 | // the bounds of non-empty list. |
| 352 | |
| 353 | // Handle any skipped over empty lists. |
| 354 | if (empty_elements > 0) { |
| 355 | RETURN_IF_ERROR(FillRepLevels(empty_elements, prev_rep_level_, context)); |
| 356 | RETURN_IF_ERROR(context->AppendDefLevels(empty_elements, def_level_if_empty_)); |
| 357 | } |
| 358 | // Start of a new list. Note that for nested lists adding the element |
| 359 | // here effectively suppresses this code until we either encounter null |
| 360 | // elements or empty lists between here and the innermost list (since |
| 361 | // we make the rep levels repetition and definition levels unequal). |
| 362 | // Similarly when we are backtracking up the stack the repetition and |
| 363 | // definition levels are again equal so if we encounter an intermediate list |
| 364 | // with more elements this will detect it as a new list. |
| 365 | if (context->EqualRepDefLevelsLengths() && !range->Empty()) { |
| 366 | RETURN_IF_ERROR(context->AppendRepLevel(prev_rep_level_)); |
| 367 | } |
| 368 | |
| 369 | if (range->Empty()) { |
| 370 | return kDone; |
| 371 | } |
| 372 | |
| 373 | ++range->start; |
| 374 | if (is_last_) { |
| 375 | // If this is the last repeated node, we can extend try |
| 376 | // to extend the child range as wide as possible before |
| 377 | // continuing to the next node. |
| 378 | return FillForLast(range, child_range, context); |
| 379 | } |
| 380 | return kNext; |
| 381 | } |
| 382 | |
| 383 | void SetLast() { is_last_ = true; } |
| 384 |
no test coverage detected