Repository navigation
Let generate_binary_search take frame numbers in any order - #947
Merged
Merged
Conversation
generate_binary_search assumed its frame numbers were sorted, and silently missed frames when they were not: [3, 1] selected only frame 1, and [10, 2, 7] missed frame 10. It now takes any iterable of frame numbers, in any order and with repeats, and sorts and de-duplicates them once. The recursion, which still assumes sorted, distinct frame numbers, moves into _binary_search. extract_specified_frames, the only caller, already sorted its set, and now passes the set directly. The expression for sorted, distinct frame numbers is unchanged byte for byte, so the same frames are extracted.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
FFMPEG.generate_binary_searchassumed its frame numbers were sorted, and silently missed frames when they were not:[3, 1]selected only frame 1 (if(lt(n\,1)\,eq(n\,3)\,eq(n\,1))), and[10, 2, 7]missed frame 10.This makes it take any iterable of frame numbers, in any order and with repeats:
generate_binary_searchsorts and de-duplicates them once (sorted(set(...)))._binary_search, which assumes sorted, distinct frame numbers.extract_specified_frames, the only caller, already sorted its set, and now passes the set directly.The expression for sorted, distinct frame numbers is unchanged byte for byte, so the same frames are extracted as before (checked on 240 random sets of 0 to 28,147 frames, given as a sorted list and as a set).
Tests:
rangeand a 22-frame list), and checks that it selects exactly the right frames and equals the expression for the sorted frames. All 6 cases fail on main.