summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/std/README.md1
-rw-r--r--docs/std/queue.md74
-rw-r--r--docs/std/string.md2
3 files changed, 77 insertions, 0 deletions
diff --git a/docs/std/README.md b/docs/std/README.md
index 988440d..f15b67a 100644
--- a/docs/std/README.md
+++ b/docs/std/README.md
@@ -6,5 +6,6 @@
- [Option](./option.md) - Optional values (Some/None).
- [Path](./path.md) - File path manipulation.
- [Result](./result.md) - Error handling (Ok/Err).
+- [Queue](./queue.md) - FIFO queue (Ring Buffer).
- [String](./string.md) - Growable, heap-allocated string type.
- [Vector (Vec)](./vec.md) - A growable dynamic array.
diff --git a/docs/std/queue.md b/docs/std/queue.md
new file mode 100644
index 0000000..d463f15
--- /dev/null
+++ b/docs/std/queue.md
@@ -0,0 +1,74 @@
+# Standard Library: Queue (`std/queue.zc`)
+
+`Queue<T>` is a generic First-In-First-Out (FIFO) queue implemented as a **Ring Buffer (Circular Buffer)**.
+
+## Usage
+
+```zc
+import "std/queue.zc"
+
+fn main() {
+ var q = Queue<int>::new();
+
+ q.push(1);
+ q.push(2);
+ q.push(3);
+
+ // Pop returns an Option<T>
+ if (q.pop().is_some()) {
+ println "Popped: {q.pop().unwrap()}"; // 1
+ }
+}
+```
+
+## Implementation Details
+
+- **Ring Buffer**: Uses a circular buffer with `head` and `tail` indices.
+- **Performance**:
+ - `push`: **Amortized O(1)** (resizes when full).
+ - `pop`: **O(1)** (advances head index).
+ - `clone`: **O(N)**.
+- **Safety**: Safe handling of memory wrapping and resizing.
+
+## Structure
+
+```zc
+struct Queue<T> {
+ data: T*;
+ cap: usize;
+ head: usize;
+ tail: usize;
+ count: usize;
+}
+```
+
+## Methods
+
+### Construction
+
+| Method | Signature | Description |
+| :--- | :--- | :--- |
+| **new** | `Queue<T>::new() -> Queue<T>` | Creates a new, empty queue. |
+| **clone** | `clone(self) -> Queue<T>` | Creates a deep copy of the queue. |
+
+### Modification
+
+| Method | Signature | Description |
+| :--- | :--- | :--- |
+| **push** | `push(self, value: T)` | Adds an element to the back of the queue. |
+| **pop** | `pop(self) -> Option<T>` | Removes and returns the element at the front. Returns `None` if empty. |
+| **clear** | `clear(self)` | Removes all items from the queue. |
+
+### Access / Query
+
+| Method | Signature | Description |
+| :--- | :--- | :--- |
+| **length** | `length(self) -> usize` | Returns the number of items. |
+| **is_empty** | `is_empty(self) -> bool` | Returns `true` if the queue is empty. |
+
+### Memory Management
+
+| Method | Signature | Description |
+| :--- | :--- | :--- |
+| **free** | `free(self)` | Frees the internal buffer. |
+| **Trait** | `impl Drop for Queue` | Automatically calls `free()` when out of scope. |
diff --git a/docs/std/string.md b/docs/std/string.md
index b83ee80..252b737 100644
--- a/docs/std/string.md
+++ b/docs/std/string.md
@@ -72,6 +72,8 @@ These methods handle UTF-8 character boundaries correctly, contrasting with the
| Method | Signature | Description |
| :--- | :--- | :--- |
| **split** | `split(self, delim: char) -> Vec<String>` | Splits the string into a vector of substrings separated by `delim`. |
+| **trim** | `trim(self) -> String` | Returns a new string with leading and trailing whitespace removed. |
+| **replace** | `replace(self, target: char*, replacement: char*) -> String` | Returns a new string with all occurrences of `target` replaced by `replacement`. |
### Comparison