philiprehberger-priority_queue 0.1.7 → 0.1.10

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: b6c6189abf62a5cd7a03eec4626b908cfb8fbfd954e8183dbb5ebe43f421105f
4
- data.tar.gz: 8af43691f143f9c673f56fed46d90486d9e0616ca938939bd99e5e62262b0bb9
3
+ metadata.gz: e95bdf19e31db232c54ac6ee645aa4a9023fc87140d2be6310c8469e4a5440d2
4
+ data.tar.gz: 944088fb4246573e985496a73fa8ca50a369da021274c050b8db926e3a6f7b4c
5
5
  SHA512:
6
- metadata.gz: fbb8db631237032ac270c43fe2c5a1f9e9c33a906a4e2c60def195451ade5d930196ffdaf44cd3342d21228a870c98d493ff31764fe0f7587e488b74a82003e7
7
- data.tar.gz: 12603ff8ef9d42bbac4fb3f364dab1b6edda0904962752e5ada257a022ec060f801d27175a7954c0849a2bd7499d78d9899d2a578bd6b1019ad26a32761a95cc
6
+ metadata.gz: 5c21fb11db45c81cc229b54ac6a8589000543141859a47abe483be620825e7662ce5b89228b278927e5665e842443300421641a9e494d372d3921f43bbcaad5a
7
+ data.tar.gz: 7efaf2fe7884442250b83e94e4c9e472f82b50e0ce7ee7ae8cc0f2390674cdd7827176de9c77baefd7df1a81b02ffca32260429545dbda04e9ea0566e0602db1
data/CHANGELOG.md CHANGED
@@ -7,6 +7,23 @@ and this gem adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.1.10] - 2026-03-31
11
+
12
+ ### Changed
13
+ - Standardize README badges, support section, and license format
14
+
15
+ ## [0.1.9] - 2026-03-26
16
+
17
+ ### Changed
18
+ - Add Sponsor badge to README
19
+ - Fix License section format
20
+
21
+
22
+ ## [0.1.8] - 2026-03-24
23
+
24
+ ### Changed
25
+ - Add Usage subsections and expand API table in README
26
+
10
27
  ## [0.1.7] - 2026-03-24
11
28
 
12
29
  ### Fixed
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Tests](https://github.com/philiprehberger/rb-priority-queue/actions/workflows/ci.yml/badge.svg)](https://github.com/philiprehberger/rb-priority-queue/actions/workflows/ci.yml)
4
4
  [![Gem Version](https://badge.fury.io/rb/philiprehberger-priority_queue.svg)](https://rubygems.org/gems/philiprehberger-priority_queue)
5
- [![License](https://img.shields.io/github/license/philiprehberger/rb-priority-queue)](LICENSE)
5
+ [![Last updated](https://img.shields.io/github/last-commit/philiprehberger/rb-priority-queue)](https://github.com/philiprehberger/rb-priority-queue/commits/main)
6
6
 
7
7
  Binary heap priority queue with min/max modes, custom comparators, and priority updates
8
8
 
@@ -31,45 +31,78 @@ require "philiprehberger/priority_queue"
31
31
 
32
32
  # Min-heap (default) - lowest priority first
33
33
  queue = Philiprehberger::PriorityQueue::Queue.new
34
- queue.push('low', priority: 1)
35
- queue.push('high', priority: 10)
36
- queue.push('mid', priority: 5)
34
+ queue.push("low", priority: 1)
35
+ queue.push("high", priority: 10)
36
+ queue.push("mid", priority: 5)
37
37
 
38
38
  queue.pop # => "low"
39
39
  queue.pop # => "mid"
40
40
  queue.pop # => "high"
41
41
 
42
- # Max-heap - highest priority first
42
+ # Peek without removing
43
+ queue.push("item", priority: 1)
44
+ queue.peek # => "item"
45
+ queue.size # => 1
46
+ queue.empty? # => false
47
+
48
+ # Shovel operator for hash-based push
49
+ queue << { item: "task", priority: 3 }
50
+ ```
51
+
52
+ ### Max-Heap Mode
53
+
54
+ Pass `mode: :max` to pop the highest priority first.
55
+
56
+ ```ruby
43
57
  queue = Philiprehberger::PriorityQueue::Queue.new(mode: :max)
44
- queue.push('task_a', priority: 3)
45
- queue.push('task_b', priority: 7)
46
- queue.pop # => "task_b"
58
+ queue.push("task_a", priority: 3)
59
+ queue.push("task_b", priority: 7)
60
+ queue.push("task_c", priority: 1)
61
+
62
+ queue.pop # => "task_b"
63
+ queue.pop # => "task_a"
64
+ queue.pop # => "task_c"
65
+ ```
66
+
67
+ ### Custom Comparator
47
68
 
48
- # Custom comparator
69
+ Supply a block to define your own ordering. The block receives two priorities and must return `-1`, `0`, or `1`.
70
+
71
+ ```ruby
49
72
  queue = Philiprehberger::PriorityQueue::Queue.new { |a, b| a.length <=> b.length }
50
- queue.push('short', priority: 'short')
51
- queue.push('very long', priority: 'very long')
52
- queue.pop # => "short"
73
+ queue.push("short", priority: "short")
74
+ queue.push("very long", priority: "very long")
75
+ queue.pop # => "short"
76
+ ```
53
77
 
54
- # Peek without removing
55
- queue = Philiprehberger::PriorityQueue::Queue.new
56
- queue.push('item', priority: 1)
57
- queue.peek # => "item"
58
- queue.size # => 1
78
+ ### Priority Updates
79
+
80
+ Change the priority of an item already in the queue. The heap re-balances automatically.
59
81
 
60
- # Change priority
82
+ ```ruby
61
83
  queue = Philiprehberger::PriorityQueue::Queue.new
62
- queue.push('task', priority: 10)
63
- queue.change_priority('task', 1) # now highest priority in min-heap
84
+ queue.push("task_a", priority: 10)
85
+ queue.push("task_b", priority: 5)
86
+
87
+ queue.change_priority("task_a", 1) # task_a is now highest priority
88
+ queue.pop # => "task_a"
89
+ ```
90
+
91
+ ### Merging Queues
64
92
 
65
- # Merge queues
66
- merged = queue1.merge(queue2)
93
+ Combine two queues into a new queue. The originals are unchanged.
67
94
 
68
- # Other operations
69
- queue.include?('task') # => true
70
- queue.to_a # => items sorted by priority
71
- queue.empty? # => false
72
- queue.clear # removes all items
95
+ ```ruby
96
+ q1 = Philiprehberger::PriorityQueue::Queue.new
97
+ q1.push("a", priority: 1)
98
+ q1.push("b", priority: 3)
99
+
100
+ q2 = Philiprehberger::PriorityQueue::Queue.new
101
+ q2.push("c", priority: 2)
102
+
103
+ merged = q1.merge(q2)
104
+ merged.to_a # => ["a", "c", "b"]
105
+ merged.size # => 3
73
106
  ```
74
107
 
75
108
  ## API
@@ -77,15 +110,16 @@ queue.clear # removes all items
77
110
  | Method | Description |
78
111
  |--------|-------------|
79
112
  | `Queue.new(mode: :min, &comparator)` | Create a priority queue; mode can be `:min` or `:max`; optional custom comparator block |
80
- | `#push(item, priority:)` | Add an item with the given priority |
81
- | `#pop` | Remove and return the highest-priority item |
82
- | `#peek` | Return the highest-priority item without removing it |
113
+ | `#push(item, priority:)` | Add an item with the given priority; returns `self` for chaining |
114
+ | `#<<(item:, priority:)` | Shovel operator; push via a hash with `:item` and `:priority` keys |
115
+ | `#pop` | Remove and return the highest-priority item; returns `nil` when empty |
116
+ | `#peek` | Return the highest-priority item without removing it; returns `nil` when empty |
83
117
  | `#size` | Return the number of items in the queue |
84
118
  | `#empty?` | Return `true` if the queue has no items |
85
- | `#change_priority(item, new_priority)` | Update the priority of an existing item and re-heapify |
86
- | `#to_a` | Return all items sorted by priority |
119
+ | `#change_priority(item, new_priority)` | Update the priority of an existing item and re-heapify; raises `ArgumentError` if item not found |
120
+ | `#to_a` | Return all items sorted by priority with FIFO tie-breaking |
87
121
  | `#include?(item)` | Return `true` if the item is in the queue |
88
- | `#clear` | Remove all items from the queue |
122
+ | `#clear` | Remove all items from the queue; returns `self` |
89
123
  | `#merge(other)` | Return a new queue containing items from both queues |
90
124
 
91
125
  ## Development
@@ -96,6 +130,24 @@ bundle exec rspec
96
130
  bundle exec rubocop
97
131
  ```
98
132
 
133
+ ## Support
134
+
135
+ If you find this project useful:
136
+
137
+ ⭐ [Star the repo](https://github.com/philiprehberger/rb-priority-queue)
138
+
139
+ 🐛 [Report issues](https://github.com/philiprehberger/rb-priority-queue/issues?q=is%3Aissue+is%3Aopen+label%3Abug)
140
+
141
+ 💡 [Suggest features](https://github.com/philiprehberger/rb-priority-queue/issues?q=is%3Aissue+is%3Aopen+label%3Aenhancement)
142
+
143
+ ❤️ [Sponsor development](https://github.com/sponsors/philiprehberger)
144
+
145
+ 🌐 [All Open Source Projects](https://philiprehberger.com/open-source-packages)
146
+
147
+ 💻 [GitHub Profile](https://github.com/philiprehberger)
148
+
149
+ 🔗 [LinkedIn Profile](https://www.linkedin.com/in/philiprehberger)
150
+
99
151
  ## License
100
152
 
101
- MIT
153
+ [MIT](LICENSE)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Philiprehberger
4
4
  module PriorityQueue
5
- VERSION = '0.1.7'
5
+ VERSION = '0.1.10'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: philiprehberger-priority_queue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - philiprehberger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-03-25 00:00:00.000000000 Z
11
+ date: 2026-03-31 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,