philiprehberger-queue_stack 0.5.0 → 0.6.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: dba395bc3ee76baae4cdbbbb100fc91103049635c386e02fe5ac3ae118e9997a
4
- data.tar.gz: 921a8e4241383d570d951e154b19e7abcce5cdb682d93b42888d36c9804871a2
3
+ metadata.gz: aeb1d7901c33280074ac91777f24b5dcc3704f9d3144dac214a4e8baba9b8bf0
4
+ data.tar.gz: 21a0f6c879d8d1f95270b4d34497e5905064ee96738b30ae9a7bb870c6e3d820
5
5
  SHA512:
6
- metadata.gz: 30320f35b2ae5d2e01221091e203c31cc799ec5d6a1ff279a0201a04dd9c038f254ad8319d1e4f8cf3a50e1e292e2522a813e8330383f2f49ce99b86d5704b1c
7
- data.tar.gz: 2ddd79499fa0b97b99fcb45c5c941984c1f8b3ddeee25cc4edeed317b9317509d9ade981940ca685266770db6dc3d472b11e3fdb8610b45731abd44f7f3a284e
6
+ metadata.gz: 28ba1990bc0e94d4c79b414d1a62a69d022f4091d76bd3bdc092e6c377cc0fd7fd79d1a265126aed15bf3a705fa34ac05c05d084990ea867022e03220f23ed7d
7
+ data.tar.gz: d6fc9a7f47a18010cf5b1f7e096861cca61bf565f604c5687a10165cc2074196457e918b3564fe8f80a233ca2e9ad4584929af11b465db4481b3e35f40e0a6ca
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.6.0] - 2026-04-27
11
+
12
+ ### Added
13
+ - `Queue#capacity`, `Queue#remaining_capacity`, `Stack#capacity`, `Stack#remaining_capacity` — capacity introspection. `capacity` returns the configured limit (or `nil` for unlimited); `remaining_capacity` returns the number of additional items that can still be accepted (or `nil` for unlimited, `0` when full). Mutex-synchronized for consistent reads.
14
+
10
15
  ## [0.5.0] - 2026-04-16
11
16
 
12
17
  ### Added
data/README.md CHANGED
@@ -159,6 +159,22 @@ q.full? # => true
159
159
  # enqueue blocks until space is available
160
160
  ```
161
161
 
162
+ ### Capacity
163
+
164
+ Read the configured capacity and the number of additional items that can be
165
+ accepted. Both return `nil` for unbounded containers; `remaining_capacity`
166
+ returns `0` when full. Useful for sizing batches or backpressure decisions.
167
+
168
+ ```ruby
169
+ q = Philiprehberger::QueueStack::Queue.new(capacity: 100)
170
+ q.capacity # => 100
171
+ q.remaining_capacity # => 100
172
+ 50.times { |i| q.enqueue(i) }
173
+ q.remaining_capacity # => 50
174
+
175
+ batch_size = [items.length, q.remaining_capacity].min
176
+ ```
177
+
162
178
  ## API
163
179
 
164
180
  ### `Queue`
@@ -182,6 +198,8 @@ q.full? # => true
182
198
  | `#size` | Number of items |
183
199
  | `#empty?` | Whether the queue is empty |
184
200
  | `#full?` | Whether the queue is at capacity |
201
+ | `#capacity` | Configured capacity, or `nil` for an unlimited queue |
202
+ | `#remaining_capacity` | Items the queue can still accept (`nil` for unlimited, `0` when full) |
185
203
 
186
204
  ### `Stack`
187
205
 
@@ -203,6 +221,8 @@ q.full? # => true
203
221
  | `#size` | Number of items |
204
222
  | `#empty?` | Whether the stack is empty |
205
223
  | `#full?` | Whether the stack is at capacity |
224
+ | `#capacity` | Configured capacity, or `nil` for an unlimited stack |
225
+ | `#remaining_capacity` | Items the stack can still accept (`nil` for unlimited, `0` when full) |
206
226
 
207
227
  ## Development
208
228
 
@@ -225,6 +225,27 @@ module Philiprehberger
225
225
  def full?
226
226
  @mutex.synchronize { @capacity ? @items.length >= @capacity : false }
227
227
  end
228
+
229
+ # The configured capacity, or +nil+ for an unlimited queue.
230
+ #
231
+ # @return [Integer, nil]
232
+ def capacity
233
+ @mutex.synchronize { @capacity }
234
+ end
235
+
236
+ # Number of additional items the queue can accept before it is full.
237
+ #
238
+ # Returns +nil+ for unlimited queues. For bounded queues returns
239
+ # +capacity - size+, clamped to a minimum of 0.
240
+ #
241
+ # @return [Integer, nil]
242
+ def remaining_capacity
243
+ @mutex.synchronize do
244
+ next nil unless @capacity
245
+
246
+ [@capacity - @items.length, 0].max
247
+ end
248
+ end
228
249
  end
229
250
  end
230
251
  end
@@ -213,6 +213,27 @@ module Philiprehberger
213
213
  def full?
214
214
  @mutex.synchronize { @capacity ? @items.length >= @capacity : false }
215
215
  end
216
+
217
+ # The configured capacity, or +nil+ for an unlimited stack.
218
+ #
219
+ # @return [Integer, nil]
220
+ def capacity
221
+ @mutex.synchronize { @capacity }
222
+ end
223
+
224
+ # Number of additional items the stack can accept before it is full.
225
+ #
226
+ # Returns +nil+ for unlimited stacks. For bounded stacks returns
227
+ # +capacity - size+, clamped to a minimum of 0.
228
+ #
229
+ # @return [Integer, nil]
230
+ def remaining_capacity
231
+ @mutex.synchronize do
232
+ next nil unless @capacity
233
+
234
+ [@capacity - @items.length, 0].max
235
+ end
236
+ end
216
237
  end
217
238
  end
218
239
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Philiprehberger
4
4
  module QueueStack
5
- VERSION = '0.5.0'
5
+ VERSION = '0.6.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.5.0
4
+ version: 0.6.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-16 00:00:00.000000000 Z
11
+ date: 2026-04-28 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