Skip to content

Allow degenerate 0-length case#24

Merged
fhunleth merged 1 commit into
mainfrom
zero-length
Jul 19, 2026
Merged

Allow degenerate 0-length case#24
fhunleth merged 1 commit into
mainfrom
zero-length

Conversation

@fhunleth

Copy link
Copy Markdown
Collaborator

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 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.
@fhunleth
fhunleth merged commit a45135a into main Jul 19, 2026
14 checks passed
@fhunleth
fhunleth deleted the zero-length branch July 19, 2026 13:44
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.

1 participant