Skip to content

Feat : Implement Circular Buffer (Ring Buffer) Data Structure #669

Open
@frHimanshu

Description

@frHimanshu

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:

  1. Fixed Size: The buffer has a fixed size and overwrites the oldest data when it becomes full.
  2. Efficient Operations: Provides constant time complexity for adding and removing elements.
  3. 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:

  1. Initialization: Allocate a fixed-size buffer and initialize pointers.
  2. Enqueue: Add an element to the buffer.Dequeue: Remove an element from the buffer.
  3. Is Full: Check if the buffer is full.
  4. Is Empty: Check if the buffer is empty.
  5. Peek: View the element at the front of the buffer without removing it.
  6. 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:

  1. Create a new file named circular_buffer.py in the pydatastructs/linear_data_structures/ directory.
  2. Implement the CircularBuffer class as described above.
  3. Add appropriate docstrings and comments to explain the code.
  4. Write unit tests for the CircularBuffer class and place them in the tests/ directory, following the structure of existing test files.
  5. 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions