seekWithinPage decides if it should reslice the current page to jump directly to the desired row number or allow the iterator to call Next() until it finds the desired row number. it uses the magicThreshold as its balance point. if the number of Next()s to skip is less than the magicThreshold, it wi
(to RowNumber, definitionLevel int)
| 734 | // or allow the iterator to call Next() until it finds the desired row number. it uses the magicThreshold |
| 735 | // as its balance point. if the number of Next()s to skip is less than the magicThreshold, it will not reslice |
| 736 | func (c *SyncIterator) seekWithinPage(to RowNumber, definitionLevel int) { |
| 737 | rowSkipRelative := int(to[0] - c.curr[0]) |
| 738 | if rowSkipRelative == 0 { |
| 739 | return |
| 740 | } |
| 741 | |
| 742 | const magicThreshold = 1000 |
| 743 | shouldSkip := false |
| 744 | |
| 745 | if definitionLevel == 0 { |
| 746 | // if definition level is 0 there is always a 1:1 ratio between Next()s and rows. it's only deeper |
| 747 | // levels of nesting we have to manually count |
| 748 | shouldSkip = rowSkipRelative > magicThreshold |
| 749 | } else { |
| 750 | // this is a nested iterator, let's count the Next()s required to get to the desired row number |
| 751 | // and decide if we should skip or not |
| 752 | replvls := c.currPage.RepetitionLevels() |
| 753 | nextsRequired := 0 |
| 754 | |
| 755 | for i := c.currPageN; i < len(replvls); i++ { |
| 756 | nextsRequired++ |
| 757 | |
| 758 | if nextsRequired > magicThreshold { |
| 759 | shouldSkip = true |
| 760 | break |
| 761 | } |
| 762 | |
| 763 | if replvls[i] == 0 { // 0 rep lvl indicates a new row |
| 764 | rowSkipRelative-- // decrement the number of rows we need to skip |
| 765 | if rowSkipRelative <= 0 { |
| 766 | // if we hit here we skipped all rows and did not exceed the magic threshold, so we're leaving shouldSkip false |
| 767 | break |
| 768 | } |
| 769 | } |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | if !shouldSkip { |
| 774 | return |
| 775 | } |
| 776 | |
| 777 | // skips are calculated off the start of the page |
| 778 | rowSkip := to[0] - c.currPageMin[0] |
| 779 | if rowSkip < 1 { |
| 780 | return |
| 781 | } |
| 782 | if rowSkip > int32(c.currPage.NumRows()) { |
| 783 | return |
| 784 | } |
| 785 | |
| 786 | // reslice the page to jump directly to the desired row number |
| 787 | pg := c.currPage.Slice(int64(rowSkip-1), c.currPage.NumRows()) |
| 788 | |
| 789 | // remove all detail below the row number |
| 790 | c.curr = TruncateRowNumber(0, to) |
| 791 | c.curr = c.curr.Preceding() |
| 792 | |
| 793 | // reset buffers and other vars |
no test coverage detected