bogo 0.1.12 → 0.1.14

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
  SHA1:
3
- metadata.gz: 1cfa543d2f3739d18a3df6fa420a46697880cc16
4
- data.tar.gz: 8875ff3c7b44e4d4f8a9ede11a6ceaf8024d1611
3
+ metadata.gz: 5cfd7e480292d255f881920e0ad55d713e98ca55
4
+ data.tar.gz: c163ab2cc687608f257a90f0305d5434cc166ff3
5
5
  SHA512:
6
- metadata.gz: ce49932b19e5bbe4e99adfdeb73b578aca860e9ea96b88901f31f67f00f69ae0baaa8278d1e824fc4861d09f75135c130703ac2ddae113481f4e1e078626b907
7
- data.tar.gz: f475c41d8176aa3b003756e55be3b209f9d0f605aac70286e72f11ef33461e7dff63270514e69192de25c7e8f09df3b9017a2ce9aff7a06be9024a03bc151d81
6
+ metadata.gz: 50e85630e7c013930b600c64d8a34f4b711289f322b929dfa0609943bb3a784515ab2c7b4e6df8b0cf22deae6260f9cbd1d6d28d6cfe7d5a75f6e3680cf56b21
7
+ data.tar.gz: 6546f6dc0bfde10d4c294d3a571d98279cdc054c0d4bf9dd7283a4067b26bd1092511e4749019ab9481466157e8619e684eb4b8e8c4d8c7717c5bfd48f2dfc6d
@@ -1,3 +1,8 @@
1
+ ## v0.1.14
2
+ * [PriorityQueue] Add PriorityQueue#include? helper method
3
+ * [PriorityQueue] Wrap sorting with synchronization
4
+ * [Constants] Remove pre-check for constant (force load)
5
+
1
6
  ## v0.1.12
2
7
  * Support multiple item push on `PriorityQueue`
3
8
 
@@ -11,8 +11,11 @@ module Bogo
11
11
  # @return [Object]
12
12
  def constantize(string)
13
13
  string.split('::').inject(ObjectSpace) do |memo, key|
14
- break unless memo.const_defined?(key)
15
- memo.const_get(key)
14
+ begin
15
+ memo.const_get(key)
16
+ rescue NameError
17
+ break
18
+ end
16
19
  end
17
20
  end
18
21
 
@@ -31,8 +31,8 @@ module Bogo
31
31
  end
32
32
  @block_costs += 1 if cost.nil?
33
33
  queue[item] = cost || block
34
- sort!
35
34
  end
35
+ sort!
36
36
  self
37
37
  end
38
38
 
@@ -53,15 +53,15 @@ module Bogo
53
53
  @block_costs += 1 if cost.is_a?(Proc)
54
54
  queue[item] = cost
55
55
  end
56
- sort!
57
56
  end
57
+ sort!
58
58
  self
59
59
  end
60
60
 
61
61
  # @return [Object, NilClass] item or nil if empty
62
62
  def pop
63
+ sort! if @block_costs > 0
63
64
  lock.synchronize do
64
- sort! if @block_costs > 0
65
65
  item, score = queue.first
66
66
  @block_costs -= 1 if score.respond_to?(:call)
67
67
  queue.delete(item)
@@ -76,21 +76,31 @@ module Bogo
76
76
  end
77
77
  end
78
78
 
79
+ # @return [TrueClass, FalseClass]
79
80
  def empty?
80
81
  size == 0
81
82
  end
82
83
 
84
+ # @return [TrueClass, FalseClass]
85
+ def include?(object)
86
+ lock.synchronize do
87
+ queue.keys.include?(object)
88
+ end
89
+ end
90
+
83
91
  # Sort the queue based on cost
84
92
  def sort!
85
- queue.replace(
86
- Hash[
87
- queue.sort do |x,y|
88
- x,y = y,x if @reverse_score
89
- (x.last.respond_to?(:call) ? x.last.call : x.last).to_f <=>
90
- (y.last.respond_to?(:call) ? y.last.call : y.last).to_f
91
- end
92
- ]
93
- )
93
+ lock.synchronize do
94
+ queue.replace(
95
+ Hash[
96
+ queue.sort do |x,y|
97
+ x,y = y,x if @reverse_score
98
+ (x.last.respond_to?(:call) ? x.last.call : x.last).to_f <=>
99
+ (y.last.respond_to?(:call) ? y.last.call : y.last).to_f
100
+ end
101
+ ]
102
+ )
103
+ end
94
104
  end
95
105
 
96
106
  protected
@@ -1,4 +1,4 @@
1
1
  module Bogo
2
2
  # Current library version
3
- VERSION = Gem::Version.new('0.1.12')
3
+ VERSION = Gem::Version.new('0.1.14')
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bogo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Roberts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-06 00:00:00.000000000 Z
11
+ date: 2015-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie