Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C++] Add operator--() to RunEndEncodedArraySpan::Iterator and make it stop violating loop invariants #34893

Closed
felipecrv opened this issue Apr 4, 2023 · 1 comment · Fixed by #34896

Comments

@felipecrv
Copy link
Contributor

Describe the enhancement requested

The value of RunEndEncodedArraySpan::Iterator::physical_pos_ from the instance returned by RunEndEncodedArraySpan::end() is smaller (by 1) than the results of successive applications of operator++ until logical_pos_ reaches the logical length of the run-end encoded array.

Why this is important?

To support backwards iteration, the Iterator returned by RunEndEncodedArraySpan::end() should be well-formed.

Why this is not a bug?

There is no operator--() in RunEndEncodedArraySpan::Iterator yet, so you can't go backwards from end(). A fix for this issue adds that operator and uses it in tests that guarantee iterators are always valid and don't assume iteration only happens in one direction.

Component(s)

C++

@felipecrv
Copy link
Contributor Author

take

zeroshade pushed a commit that referenced this issue Apr 12, 2023
…st on backwards iteration (#34896)

### Rationale for this change

The value of `RunEndEncodedArraySpan::Iterator::physical_pos_` from the instance returned by `RunEndEncodedArraySpan::end()` is smaller (by 1) than the results of successive applications of `operator++()` until `logical_pos_` reaches the logical length of the run-end encoded array.

To support backwards iteration, the `Iterator` returned by `RunEndEncodedArraySpan::end()` should be well-formed.

There was no `operator--()` in `RunEndEncodedArraySpan::Iterator` before this PR, so one can't go backwards from `end()` and this latent bug doesn't manifest. 

### What changes are included in this PR?

 - Addition of `RunEndEncodedArraySpan::Iterator::operator--()`
 - Addition of `MergedRunsIterator::operator--()`
 - Rename `isEnd()` to `is_end()` (it was a code-style violation)
 - More test cases

### Are these changes tested?

By existing and new unit tests.

### Are there any user-facing changes?

A public function -- `isEnd` -- was renamed, but this code hasn't been released yet, so it's OK.
* Closes: #34893

Authored-by: Felipe Oliveira Carvalho <felipekde@gmail.com>
Signed-off-by: Matt Topol <zotthewizard@gmail.com>
@zeroshade zeroshade added this to the 12.0.0 milestone Apr 12, 2023
liujiacheng777 pushed a commit to LoongArch-Python/arrow that referenced this issue May 11, 2023
…manifest on backwards iteration (apache#34896)

### Rationale for this change

The value of `RunEndEncodedArraySpan::Iterator::physical_pos_` from the instance returned by `RunEndEncodedArraySpan::end()` is smaller (by 1) than the results of successive applications of `operator++()` until `logical_pos_` reaches the logical length of the run-end encoded array.

To support backwards iteration, the `Iterator` returned by `RunEndEncodedArraySpan::end()` should be well-formed.

There was no `operator--()` in `RunEndEncodedArraySpan::Iterator` before this PR, so one can't go backwards from `end()` and this latent bug doesn't manifest. 

### What changes are included in this PR?

 - Addition of `RunEndEncodedArraySpan::Iterator::operator--()`
 - Addition of `MergedRunsIterator::operator--()`
 - Rename `isEnd()` to `is_end()` (it was a code-style violation)
 - More test cases

### Are these changes tested?

By existing and new unit tests.

### Are there any user-facing changes?

A public function -- `isEnd` -- was renamed, but this code hasn't been released yet, so it's OK.
* Closes: apache#34893

Authored-by: Felipe Oliveira Carvalho <felipekde@gmail.com>
Signed-off-by: Matt Topol <zotthewizard@gmail.com>
ArgusLi pushed a commit to Bit-Quill/arrow that referenced this issue May 15, 2023
…manifest on backwards iteration (apache#34896)

### Rationale for this change

The value of `RunEndEncodedArraySpan::Iterator::physical_pos_` from the instance returned by `RunEndEncodedArraySpan::end()` is smaller (by 1) than the results of successive applications of `operator++()` until `logical_pos_` reaches the logical length of the run-end encoded array.

To support backwards iteration, the `Iterator` returned by `RunEndEncodedArraySpan::end()` should be well-formed.

There was no `operator--()` in `RunEndEncodedArraySpan::Iterator` before this PR, so one can't go backwards from `end()` and this latent bug doesn't manifest. 

### What changes are included in this PR?

 - Addition of `RunEndEncodedArraySpan::Iterator::operator--()`
 - Addition of `MergedRunsIterator::operator--()`
 - Rename `isEnd()` to `is_end()` (it was a code-style violation)
 - More test cases

### Are these changes tested?

By existing and new unit tests.

### Are there any user-facing changes?

A public function -- `isEnd` -- was renamed, but this code hasn't been released yet, so it's OK.
* Closes: apache#34893

Authored-by: Felipe Oliveira Carvalho <felipekde@gmail.com>
Signed-off-by: Matt Topol <zotthewizard@gmail.com>
rtpsw pushed a commit to rtpsw/arrow that referenced this issue May 16, 2023
…manifest on backwards iteration (apache#34896)

### Rationale for this change

The value of `RunEndEncodedArraySpan::Iterator::physical_pos_` from the instance returned by `RunEndEncodedArraySpan::end()` is smaller (by 1) than the results of successive applications of `operator++()` until `logical_pos_` reaches the logical length of the run-end encoded array.

To support backwards iteration, the `Iterator` returned by `RunEndEncodedArraySpan::end()` should be well-formed.

There was no `operator--()` in `RunEndEncodedArraySpan::Iterator` before this PR, so one can't go backwards from `end()` and this latent bug doesn't manifest. 

### What changes are included in this PR?

 - Addition of `RunEndEncodedArraySpan::Iterator::operator--()`
 - Addition of `MergedRunsIterator::operator--()`
 - Rename `isEnd()` to `is_end()` (it was a code-style violation)
 - More test cases

### Are these changes tested?

By existing and new unit tests.

### Are there any user-facing changes?

A public function -- `isEnd` -- was renamed, but this code hasn't been released yet, so it's OK.
* Closes: apache#34893

Authored-by: Felipe Oliveira Carvalho <felipekde@gmail.com>
Signed-off-by: Matt Topol <zotthewizard@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants