priority_queue_cxx 0.3.5 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/fast_containers/FastContainers.cpp +1 -0
- data/ext/fast_containers/fc_pq.cpp +6 -3
- data/test/test_fast_containers.rb +13 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdf28c23df29684a2a6a9dfb4d5c5b2be60ffa1c4729c0bde44925b3f31c2237
|
4
|
+
data.tar.gz: 90415c07d9cd47d1a4a626abbab3123e724123f95599f09cca420c0d3bd1a752
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb1167358338c541477a748a303e1c32dd760f7433db2f187d5476a492202e9538244c7f6617299d026718869f0d1d39ba5dda553b2af2ca6f58567b1157cc32
|
7
|
+
data.tar.gz: bbd3e48430af5471fc9e27881a9b4f65571979732412de5352f03691df7ecd85b316cf67055cd4405b292d361505b0ae27bb248aa806b49e68f9a26ce88c7972
|
@@ -255,6 +255,7 @@ extern "C" {
|
|
255
255
|
void Init_fast_containers() {
|
256
256
|
FastContainers = rb_define_module("FastContainers");
|
257
257
|
PriorityQueue = rb_define_class_under(FastContainers, "PriorityQueue", rb_cObject);
|
258
|
+
rb_undef_alloc_func(PriorityQueue);
|
258
259
|
rb_global_variable(&FastContainers);
|
259
260
|
rb_global_variable(&PriorityQueue);
|
260
261
|
|
@@ -81,15 +81,18 @@ namespace fc_pq {
|
|
81
81
|
}
|
82
82
|
|
83
83
|
double second_best_key(PQueue q) {
|
84
|
+
// elements in storage are not necessarily sorted, but the
|
85
|
+
// second best key is bound to be in one of the first two elements
|
84
86
|
if(q->storage.size()==2)
|
85
87
|
return q->storage.at(1).second;
|
86
88
|
|
87
89
|
double key1 = q->storage.at(1).second;
|
88
90
|
double key2 = q->storage.at(2).second;
|
89
|
-
|
90
|
-
|
91
|
-
} else {
|
91
|
+
|
92
|
+
if( q->comparator(q->storage.at(1), q->storage.at(2)) ) {
|
92
93
|
return key2;
|
94
|
+
} else {
|
95
|
+
return key1;
|
93
96
|
}
|
94
97
|
}
|
95
98
|
|
@@ -19,9 +19,11 @@
|
|
19
19
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
20
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
21
|
require "minitest/autorun"
|
22
|
+
require 'minitest/spec'
|
23
|
+
require 'minitest/autorun'
|
22
24
|
require "fc"
|
23
25
|
|
24
|
-
class TestFastContainers <
|
26
|
+
class TestFastContainers < Minitest::Test
|
25
27
|
def test_new_object_creation
|
26
28
|
assert !FastContainers::PriorityQueue.new(:max).nil?
|
27
29
|
end
|
@@ -177,6 +179,15 @@ class TestFastContainers < MiniTest::Unit::TestCase
|
|
177
179
|
|
178
180
|
assert_equal pq.second_best_key, 95
|
179
181
|
end
|
182
|
+
|
183
|
+
def test_second_best_key_on_min_queues
|
184
|
+
pq = FastContainers::PriorityQueue.new(:min)
|
185
|
+
pq.push("a",2)
|
186
|
+
pq.push("b",2)
|
187
|
+
pq.push("c",3)
|
188
|
+
|
189
|
+
assert_equal pq.second_best_key, 2
|
190
|
+
end
|
180
191
|
|
181
192
|
def test_second_best_key_on_empty_pq
|
182
193
|
pq = FastContainers::PriorityQueue.new(:max)
|
@@ -239,7 +250,7 @@ class TestFastContainers < MiniTest::Unit::TestCase
|
|
239
250
|
end
|
240
251
|
end
|
241
252
|
|
242
|
-
assert_match /a change in the priority queue invalidated the current iterator
|
253
|
+
assert_match (/a change in the priority queue invalidated the current iterator/), exception.message
|
243
254
|
assert_equal 4, objects.size
|
244
255
|
end
|
245
256
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: priority_queue_cxx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roberto Esposito
|
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
requirements: []
|
70
|
-
rubygems_version: 3.
|
70
|
+
rubygems_version: 3.5.4
|
71
71
|
signing_key:
|
72
72
|
specification_version: 4
|
73
73
|
summary: Fast (c++ wrapper) priority queue implementation for ruby.
|