Skip to content

circular-buffer: Clarify overwrite #892

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

Merged
merged 2 commits into from
Sep 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions exercises/circular-buffer/canonical-data.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"exercise": "circular-buffer",
"version": "1.0.0",
"version": "1.0.1",
"comments": [
"In general, these circular buffers are expected to be stateful,",
"and each language will operate on them differently.",
Expand All @@ -13,7 +13,7 @@
" If it should succeed, it should produce the item at `expected`. ",
" If it should fail, `expected` will not be present. ",
"write: Writing the item located at `item` should succeed if and only if `should_succeed` is true.",
"overwrite: Write the item located at `item` into the buffer, removing the oldest item if necessary.",
"overwrite: Write the item located at `item` into the buffer, replacing the oldest item if necessary.",
"clear: Clear the buffer.",
"",
"Failure of either `read` or `write` may be indicated in a manner appropriate for your language:",
Expand Down Expand Up @@ -273,7 +273,7 @@
]
},
{
"description": "overwrite removes the oldest item on full buffer",
"description": "overwrite replaces the oldest item on full buffer",
"property": "run",
"capacity": 2,
"operations": [
Expand Down Expand Up @@ -304,7 +304,7 @@
]
},
{
"description": "overwrite doesn't remove an already-read item",
"description": "overwrite replaces the oldest item remaining in buffer following a read",
"property": "run",
"capacity": 3,
"operations": [
Expand Down
19 changes: 13 additions & 6 deletions exercises/circular-buffer/description.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,21 @@ If the buffer has 7 elements then it is completely full:
When the buffer is full an error will be raised, alerting the client
that further writes are blocked until a slot becomes free.

The client can opt to overwrite the oldest data with a forced write. In
this case, two more elements — A & B — are added and they overwrite the
3 & 4:
When the buffer is full, the client can opt to overwrite the oldest
data with a forced write. In this case, two more elements — A & B —
are added and they overwrite the 3 & 4:

[6][7][8][9][A][B][5]

Finally, if two elements are now removed then what would be returned is
not 3 & 4 but 5 & 6 because A & B overwrote the 3 & the 4 yielding the
buffer with:
3 & 4 have been replaced by A & B making 5 now the oldest data in the
buffer. Finally, if two elements are removed then what would be
returned is 5 & 6 yielding the buffer:

[ ][7][8][9][A][B][ ]

Because there is space available, if the client again uses overwrite
to store C & D then the space where 5 & 6 were stored previously will
be used not the location of 7 & 8. 7 is still the oldest element and
the buffer is once again full.

[D][7][8][9][A][B][C]