pairing_heap 3.1.1 → 3.1.2

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: f95d383584e208d1239f310d3e3bab5c727b4d721405b6b2b34eeb2a684b7ef0
4
- data.tar.gz: 3d1faf97fae0312ffcd3491bd70cddc1acc40a280c2d7af446742094456007bb
3
+ metadata.gz: 8389560b615ae5871d0adbae5a6b4e55554fa2df72e611e208a91352cdb3af28
4
+ data.tar.gz: 130e2d0daa895cf7921e18dd736552de22bf6ac23aab8bbdb0c6a33536c2d5e9
5
5
  SHA512:
6
- metadata.gz: 2ad6b8a6410b9bebcf0b1b10fa29fe79ef8799faff50e043c600faa47fe965efcb949cdd725ce0b612fe7f8f1b8432c1c3e04604c3424c3084ef4396e670eb1e
7
- data.tar.gz: 935a061846b27ed77f2af4f92f59b1080fddf83fe8949732ea23ca26e33e5d185cae232f9765edb5b7f850ac9970304a6872d504703342bc5b7601eb17c477e2
6
+ metadata.gz: 6f2d1588a2de63ce23c96ee06af18983304798dd4d678e88e58a7ee09efafafe511adc8d33259ed17aee88fcba63726fa467fb6a79a7ce863dac25466137e4ec
7
+ data.tar.gz: e972e7c8cd380c9374870c5b9232c1c307f3c723ba7672007f66e843d837482dd5e983d683eba29ef4e24aeaed839b8ab5f78cc382a0d6731de0f2fd393e716e
@@ -7,7 +7,7 @@ jobs:
7
7
  fail-fast: false
8
8
  matrix:
9
9
  os: [ubuntu-latest, macos-latest]
10
- ruby: ['3.2', '3.3', '3.4', '3.5', '4.0', jruby, truffleruby]
10
+ ruby: ['3.3', '3.4', '3.5', '4.0', jruby, truffleruby]
11
11
  runs-on: ${{ matrix.os }}
12
12
  steps:
13
13
  - uses: actions/checkout@v4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pairing_heap (3.1.1)
4
+ pairing_heap (3.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -9,10 +9,12 @@ GEM
9
9
  ast (2.4.3)
10
10
  docile (1.4.1)
11
11
  drb (2.2.3)
12
- json (2.18.0)
13
- json (2.18.0-java)
12
+ jar-dependencies (0.6.1-java)
13
+ json (2.21.2)
14
+ json (2.21.2-java)
14
15
  language_server-protocol (3.17.0.5)
15
16
  lint_roller (1.1.0)
17
+ logger (1.7.0)
16
18
  minitest (6.0.6)
17
19
  drb (~> 2.0)
18
20
  prism (~> 1.5)
@@ -20,11 +22,20 @@ GEM
20
22
  parser (3.3.10.0)
21
23
  ast (~> 2.4.1)
22
24
  racc
23
- prism (1.7.0)
25
+ prism (1.9.0)
24
26
  racc (1.8.1)
25
27
  racc (1.8.1-java)
26
28
  rainbow (3.1.1)
27
29
  rake (13.3.1)
30
+ rbs (4.2.0)
31
+ logger
32
+ prism (>= 1.6.0)
33
+ tsort
34
+ rbs (4.2.0-java)
35
+ jar-dependencies (>= 0.1.7)
36
+ logger
37
+ prism (>= 1.6.0)
38
+ tsort
28
39
  regexp_parser (2.11.3)
29
40
  rubocop (1.87.0)
30
41
  json (~> 2.3)
@@ -63,6 +74,7 @@ GEM
63
74
  standard-performance (1.9.0)
64
75
  lint_roller (~> 1.1)
65
76
  rubocop-performance (~> 1.26.0)
77
+ tsort (0.2.0)
66
78
  unicode-display_width (3.2.0)
67
79
  unicode-emoji (~> 4.1)
68
80
  unicode-emoji (4.2.0)
@@ -75,6 +87,7 @@ DEPENDENCIES
75
87
  minitest (~> 6.0)
76
88
  pairing_heap!
77
89
  rake (~> 13.3)
90
+ rbs (~> 4.2)
78
91
  simplecov (~> 0.22.0)
79
92
  standard (~> 1.55)
80
93
 
@@ -82,19 +95,23 @@ CHECKSUMS
82
95
  ast (2.4.3) sha256=954615157c1d6a382bc27d690d973195e79db7f55e9765ac7c481c60bdb4d383
83
96
  docile (1.4.1) sha256=96159be799bfa73cdb721b840e9802126e4e03dfc26863db73647204c727f21e
84
97
  drb (2.2.3) sha256=0b00d6fdb50995fe4a45dea13663493c841112e4068656854646f418fda13373
85
- json (2.18.0) sha256=b10506aee4183f5cf49e0efc48073d7b75843ce3782c68dbeb763351c08fd505
86
- json (2.18.0-java) sha256=74706f684baeb1a40351ed26fc8fe6e958afa861320d1c28ff4eb7073b29c7aa
98
+ jar-dependencies (0.6.1-java) sha256=2746643482d139fd9cecb524b57df63b71d9b5d734c7275171701201e3164f23
99
+ json (2.21.2) sha256=1f1d3b7cf2b3ba1a69beca0bb6db13d5438b80bff3cd54cdaaa620b9b07c1c6a
100
+ json (2.21.2-java) sha256=f01521cd90639cc26b63040fb00d2b949f18f41ecaab5c82b02fb31d0b8b736c
87
101
  language_server-protocol (3.17.0.5) sha256=fd1e39a51a28bf3eec959379985a72e296e9f9acfce46f6a79d31ca8760803cc
88
102
  lint_roller (1.1.0) sha256=2c0c845b632a7d172cb849cc90c1bce937a28c5c8ccccb50dfd46a485003cc87
103
+ logger (1.7.0) sha256=196edec7cc44b66cfb40f9755ce11b392f21f7967696af15d274dde7edff0203
89
104
  minitest (6.0.6) sha256=153ea36d1d987a62942382b61075745042a2b3123b1cd48f4c3675af9cc7d6f1
90
- pairing_heap (3.1.1)
105
+ pairing_heap (3.1.2)
91
106
  parallel (1.27.0) sha256=4ac151e1806b755fb4e2dc2332cbf0e54f2e24ba821ff2d3dcf86bf6dc4ae130
92
107
  parser (3.3.10.0) sha256=ce3587fa5cc55a88c4ba5b2b37621b3329aadf5728f9eafa36bbd121462aabd6
93
- prism (1.7.0) sha256=10062f734bf7985c8424c44fac382ac04a58124ea3d220ec3ba9fe4f2da65103
108
+ prism (1.9.0) sha256=7b530c6a9f92c24300014919c9dcbc055bf4cdf51ec30aed099b06cd6674ef85
94
109
  racc (1.8.1) sha256=4a7f6929691dbec8b5209a0b373bc2614882b55fc5d2e447a21aaa691303d62f
95
110
  racc (1.8.1-java) sha256=54f2e6d1e1b91c154013277d986f52a90e5ececbe91465d29172e49342732b98
96
111
  rainbow (3.1.1) sha256=039491aa3a89f42efa1d6dec2fc4e62ede96eb6acd95e52f1ad581182b79bc6a
97
112
  rake (13.3.1) sha256=8c9e89d09f66a26a01264e7e3480ec0607f0c497a861ef16063604b1b08eb19c
113
+ rbs (4.2.0) sha256=51f7b886dcc05bc09e10b901daa6a81829f6adc03101d6ca9ea4aac6103e0674
114
+ rbs (4.2.0-java) sha256=a19282d89c307dd6d33c6a72cc60f75b10d6d35a5996796e864789c903cddb3c
98
115
  regexp_parser (2.11.3) sha256=ca13f381a173b7a93450e53459075c9b76a10433caadcb2f1180f2c741fc55a4
99
116
  rubocop (1.87.0) sha256=b9d9ddf55116a513f8ef2c7ae660662d8b49301f118d3f0df61865b33a5c188d
100
117
  rubocop-ast (1.49.0) sha256=49c3676d3123a0923d333e20c6c2dbaaae2d2287b475273fddee0c61da9f71fd
@@ -106,6 +123,7 @@ CHECKSUMS
106
123
  standard (1.55.0) sha256=8a8f2c3e681a4db3aafde1b301561b0f3d7c5f06c160167cb744a4d7baf0426e
107
124
  standard-custom (1.0.2) sha256=424adc84179a074f1a2a309bb9cf7cd6bfdb2b6541f20c6bf9436c0ba22a652b
108
125
  standard-performance (1.9.0) sha256=49483d31be448292951d80e5e67cdcb576c2502103c7b40aec6f1b6e9c88e3f2
126
+ tsort (0.2.0) sha256=9650a793f6859a43b6641671278f79cfead60ac714148aabe4e3f0060480089f
109
127
  unicode-display_width (3.2.0) sha256=0cdd96b5681a5949cdbc2c55e7b420facae74c4aaf9a9815eee1087cb1853c42
110
128
  unicode-emoji (4.2.0) sha256=519e69150f75652e40bf736106cfbc8f0f73aa3fb6a65afe62fefa7f80b0f80f
111
129
 
data/Rakefile CHANGED
@@ -12,4 +12,8 @@ Rake::TestTask.new(:test) do |t|
12
12
  t.test_files = FileList["test/**/*_test.rb"]
13
13
  end
14
14
 
15
- task default: %i[test standard]
15
+ task :rbs do
16
+ sh "rbs validate sig/pairing_heap.rbs"
17
+ end
18
+
19
+ task default: %i[test standard rbs]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PairingHeap
4
- VERSION = "3.1.1"
4
+ VERSION = "3.1.2"
5
5
  end
data/pairing_heap.gemspec CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
27
  spec.require_paths = ["lib"]
28
28
 
29
+ spec.add_development_dependency "rbs", "~> 4.2"
29
30
  spec.add_development_dependency "minitest", "~> 6.0"
30
31
  spec.add_development_dependency "rake", "~> 13.3"
31
32
  spec.add_development_dependency "simplecov", "~> 0.22.0"
@@ -0,0 +1,175 @@
1
+ module PairingHeap
2
+ VERSION: String
3
+
4
+ # Pairing heap data structure implementation
5
+ # @see https://en.wikipedia.org/wiki/Pairing_heap
6
+ class PairingHeap[Elem, Priority]
7
+ # @yield [l_priority, r_priority] Optional heap property priority comparator. `<=.to_proc` by default
8
+ # @yieldreturn [bool] if `l_priority` is more prioritary than `r_priority`, or the priorities are equal
9
+ def initialize: () ?{ (Priority, Priority) -> boolish } -> void
10
+
11
+ # Pushes element to the heap.
12
+ # Time Complexity: O(1)
13
+ # @raise [ArgumentError] if the element is already in the heap
14
+ def push: (Elem elem, ?Priority priority) -> self
15
+ alias enqueue push
16
+ alias offer push
17
+
18
+ # Returns the element at the top of the heap.
19
+ # Time Complexity: O(1)
20
+ def peek: () -> Elem?
21
+
22
+ # Returns the priority of the element at the top of the heap.
23
+ # Time Complexity: O(1)
24
+ def peek_priority: () -> Priority?
25
+
26
+ # Returns the element and its priority at the top of the heap.
27
+ # Time Complexity: O(1)
28
+ def peek_with_priority: () -> [Elem, Priority] | [nil, nil]
29
+
30
+ # Time Complexity: O(1)
31
+ def empty?: () -> bool
32
+
33
+ # Time Complexity: O(1)
34
+ def any?: () -> bool
35
+
36
+ # Time Complexity: O(1)
37
+ def size: () -> Integer
38
+ alias length size
39
+
40
+ # Removes element from the top of the heap and returns it.
41
+ # Time Complexity: O(N), Amortized: O(log N)
42
+ def pop: () -> Elem?
43
+ alias dequeue pop
44
+
45
+ # Removes element from the top of the heap and returns its priority.
46
+ # Time Complexity: O(N), Amortized: O(log N)
47
+ def pop_priority: () -> Priority?
48
+
49
+ # Removes element from the top of the heap and returns it along with its priority.
50
+ # Time Complexity: O(N), Amortized: O(log N)
51
+ def pop_with_priority: () -> [Elem, Priority] | [nil, nil]
52
+
53
+ # Changes a priority of element to a more prioritary one.
54
+ # Time Complexity: O(1), Amortized: O(log N)
55
+ # @param elem Element
56
+ # @param priority New priority
57
+ # @raise [ArgumentError] if the element is not in the heap or the new priority is less prioritary
58
+ def change_priority: (Elem elem, Priority priority) -> self
59
+
60
+ # Removes element from the heap.
61
+ # Time Complexity: O(N), Amortized: O(log N)
62
+ # @raise [ArgumentError] if the element is not in the heap
63
+ def delete: (Elem elem) -> self
64
+
65
+ # Check if element is in the heap.
66
+ # Time Complexity: O(1)
67
+ def include?: (Elem key) -> bool
68
+ alias exists? include?
69
+
70
+ # Returns priority of the provided element.
71
+ # Time Complexity: O(1)
72
+ def get_priority: (Elem elem) -> Priority?
73
+
74
+ # Returns [false, nil] if the element is not in heap, [true, priority] if it is.
75
+ # Time Complexity: O(1)
76
+ def get_priority_if_exists: (Elem elem) -> [false, nil] | [true, Priority]
77
+
78
+ # Yields each element in the heap. No order guarantees.
79
+ def each: () { (Elem) -> void } -> void
80
+ | () -> Enumerator[Elem, void]
81
+
82
+ # Yields each [element, priority] pair in the heap. No order guarantees.
83
+ def each_with_priority: () { ([Elem, Priority]) -> void } -> void
84
+ | () -> Enumerator[[Elem, Priority], void]
85
+ end
86
+
87
+ class SimplePairingHeap[Elem, Priority]
88
+ # @yield [l_priority, r_priority] Optional heap property priority comparator. `<=.to_proc` by default
89
+ # @yieldreturn [bool] if `l_priority` is more prioritary than `r_priority`, or the priorities are equal
90
+ def initialize: () ?{ (Priority, Priority) -> boolish } -> void
91
+
92
+ # Pushes element to the heap.
93
+ # Time Complexity: O(1)
94
+ def push: (Elem elem, ?Priority priority) -> self
95
+ alias enqueue push
96
+ alias offer push
97
+
98
+ # Returns the element at the top of the heap.
99
+ # Time Complexity: O(1)
100
+ def peek: () -> Elem?
101
+
102
+ # Returns the priority of the element at the top of the heap.
103
+ # Time Complexity: O(1)
104
+ def peek_priority: () -> Priority?
105
+
106
+ # Returns the element and its priority at the top of the heap.
107
+ # Time Complexity: O(1)
108
+ def peek_with_priority: () -> [Elem, Priority] | [nil, nil]
109
+
110
+ # Time Complexity: O(1)
111
+ def empty?: () -> bool
112
+
113
+ # Time Complexity: O(1)
114
+ def any?: () -> bool
115
+
116
+ # Time Complexity: O(1)
117
+ attr_reader size: Integer
118
+ alias length size
119
+
120
+ # Removes element from the top of the heap and returns it.
121
+ # Time Complexity: O(N), Amortized: O(log N)
122
+ def pop: () -> Elem?
123
+ alias dequeue pop
124
+
125
+ # Removes element from the top of the heap and returns its priority.
126
+ # Time Complexity: O(N), Amortized: O(log N)
127
+ def pop_priority: () -> Priority?
128
+
129
+ # Removes element from the top of the heap and returns it along with its priority.
130
+ # Time Complexity: O(N), Amortized: O(log N)
131
+ def pop_with_priority: () -> [Elem, Priority] | [nil, nil]
132
+
133
+ # Yields each element in the heap. No order guarantees.
134
+ def each: () { (Elem) -> void } -> void
135
+ | () -> Enumerator[Elem, void]
136
+
137
+ # Yields each [element, priority] pair in the heap. No order guarantees.
138
+ def each_with_priority: () { ([Elem, Priority]) -> void } -> void
139
+ | () -> Enumerator[[Elem, Priority], void]
140
+
141
+ # Merges provided heap into self.
142
+ # Time Complexity: O(1)
143
+ # @raise [ArgumentError] if the provided argument is self
144
+ # @note Modifies the argument (clears it)
145
+ def merge: (SimplePairingHeap[Elem, Priority] other) -> self
146
+ end
147
+
148
+ # Priority queue where the smallest priority is the most prioritary
149
+ class MinPriorityQueue[Elem, Priority < Comparable[Priority]] < PairingHeap[Elem, Priority]
150
+ def initialize: () -> void
151
+
152
+ alias decrease_key change_priority
153
+ alias min peek
154
+ alias extract_min dequeue
155
+ end
156
+
157
+ # Priority queue where the highest priority is the most prioritary
158
+ class MaxPriorityQueue[Elem, Priority < Comparable[Priority]] < PairingHeap[Elem, Priority]
159
+ def initialize: () -> void
160
+
161
+ alias increase_key change_priority
162
+ alias max peek
163
+ alias extract_max dequeue
164
+ end
165
+
166
+ # Priority queue with change_priority that accepts changing to a less prioritary priority
167
+ class SafeChangePriorityQueue[Elem, Priority] < PairingHeap[Elem, Priority]
168
+ # Changes a priority of the element (accepts any direction).
169
+ # Time Complexity: O(N), Amortized: O(log N)
170
+ # @param elem Element
171
+ # @param priority New priority
172
+ # @raise [ArgumentError] if the element is not in the heap
173
+ def change_priority: (Elem elem, Priority priority) -> self
174
+ end
175
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pairing_heap
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcin Henryk Bartkowiak
@@ -9,6 +9,20 @@ bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rbs
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '4.2'
19
+ type: :development
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '4.2'
12
26
  - !ruby/object:Gem::Dependency
13
27
  name: minitest
14
28
  requirement: !ruby/object:Gem::Requirement
@@ -86,6 +100,7 @@ files:
86
100
  - lib/pairing_heap.rb
87
101
  - lib/pairing_heap/version.rb
88
102
  - pairing_heap.gemspec
103
+ - sig/pairing_heap.rbs
89
104
  homepage: https://github.com/mhib/pairing_heap
90
105
  licenses:
91
106
  - MIT
@@ -108,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
123
  - !ruby/object:Gem::Version
109
124
  version: '0'
110
125
  requirements: []
111
- rubygems_version: 4.0.10
126
+ rubygems_version: 4.0.16
112
127
  specification_version: 4
113
128
  summary: Performant priority queue in pure ruby with support for changing priority
114
129
  test_files: []