Open
Description
Implement a Circular Buffer (Ring Buffer) data structure in the pydatastructs library. A circular buffer is a fixed-size data structure that uses a single, fixed-size buffer as if it were connected end-to-end, providing efficient management of cyclic data.
Features:
- Fixed Size: The buffer has a fixed size and overwrites the oldest data when it becomes full.
- Efficient Operations: Provides constant time complexity for adding and removing elements.
- Wrap-Around: When the end of the buffer is reached, the next element is inserted at the beginning of the buffer (wrap-around behavior).
Methods to Implement:
- Initialization: Allocate a fixed-size buffer and initialize pointers.
- Enqueue: Add an element to the buffer.Dequeue: Remove an element from the buffer.
- Is Full: Check if the buffer is full.
- Is Empty: Check if the buffer is empty.
- Peek: View the element at the front of the buffer without removing it.
- Size: Get the number of elements currently in the buffer.
File Placement:
File Name: circular_buffer.py
File Location: pydatastructs/linear_data_structures/
Instructions for Adding the File:
- Create a new file named circular_buffer.py in the pydatastructs/linear_data_structures/ directory.
- Implement the CircularBuffer class as described above.
- Add appropriate docstrings and comments to explain the code.
- Write unit tests for the CircularBuffer class and place them in the tests/ directory, following the structure of existing test files.
- This feature will provide a useful data structure for managing cyclic data efficiently and will be a valuable addition to the pydatastructs library.
Metadata
Metadata
Assignees
Labels
No labels