philiprehberger-queue_stack 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +8 -3
- data/lib/philiprehberger/queue_stack/queue.rb +12 -0
- data/lib/philiprehberger/queue_stack/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8f720c2ee97526d57826cb37fba4be96e6e1143879b7627a2792cef97ffaa1dc
|
|
4
|
+
data.tar.gz: 311fdae1a3eb9f31d27f4ef77006eae1f224050418ac97721540d761ac081ac0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fd4c5bc553fde4d2278b2efa422ed0c4c67aaf63d9c5bc049bce395066ab544533bf2b11696a564769cbd6dbdd900a4c802a12abec032d888d17c0d0d5d0dc36
|
|
7
|
+
data.tar.gz: aa1cc6ea3d889cde7c372943df2bb9b5c46d0f87f3e628659e01ebbbf3697a8ce548f41c36508a3f82af14818ca0bd852da74aa577e13abf29899f1b60e6a162
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.4.0] - 2026-04-15
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `Queue#peek_at(index)` returns the item at the given position without removing it, supporting negative indices like `Array#[]` and returning `nil` when out of range
|
|
14
|
+
|
|
10
15
|
## [0.3.0] - 2026-04-09
|
|
11
16
|
|
|
12
17
|
### Added
|
data/README.md
CHANGED
|
@@ -40,9 +40,13 @@ item = q.dequeue # => 'task'
|
|
|
40
40
|
q = Philiprehberger::QueueStack::Queue.new(capacity: 10)
|
|
41
41
|
q.enqueue('first')
|
|
42
42
|
q.enqueue('second')
|
|
43
|
-
q.
|
|
44
|
-
q.peek
|
|
45
|
-
q.
|
|
43
|
+
q.enqueue('third')
|
|
44
|
+
q.peek # => 'first'
|
|
45
|
+
q.peek_at(1) # => 'second'
|
|
46
|
+
q.peek_at(-1) # => 'third'
|
|
47
|
+
q.peek_at(99) # => nil (out of range)
|
|
48
|
+
q.dequeue # => 'first'
|
|
49
|
+
q.size # => 2
|
|
46
50
|
```
|
|
47
51
|
|
|
48
52
|
### Stack (LIFO)
|
|
@@ -149,6 +153,7 @@ q.full? # => true
|
|
|
149
153
|
| `#try_dequeue(timeout:)` | Dequeue with timeout, returns nil on timeout |
|
|
150
154
|
| `#clear` | Remove all items without returning them |
|
|
151
155
|
| `#peek` | View front item without removing |
|
|
156
|
+
| `#peek_at(index)` | View item at the given position (supports negative indices, returns nil if out of range) |
|
|
152
157
|
| `#drain` | Remove and return all items as array (FIFO order) |
|
|
153
158
|
| `#each` | Iterate items without removing (returns Enumerator if no block) |
|
|
154
159
|
| `#to_a` | Snapshot as array (FIFO order) |
|
|
@@ -175,6 +175,18 @@ module Philiprehberger
|
|
|
175
175
|
@mutex.synchronize { @items.first }
|
|
176
176
|
end
|
|
177
177
|
|
|
178
|
+
# Peek at the item at the given position without removing it.
|
|
179
|
+
#
|
|
180
|
+
# Indexing follows +Array#[]+ semantics: +0+ is the front of the queue,
|
|
181
|
+
# +size - 1+ is the back, and negative indices count from the back
|
|
182
|
+
# (+-1+ is the last item). Returns +nil+ when the index is out of range.
|
|
183
|
+
#
|
|
184
|
+
# @param index [Integer] position in the queue (supports negative indices)
|
|
185
|
+
# @return [Object, nil] the item at the position or nil if out of range
|
|
186
|
+
def peek_at(index)
|
|
187
|
+
@mutex.synchronize { @items[index] }
|
|
188
|
+
end
|
|
189
|
+
|
|
178
190
|
# Return the number of items in the queue.
|
|
179
191
|
#
|
|
180
192
|
# @return [Integer]
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-queue_stack
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Philip Rehberger
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-04-
|
|
11
|
+
date: 2026-04-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Thread-safe queue and stack data structures with configurable capacity
|
|
14
14
|
limits, blocking enqueue/dequeue with timeouts, and peek operations. Uses Mutex
|