Skip to content

Clarification of indices in documentation #13

Description

@joe-saronic

The use of indices in the documentation (e.g., get) shows under-filled buffers, where the index in the view and the underlying buffer match. A couple of examples of how the index behaves in case of an overfilled buffer would be useful.

For example, given

use circular_buffer::CircularBuffer;

let mut buf = CircularBuffer::<3, char>::new();
buf.push_back('a');
buf.push_back('b');
buf.push_back('c');
buf.push_back('d');

Which of the following is correct?

assert_eq!(buf.get(0), Some(&'d'));

OR

assert_eq!(buf.get(0), Some(&'b'));

In the first case, the index is static relative to the underlying memory, which can be convenient. In the latter, the index of an element changes every time something is appended to the buffer. A corrolary of the former would be that it would be nice to have access to the index of the front and back. I would be happy to make a PR for some getters if this turns out to be the case.

The usecase I have in mind is that I want to buffer some data and grab some items that I've flagged in the past (that are still definitely within the buffer).

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions