pairing_heap 3.1.0 → 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 +4 -4
- data/.github/workflows/main.yml +2 -3
- data/Gemfile.lock +96 -47
- data/Rakefile +5 -1
- data/lib/pairing_heap/version.rb +1 -1
- data/lib/pairing_heap.rb +13 -7
- data/pairing_heap.gemspec +4 -3
- data/sig/pairing_heap.rbs +175 -0
- metadata +24 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8389560b615ae5871d0adbae5a6b4e55554fa2df72e611e208a91352cdb3af28
|
|
4
|
+
data.tar.gz: 130e2d0daa895cf7921e18dd736552de22bf6ac23aab8bbdb0c6a33536c2d5e9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6f2d1588a2de63ce23c96ee06af18983304798dd4d678e88e58a7ee09efafafe511adc8d33259ed17aee88fcba63726fa467fb6a79a7ce863dac25466137e4ec
|
|
7
|
+
data.tar.gz: e972e7c8cd380c9374870c5b9232c1c307f3c723ba7672007f66e843d837482dd5e983d683eba29ef4e24aeaed839b8ab5f78cc382a0d6731de0f2fd393e716e
|
data/.github/workflows/main.yml
CHANGED
|
@@ -7,11 +7,10 @@ jobs:
|
|
|
7
7
|
fail-fast: false
|
|
8
8
|
matrix:
|
|
9
9
|
os: [ubuntu-latest, macos-latest]
|
|
10
|
-
|
|
11
|
-
ruby: ['2.7', '3.0', '3.1', '3.2', '3.3', head, jruby, jruby-head, truffleruby, truffleruby-head]
|
|
10
|
+
ruby: ['3.3', '3.4', '3.5', '4.0', jruby, truffleruby]
|
|
12
11
|
runs-on: ${{ matrix.os }}
|
|
13
12
|
steps:
|
|
14
|
-
- uses: actions/checkout@
|
|
13
|
+
- uses: actions/checkout@v4
|
|
15
14
|
- name: Set up ruby
|
|
16
15
|
uses: ruby/setup-ruby@v1
|
|
17
16
|
with:
|
data/Gemfile.lock
CHANGED
|
@@ -1,82 +1,131 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
pairing_heap (3.1.
|
|
4
|
+
pairing_heap (3.1.2)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
8
8
|
specs:
|
|
9
|
-
ast (2.4.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
json (2.
|
|
14
|
-
|
|
9
|
+
ast (2.4.3)
|
|
10
|
+
docile (1.4.1)
|
|
11
|
+
drb (2.2.3)
|
|
12
|
+
jar-dependencies (0.6.1-java)
|
|
13
|
+
json (2.21.2)
|
|
14
|
+
json (2.21.2-java)
|
|
15
|
+
language_server-protocol (3.17.0.5)
|
|
15
16
|
lint_roller (1.1.0)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
logger (1.7.0)
|
|
18
|
+
minitest (6.0.6)
|
|
19
|
+
drb (~> 2.0)
|
|
20
|
+
prism (~> 1.5)
|
|
21
|
+
parallel (1.27.0)
|
|
22
|
+
parser (3.3.10.0)
|
|
19
23
|
ast (~> 2.4.1)
|
|
20
24
|
racc
|
|
21
|
-
|
|
22
|
-
racc (1.
|
|
25
|
+
prism (1.9.0)
|
|
26
|
+
racc (1.8.1)
|
|
27
|
+
racc (1.8.1-java)
|
|
23
28
|
rainbow (3.1.1)
|
|
24
|
-
rake (13.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
|
39
|
+
regexp_parser (2.11.3)
|
|
40
|
+
rubocop (1.87.0)
|
|
29
41
|
json (~> 2.3)
|
|
30
|
-
language_server-protocol (
|
|
31
|
-
|
|
32
|
-
|
|
42
|
+
language_server-protocol (~> 3.17.0.2)
|
|
43
|
+
lint_roller (~> 1.1.0)
|
|
44
|
+
parallel (>= 1.10)
|
|
45
|
+
parser (>= 3.3.0.2)
|
|
33
46
|
rainbow (>= 2.2.2, < 4.0)
|
|
34
|
-
regexp_parser (>=
|
|
35
|
-
|
|
36
|
-
rubocop-ast (>= 1.28.1, < 2.0)
|
|
47
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
|
48
|
+
rubocop-ast (>= 1.49.0, < 2.0)
|
|
37
49
|
ruby-progressbar (~> 1.7)
|
|
38
|
-
unicode-display_width (>= 2.4.0, <
|
|
39
|
-
rubocop-ast (1.
|
|
40
|
-
parser (>= 3.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
50
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
|
51
|
+
rubocop-ast (1.49.0)
|
|
52
|
+
parser (>= 3.3.7.2)
|
|
53
|
+
prism (~> 1.7)
|
|
54
|
+
rubocop-performance (1.26.1)
|
|
55
|
+
lint_roller (~> 1.1)
|
|
56
|
+
rubocop (>= 1.75.0, < 2.0)
|
|
57
|
+
rubocop-ast (>= 1.47.1, < 2.0)
|
|
44
58
|
ruby-progressbar (1.13.0)
|
|
45
59
|
simplecov (0.22.0)
|
|
46
60
|
docile (~> 1.1)
|
|
47
61
|
simplecov-html (~> 0.11)
|
|
48
62
|
simplecov_json_formatter (~> 0.1)
|
|
49
|
-
simplecov-html (0.
|
|
63
|
+
simplecov-html (0.13.2)
|
|
50
64
|
simplecov_json_formatter (0.1.4)
|
|
51
|
-
standard (1.
|
|
65
|
+
standard (1.55.0)
|
|
52
66
|
language_server-protocol (~> 3.17.0.2)
|
|
53
67
|
lint_roller (~> 1.0)
|
|
54
|
-
rubocop (~> 1.
|
|
68
|
+
rubocop (~> 1.87.0)
|
|
55
69
|
standard-custom (~> 1.0.0)
|
|
56
|
-
standard-performance (~> 1.
|
|
70
|
+
standard-performance (~> 1.8)
|
|
57
71
|
standard-custom (1.0.2)
|
|
58
72
|
lint_roller (~> 1.0)
|
|
59
73
|
rubocop (~> 1.50)
|
|
60
|
-
standard-performance (1.
|
|
74
|
+
standard-performance (1.9.0)
|
|
61
75
|
lint_roller (~> 1.1)
|
|
62
|
-
rubocop-performance (~> 1.
|
|
63
|
-
|
|
76
|
+
rubocop-performance (~> 1.26.0)
|
|
77
|
+
tsort (0.2.0)
|
|
78
|
+
unicode-display_width (3.2.0)
|
|
79
|
+
unicode-emoji (~> 4.1)
|
|
80
|
+
unicode-emoji (4.2.0)
|
|
64
81
|
|
|
65
82
|
PLATFORMS
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
x86_64-darwin-20
|
|
69
|
-
x86_64-darwin-21
|
|
70
|
-
x86_64-darwin-22
|
|
71
|
-
x86_64-darwin-23
|
|
72
|
-
x86_64-linux
|
|
83
|
+
java
|
|
84
|
+
ruby
|
|
73
85
|
|
|
74
86
|
DEPENDENCIES
|
|
75
|
-
minitest (~>
|
|
87
|
+
minitest (~> 6.0)
|
|
76
88
|
pairing_heap!
|
|
77
|
-
rake (~> 13.
|
|
89
|
+
rake (~> 13.3)
|
|
90
|
+
rbs (~> 4.2)
|
|
78
91
|
simplecov (~> 0.22.0)
|
|
79
|
-
standard (~> 1.
|
|
92
|
+
standard (~> 1.55)
|
|
93
|
+
|
|
94
|
+
CHECKSUMS
|
|
95
|
+
ast (2.4.3) sha256=954615157c1d6a382bc27d690d973195e79db7f55e9765ac7c481c60bdb4d383
|
|
96
|
+
docile (1.4.1) sha256=96159be799bfa73cdb721b840e9802126e4e03dfc26863db73647204c727f21e
|
|
97
|
+
drb (2.2.3) sha256=0b00d6fdb50995fe4a45dea13663493c841112e4068656854646f418fda13373
|
|
98
|
+
jar-dependencies (0.6.1-java) sha256=2746643482d139fd9cecb524b57df63b71d9b5d734c7275171701201e3164f23
|
|
99
|
+
json (2.21.2) sha256=1f1d3b7cf2b3ba1a69beca0bb6db13d5438b80bff3cd54cdaaa620b9b07c1c6a
|
|
100
|
+
json (2.21.2-java) sha256=f01521cd90639cc26b63040fb00d2b949f18f41ecaab5c82b02fb31d0b8b736c
|
|
101
|
+
language_server-protocol (3.17.0.5) sha256=fd1e39a51a28bf3eec959379985a72e296e9f9acfce46f6a79d31ca8760803cc
|
|
102
|
+
lint_roller (1.1.0) sha256=2c0c845b632a7d172cb849cc90c1bce937a28c5c8ccccb50dfd46a485003cc87
|
|
103
|
+
logger (1.7.0) sha256=196edec7cc44b66cfb40f9755ce11b392f21f7967696af15d274dde7edff0203
|
|
104
|
+
minitest (6.0.6) sha256=153ea36d1d987a62942382b61075745042a2b3123b1cd48f4c3675af9cc7d6f1
|
|
105
|
+
pairing_heap (3.1.2)
|
|
106
|
+
parallel (1.27.0) sha256=4ac151e1806b755fb4e2dc2332cbf0e54f2e24ba821ff2d3dcf86bf6dc4ae130
|
|
107
|
+
parser (3.3.10.0) sha256=ce3587fa5cc55a88c4ba5b2b37621b3329aadf5728f9eafa36bbd121462aabd6
|
|
108
|
+
prism (1.9.0) sha256=7b530c6a9f92c24300014919c9dcbc055bf4cdf51ec30aed099b06cd6674ef85
|
|
109
|
+
racc (1.8.1) sha256=4a7f6929691dbec8b5209a0b373bc2614882b55fc5d2e447a21aaa691303d62f
|
|
110
|
+
racc (1.8.1-java) sha256=54f2e6d1e1b91c154013277d986f52a90e5ececbe91465d29172e49342732b98
|
|
111
|
+
rainbow (3.1.1) sha256=039491aa3a89f42efa1d6dec2fc4e62ede96eb6acd95e52f1ad581182b79bc6a
|
|
112
|
+
rake (13.3.1) sha256=8c9e89d09f66a26a01264e7e3480ec0607f0c497a861ef16063604b1b08eb19c
|
|
113
|
+
rbs (4.2.0) sha256=51f7b886dcc05bc09e10b901daa6a81829f6adc03101d6ca9ea4aac6103e0674
|
|
114
|
+
rbs (4.2.0-java) sha256=a19282d89c307dd6d33c6a72cc60f75b10d6d35a5996796e864789c903cddb3c
|
|
115
|
+
regexp_parser (2.11.3) sha256=ca13f381a173b7a93450e53459075c9b76a10433caadcb2f1180f2c741fc55a4
|
|
116
|
+
rubocop (1.87.0) sha256=b9d9ddf55116a513f8ef2c7ae660662d8b49301f118d3f0df61865b33a5c188d
|
|
117
|
+
rubocop-ast (1.49.0) sha256=49c3676d3123a0923d333e20c6c2dbaaae2d2287b475273fddee0c61da9f71fd
|
|
118
|
+
rubocop-performance (1.26.1) sha256=cd19b936ff196df85829d264b522fd4f98b6c89ad271fa52744a8c11b8f71834
|
|
119
|
+
ruby-progressbar (1.13.0) sha256=80fc9c47a9b640d6834e0dc7b3c94c9df37f08cb072b7761e4a71e22cff29b33
|
|
120
|
+
simplecov (0.22.0) sha256=fe2622c7834ff23b98066bb0a854284b2729a569ac659f82621fc22ef36213a5
|
|
121
|
+
simplecov-html (0.13.2) sha256=bd0b8e54e7c2d7685927e8d6286466359b6f16b18cb0df47b508e8d73c777246
|
|
122
|
+
simplecov_json_formatter (0.1.4) sha256=529418fbe8de1713ac2b2d612aa3daa56d316975d307244399fa4838c601b428
|
|
123
|
+
standard (1.55.0) sha256=8a8f2c3e681a4db3aafde1b301561b0f3d7c5f06c160167cb744a4d7baf0426e
|
|
124
|
+
standard-custom (1.0.2) sha256=424adc84179a074f1a2a309bb9cf7cd6bfdb2b6541f20c6bf9436c0ba22a652b
|
|
125
|
+
standard-performance (1.9.0) sha256=49483d31be448292951d80e5e67cdcb576c2502103c7b40aec6f1b6e9c88e3f2
|
|
126
|
+
tsort (0.2.0) sha256=9650a793f6859a43b6641671278f79cfead60ac714148aabe4e3f0060480089f
|
|
127
|
+
unicode-display_width (3.2.0) sha256=0cdd96b5681a5949cdbc2c55e7b420facae74c4aaf9a9815eee1087cb1853c42
|
|
128
|
+
unicode-emoji (4.2.0) sha256=519e69150f75652e40bf736106cfbc8f0f73aa3fb6a65afe62fefa7f80b0f80f
|
|
80
129
|
|
|
81
130
|
BUNDLED WITH
|
|
82
|
-
|
|
131
|
+
4.0.3
|
data/Rakefile
CHANGED
data/lib/pairing_heap/version.rb
CHANGED
data/lib/pairing_heap.rb
CHANGED
|
@@ -508,7 +508,7 @@ module PairingHeap
|
|
|
508
508
|
delete(elem)
|
|
509
509
|
push(elem, priority)
|
|
510
510
|
else
|
|
511
|
-
super
|
|
511
|
+
super
|
|
512
512
|
end
|
|
513
513
|
end
|
|
514
514
|
end
|
|
@@ -518,14 +518,20 @@ module PairingHeap
|
|
|
518
518
|
|
|
519
519
|
def visit_node(node, &block)
|
|
520
520
|
return unless node
|
|
521
|
+
stack = [node]
|
|
521
522
|
|
|
522
|
-
|
|
523
|
+
until stack.empty?
|
|
524
|
+
node = stack.pop
|
|
523
525
|
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
526
|
+
block.call(node)
|
|
527
|
+
|
|
528
|
+
if node.subheaps
|
|
529
|
+
stack << node.subheaps
|
|
530
|
+
end
|
|
531
|
+
|
|
532
|
+
if node.next_sibling
|
|
533
|
+
stack << node.next_sibling
|
|
534
|
+
end
|
|
529
535
|
end
|
|
530
536
|
end
|
|
531
537
|
end
|
data/pairing_heap.gemspec
CHANGED
|
@@ -26,8 +26,9 @@ 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 "
|
|
30
|
-
spec.add_development_dependency "
|
|
29
|
+
spec.add_development_dependency "rbs", "~> 4.2"
|
|
30
|
+
spec.add_development_dependency "minitest", "~> 6.0"
|
|
31
|
+
spec.add_development_dependency "rake", "~> 13.3"
|
|
31
32
|
spec.add_development_dependency "simplecov", "~> 0.22.0"
|
|
32
|
-
spec.add_development_dependency "standard", "~> 1.
|
|
33
|
+
spec.add_development_dependency "standard", "~> 1.55"
|
|
33
34
|
end
|
|
@@ -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,43 +1,56 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pairing_heap
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.1.
|
|
4
|
+
version: 3.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Marcin Henryk Bartkowiak
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: exe
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
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'
|
|
13
26
|
- !ruby/object:Gem::Dependency
|
|
14
27
|
name: minitest
|
|
15
28
|
requirement: !ruby/object:Gem::Requirement
|
|
16
29
|
requirements:
|
|
17
30
|
- - "~>"
|
|
18
31
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
32
|
+
version: '6.0'
|
|
20
33
|
type: :development
|
|
21
34
|
prerelease: false
|
|
22
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
36
|
requirements:
|
|
24
37
|
- - "~>"
|
|
25
38
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
39
|
+
version: '6.0'
|
|
27
40
|
- !ruby/object:Gem::Dependency
|
|
28
41
|
name: rake
|
|
29
42
|
requirement: !ruby/object:Gem::Requirement
|
|
30
43
|
requirements:
|
|
31
44
|
- - "~>"
|
|
32
45
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '13.
|
|
46
|
+
version: '13.3'
|
|
34
47
|
type: :development
|
|
35
48
|
prerelease: false
|
|
36
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
50
|
requirements:
|
|
38
51
|
- - "~>"
|
|
39
52
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '13.
|
|
53
|
+
version: '13.3'
|
|
41
54
|
- !ruby/object:Gem::Dependency
|
|
42
55
|
name: simplecov
|
|
43
56
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -58,14 +71,14 @@ dependencies:
|
|
|
58
71
|
requirements:
|
|
59
72
|
- - "~>"
|
|
60
73
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '1.
|
|
74
|
+
version: '1.55'
|
|
62
75
|
type: :development
|
|
63
76
|
prerelease: false
|
|
64
77
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
78
|
requirements:
|
|
66
79
|
- - "~>"
|
|
67
80
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '1.
|
|
81
|
+
version: '1.55'
|
|
69
82
|
description: Performant priority queue in pure ruby with support for changing priority
|
|
70
83
|
using pairing heap data structure
|
|
71
84
|
email:
|
|
@@ -87,6 +100,7 @@ files:
|
|
|
87
100
|
- lib/pairing_heap.rb
|
|
88
101
|
- lib/pairing_heap/version.rb
|
|
89
102
|
- pairing_heap.gemspec
|
|
103
|
+
- sig/pairing_heap.rbs
|
|
90
104
|
homepage: https://github.com/mhib/pairing_heap
|
|
91
105
|
licenses:
|
|
92
106
|
- MIT
|
|
@@ -95,7 +109,6 @@ metadata:
|
|
|
95
109
|
source_code_uri: https://github.com/mhib/pairing_heap
|
|
96
110
|
documentation_uri: https://rubydoc.info/gems/pairing_heap
|
|
97
111
|
rubygems_mfa_required: 'true'
|
|
98
|
-
post_install_message:
|
|
99
112
|
rdoc_options: []
|
|
100
113
|
require_paths:
|
|
101
114
|
- lib
|
|
@@ -110,8 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
110
123
|
- !ruby/object:Gem::Version
|
|
111
124
|
version: '0'
|
|
112
125
|
requirements: []
|
|
113
|
-
rubygems_version:
|
|
114
|
-
signing_key:
|
|
126
|
+
rubygems_version: 4.0.16
|
|
115
127
|
specification_version: 4
|
|
116
128
|
summary: Performant priority queue in pure ruby with support for changing priority
|
|
117
129
|
test_files: []
|