bogo 0.1.12 → 0.1.14
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/CHANGELOG.md +5 -0
- data/lib/bogo/constants.rb +5 -2
- data/lib/bogo/priority_queue.rb +22 -12
- data/lib/bogo/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5cfd7e480292d255f881920e0ad55d713e98ca55
|
4
|
+
data.tar.gz: c163ab2cc687608f257a90f0305d5434cc166ff3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50e85630e7c013930b600c64d8a34f4b711289f322b929dfa0609943bb3a784515ab2c7b4e6df8b0cf22deae6260f9cbd1d6d28d6cfe7d5a75f6e3680cf56b21
|
7
|
+
data.tar.gz: 6546f6dc0bfde10d4c294d3a571d98279cdc054c0d4bf9dd7283a4067b26bd1092511e4749019ab9481466157e8619e684eb4b8e8c4d8c7717c5bfd48f2dfc6d
|
data/CHANGELOG.md
CHANGED
data/lib/bogo/constants.rb
CHANGED
@@ -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
|
-
|
15
|
-
|
14
|
+
begin
|
15
|
+
memo.const_get(key)
|
16
|
+
rescue NameError
|
17
|
+
break
|
18
|
+
end
|
16
19
|
end
|
17
20
|
end
|
18
21
|
|
data/lib/bogo/priority_queue.rb
CHANGED
@@ -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
|
-
|
86
|
-
|
87
|
-
|
88
|
-
x,y
|
89
|
-
|
90
|
-
(
|
91
|
-
|
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
|
data/lib/bogo/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2015-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|