Skip to content

Take the next sorted value above the one the block of Fbe.iterate returns - #1334

Open
Thayorns wants to merge 1 commit into
zerocracy:masterfrom
Thayorns:1248
Open

Thayorns wants to merge 1 commit into
zerocracy:masterfrom
Thayorns:1248

Conversation

@Thayorns

Copy link
Copy Markdown
Contributor

With sort_by, Fbe::Iterate#over built the sorted list of values once per repository and walked it with .next, so the value the block returned was never used as the next $before. With facts n from 1 to 6 and a block that returns n + 2, a plain query visited 1 and 4 and stored 6, while sort_by visited all six and stored 8, which it had never processed.

The sorted list is now kept as an array, and each step takes the first value above the current $before with bsearch. The first step starts from the stored marker, as before, and every later one starts from what the block returned, which is the contract the docs of over describe. The StopIteration rescue is gone, since bsearch simply gives nil when nothing is left, and that already restarts the repository.

The tests check the visited values and the stored marker for the case from the issue, and that sort_by and a plain (min n) query visit the same values for the same block, as settled in #826.

Closes #1248

@Thayorns

Copy link
Copy Markdown
Contributor Author

@yegor256 take a look please, happy to clarify anything about the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fbe.iterate with sort_by ignores the value the block returns and keeps yielding values it asked to skip

1 participant