priority_queue_cxx 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7abe67c4e9f2b119c40c6313206cbd68b79e56e8c79550d38e5a38f9b33236b2
4
- data.tar.gz: 9ff72ad384bd32a437e53011de54fa33f580645a1fc761e9755e95cc733bfb3d
3
+ metadata.gz: fdf28c23df29684a2a6a9dfb4d5c5b2be60ffa1c4729c0bde44925b3f31c2237
4
+ data.tar.gz: 90415c07d9cd47d1a4a626abbab3123e724123f95599f09cca420c0d3bd1a752
5
5
  SHA512:
6
- metadata.gz: 3001a18291bd80439f2beba7a1a560676c30bb591d3d1b04ac7a8fb3ede8084e1bdbfb8554b2590d80c101a7bf216e86cc29cfe1900b0f9dc43356f063f84d79
7
- data.tar.gz: 4b477633d626e58227c189b11fb241f4fbdf0f0a0534e6901c5827c32d6ffe0e0e55f2efe63fb9479e56cad3dc3faed2d183fe2b26d08b37f5108a936a913889
6
+ metadata.gz: fb1167358338c541477a748a303e1c32dd760f7433db2f187d5476a492202e9538244c7f6617299d026718869f0d1d39ba5dda553b2af2ca6f58567b1157cc32
7
+ data.tar.gz: bbd3e48430af5471fc9e27881a9b4f65571979732412de5352f03691df7ecd85b316cf67055cd4405b292d361505b0ae27bb248aa806b49e68f9a26ce88c7972
@@ -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
- if( key1 > key2 ) {
90
- return key1;
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 < MiniTest::Unit::TestCase
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/, exception.message
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.6
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.4.2
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.