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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61b9b755594ffadcc05a80b942c0424a29043da9e01c81bc41045c5d440156e1
4
- data.tar.gz: 823d4982ec931ecf197a42e37ceb7439939a4e6e06070d22ceb437eb1985f2e4
3
+ metadata.gz: 8f720c2ee97526d57826cb37fba4be96e6e1143879b7627a2792cef97ffaa1dc
4
+ data.tar.gz: 311fdae1a3eb9f31d27f4ef77006eae1f224050418ac97721540d761ac081ac0
5
5
  SHA512:
6
- metadata.gz: 0c2f235cd8a6f31bafd5d94af63806e3caabc0fff8743b82815ff90df255f74dbf6d924edccb57e5d73f0fef65958b1c7231e60e96bc9dde9aee3e94718ce0fd
7
- data.tar.gz: 35d25847836f39bbd80fd7aa8ff07005c126cec030be1d1e9908a4d428d8f96cf2b662167cce8428314aefd7a1ce2384179dd8489e132f1635333e2ffd1dec48
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.dequeue # => 'first'
44
- q.peek # => 'second'
45
- q.size # => 1
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]
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Philiprehberger
4
4
  module QueueStack
5
- VERSION = '0.3.0'
5
+ VERSION = '0.4.0'
6
6
  end
7
7
  end
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.3.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-09 00:00:00.000000000 Z
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