Allow degenerate 0-length case#24
Merged
Merged
Conversation
This comes up when code using CircularBuffer accumulate changes to an entry before putting it into the buffer. For this case, the CircularBuffer is allocated with n-1 entries. The entry accumulating changes gets committed to the CircularBuffer and then a new entry is started. This means that there are a max of n entries each time. The edge case is when n=1. When that happens, special case code needed to be added since CircularBuffers couldn't be length 0. Supporting length 0 gets rid of that special case code. The effect to the CircularBuffer implementation is to add an empty buffer check whenever it's time to reload the b list. This happens once every n insertions where n is the length of the CircularBuffer, so in addition to being a simple check, it's also not even run that often. Property tests that didn't require at least one element in the buffer were updated to exercise the 0-length case.
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.
This comes up when code using CircularBuffer accumulate changes to an
entry before putting it into the buffer. For this case, the
CircularBuffer is allocated with n-1 entries. The entry accumulating
changes gets committed to the CircularBuffer and then a new entry is
started. This means that there are a max of n entries each time. The
edge case is when n=1. When that happens, special case code needed to be
added since CircularBuffers couldn't be length 0. Supporting length 0
gets rid of that special case code.
The effect to the CircularBuffer implementation is to add an empty
buffer check whenever it's time to reload the b list. This happens once
every n insertions where n is the length of the CircularBuffer, so in
addition to being a simple check, it's also not even run that often.
Property tests that didn't require at least one element in the buffer
were updated to exercise the 0-length case.