philiprehberger-priority_queue 0.2.0 → 0.3.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 +11 -0
- data/README.md +16 -0
- data/lib/philiprehberger/priority_queue/version.rb +1 -1
- data/lib/philiprehberger/priority_queue.rb +12 -0
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 81ecb740f0ef3871c9662a0bf53f627784e039ad638c3e772fae8cbf9664ec52
|
|
4
|
+
data.tar.gz: 8233105bc0db893faa7a53696c2283165d4bc6b5f10f86c02771a1101ddb1a76
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 47adacec5e5bd08c5cd6dd2a45500f5e5901372df0171b1aaceb6aefe0e162fc4504e67b345a067ee818685333ca158eb3440a7fe9173c4716e2ed18f1586537
|
|
7
|
+
data.tar.gz: 53380b7734ed65fcbf26b80644caef0268b2c187182a8168792aba4fa855433a4dcca840060a9f673972cb4250fc3e1cc996e75474bfcb8a07ac35168d03da59
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,17 @@ and this gem adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.3.0] - 2026-04-15
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `Queue#pop_n(n)` to pop up to `n` items in priority order and return them as an array; returns `[]` for empty queues or `n == 0`; raises `ArgumentError` for negative `n`
|
|
14
|
+
|
|
15
|
+
## [0.2.1] - 2026-04-15
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
- Set gemspec authors to `Philip Rehberger` and email to `me@philiprehberger.com`
|
|
19
|
+
- Update `required_ruby_version` to `>= 3.1.0` to match gemspec template
|
|
20
|
+
|
|
10
21
|
## [0.2.0] - 2026-04-03
|
|
11
22
|
|
|
12
23
|
### Added
|
data/README.md
CHANGED
|
@@ -127,6 +127,21 @@ queue.drain # => ["a", "b", "c"]
|
|
|
127
127
|
queue.empty? # => true
|
|
128
128
|
```
|
|
129
129
|
|
|
130
|
+
### Pop N
|
|
131
|
+
|
|
132
|
+
Pop up to `n` items in priority order. Returns fewer than `n` items when the queue is exhausted.
|
|
133
|
+
|
|
134
|
+
```ruby
|
|
135
|
+
queue = Philiprehberger::PriorityQueue::Queue.new
|
|
136
|
+
queue.push("a", priority: 1)
|
|
137
|
+
queue.push("b", priority: 2)
|
|
138
|
+
queue.push("c", priority: 3)
|
|
139
|
+
|
|
140
|
+
queue.pop_n(2) # => ["a", "b"]
|
|
141
|
+
queue.pop_n(5) # => ["c"]
|
|
142
|
+
queue.pop_n(0) # => []
|
|
143
|
+
```
|
|
144
|
+
|
|
130
145
|
### Delete
|
|
131
146
|
|
|
132
147
|
Remove a specific item by value.
|
|
@@ -202,6 +217,7 @@ merged.size # => 3
|
|
|
202
217
|
| `#push_many(items)` | Batch push from array of hashes `[{ item: x, priority: n }, ...]`; returns `self` |
|
|
203
218
|
| `#peek_priority` | Return just the top priority value; returns `nil` when empty |
|
|
204
219
|
| `#drain` | Pop all items and return as array in priority order; empties the queue |
|
|
220
|
+
| `#pop_n(n)` | Pop up to `n` items in priority order and return as array; returns `[]` for empty queue or `n == 0`; raises `ArgumentError` for negative `n` |
|
|
205
221
|
| `#delete(item)` | Remove a specific item by value; returns the item or `nil` |
|
|
206
222
|
| `#priorities` | Return sorted array of unique priority values in the queue |
|
|
207
223
|
| `#each` | Yield `[item, priority]` pairs in priority order (Enumerable) |
|
|
@@ -57,6 +57,18 @@ module Philiprehberger
|
|
|
57
57
|
@heap[0][2]
|
|
58
58
|
end
|
|
59
59
|
|
|
60
|
+
def pop_n(n)
|
|
61
|
+
raise ArgumentError, "n must be non-negative, got #{n}" if n.negative?
|
|
62
|
+
|
|
63
|
+
result = []
|
|
64
|
+
n.times do
|
|
65
|
+
break if empty?
|
|
66
|
+
|
|
67
|
+
result << pop
|
|
68
|
+
end
|
|
69
|
+
result
|
|
70
|
+
end
|
|
71
|
+
|
|
60
72
|
def empty?
|
|
61
73
|
@size.zero?
|
|
62
74
|
end
|
metadata
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-priority_queue
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.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: A binary heap-based priority queue supporting min-heap, max-heap, and
|
|
14
14
|
custom comparator modes. Features O(log n) push/pop, priority changes, merge operations,
|
|
15
15
|
and FIFO tie-breaking.
|
|
16
16
|
email:
|
|
17
|
-
- philiprehberger
|
|
17
|
+
- me@philiprehberger.com
|
|
18
18
|
executables: []
|
|
19
19
|
extensions: []
|
|
20
20
|
extra_rdoc_files: []
|
|
@@ -41,7 +41,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
41
41
|
requirements:
|
|
42
42
|
- - ">="
|
|
43
43
|
- !ruby/object:Gem::Version
|
|
44
|
-
version:
|
|
44
|
+
version: 3.1.0
|
|
45
45
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
46
|
requirements:
|
|
47
47
|
- - ">="
|