Skip to content
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

Add an array-based bounded queue #8

Open
9 tasks
mwermelinger opened this issue Jan 6, 2024 · 0 comments
Open
9 tasks

Add an array-based bounded queue #8

mwermelinger opened this issue Jan 6, 2024 · 0 comments
Labels
effort: medium These issues require some work priority: low type: enhancement Improve an existing feature

Comments

@mwermelinger
Copy link
Member

A bounded queue has a fixed capacity (maximum number of members). When the capacity is reached, the queue is full and no further items can be enqueued. A bounded queue can be implemented with a .

In file queue.py:

  • Create a class StaticArrayQueue as a copy of LinkedListQueue.
  • Add the new class to the __all__ list.
  • Update the docstring of the new class, including the doctest.
  • In method __init__, add an integer parameter capacity. Raise ValueError if capacity is negative or smaller than the length of parameter sequence. Update the class's doctest to use this parameter.
  • Change the implementation of all methods to use a static array (fixed-length Python list) as circular buffer instead of a linked list.
  • Add a new method capacity that returns the fixed length of the array. Use this method in the doctest.
  • Change method enqueue to raise ValueError when the stack is full. Update the docstring accordingly.

In file tests/test_queue.py:

  • Add StaticArrayQueue to the import statement (line 7), the type definition (line 11) and the Queue fixture (line 27)
  • Betweentest_enqueue and test_dequeue, add a function test_enqueue_full(sequence: Sequence) that tests that enqueuing doesn't change the queue's capacity and that ValueError is raised when enqueuing on a full queue. (See the check_is_empty function for how to do that.)
@mwermelinger mwermelinger added effort: medium These issues require some work priority: low type: enhancement Improve an existing feature labels Jan 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort: medium These issues require some work priority: low type: enhancement Improve an existing feature
Projects
None yet
Development

No branches or pull requests

1 participant