|
1 | 1 | # Containers-Queue |
| 2 | +A High-performance, Circular Array based Queue implementation providing efficient FIFO (First In, First Out) operations with dynamic capacity and proper error handling. |
2 | 3 |
|
3 | | -[](https://travis-ci.com/pharo-containers/Containers-Queue) |
4 | | -[]() |
5 | | -[](https://pharo.org/download) |
6 | | -[](https://pharo.org/download) |
| 4 | + |
| 5 | +[](LICENSE) |
7 | 6 |
|
8 | | -A queue support FIFO (first in first out) behavior. Now it is a bit limited so feel free to enhance it. |
| 7 | +## What is a Queue? |
9 | 8 |
|
10 | | -This package is part of the Containers project: This project is to collect, clean, |
11 | | -test and document alternate collection datastructures. Each package is modular so that users |
12 | | -can only load the collection they need without 100 of related collections. |
| 9 | +A Queue is a linear data structure that follows the FIFO (First In, First Out) principle. Elements are added at the rear (enqueue) and removed from the front (dequeue). Think of it like a line at a store - the first person in line is the first person served. |
13 | 10 |
|
14 | | -## Example |
| 11 | +### Key Benefits |
| 12 | +- **O(1) Performance**: Constant time enqueue, dequeue, and front operations |
| 13 | +- **Dynamic Growth**: Circular array implementation that doubles capacity when needed |
| 14 | +- **Memory Safe**: Automatic cleanup prevents memory leaks |
| 15 | +- **Simple API**: Clean, intuitive interface following standard queue conventions |
| 16 | +- **Robust Error Handling**: Proper empty queue protection with clear error messages |
15 | 17 |
|
16 | | -```smalltalk |
17 | | -CTEnvironmentTest >> testDequeue [ |
18 | | -
|
19 | | - | queue | |
20 | | - queue := CTQueue new. |
21 | | - queue queue: 1. |
22 | | - queue queue: 2. |
23 | | - queue queue: 3. |
24 | | - self assert: queue dequeue equals: 1. |
25 | | - self assert: queue dequeue equals: 2. |
26 | | -] |
27 | | -``` |
28 | | - |
29 | | -## Loading |
| 18 | +## Loading |
| 19 | +The following script installs Containers-Queue in Pharo. |
30 | 20 |
|
31 | 21 | ```smalltalk |
32 | 22 | Metacello new |
33 | | - baseline: 'ContainersQueue'; |
34 | | - repository: 'github://pharo-containers/Containers-Queue/'; |
35 | | - load. |
| 23 | + baseline: 'ContainersQueue'; |
| 24 | + repository: 'github://pharo-containers/Containers-Queue/src'; |
| 25 | + load. |
36 | 26 | ``` |
37 | 27 |
|
38 | | -## If you want to depend on it |
| 28 | +## If you want to depend on it |
| 29 | + |
| 30 | +Add the following code to your Metacello baseline or configuration |
39 | 31 |
|
40 | 32 | ```smalltalk |
41 | 33 | spec |
42 | 34 | baseline: 'ContainersQueue' |
43 | 35 | with: [ spec repository: 'github://pharo-containers/Containers-Queue/src' ]. |
44 | 36 | ``` |
45 | 37 |
|
| 38 | +## Quick Start |
| 39 | + |
| 40 | +```smalltalk |
| 41 | +"Create a queue with default capacity of 10" |
| 42 | +queue := CTQueue new. |
| 43 | +
|
| 44 | +"Enqueue elements" |
| 45 | +queue enqueue: 'first'. |
| 46 | +queue enqueue: 'second'. |
| 47 | +queue enqueue: 'third'. |
| 48 | +
|
| 49 | +"Check front element without removing" |
| 50 | +queue front. "Returns 'first'" |
| 51 | +queue size. "Returns 3" |
| 52 | +
|
| 53 | +"Dequeue elements (FIFO order)" |
| 54 | +queue dequeue. "Returns 'first'" |
| 55 | +queue dequeue. "Returns 'second'" |
| 56 | +queue dequeue. "Returns 'third'" |
| 57 | +
|
| 58 | +"Queue is now empty" |
| 59 | +queue isEmpty. "Returns true" |
| 60 | +``` |
| 61 | + |
| 62 | +## Contributing |
46 | 63 |
|
47 | | ----- |
48 | | -The best way to predict the future is to do it! |
49 | | -Less talking more doing. stephane.ducasse@inria.fr |
| 64 | +This is part of the Pharo Containers project. Feel free to contribute by implementing additional methods, improving tests, or enhancing documentation. |
0 commit comments