comp_tree 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.rdoc +5 -0
- data/devel/levitate.rb +11 -9
- data/lib/comp_tree.rb +8 -1
- data/lib/comp_tree/algorithm.rb +6 -5
- data/lib/comp_tree/driver.rb +7 -6
- data/lib/comp_tree/node.rb +17 -37
- data/lib/comp_tree/version.rb +1 -1
- metadata +2 -2
data/CHANGES.rdoc
CHANGED
data/devel/levitate.rb
CHANGED
@@ -250,7 +250,7 @@ class Levitate
|
|
250
250
|
include Util
|
251
251
|
|
252
252
|
def initialize(gem_name)
|
253
|
-
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
253
|
+
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
|
254
254
|
|
255
255
|
require 'rubygems/package_task'
|
256
256
|
|
@@ -402,11 +402,7 @@ class Levitate
|
|
402
402
|
end
|
403
403
|
|
404
404
|
attribute :extra_rdoc_files do
|
405
|
-
|
406
|
-
[readme_file, history_file].each { |file|
|
407
|
-
result << file if File.file?(file)
|
408
|
-
}
|
409
|
-
result
|
405
|
+
[readme_file, history_file].select { |file| File.file?(file) }
|
410
406
|
end
|
411
407
|
|
412
408
|
attribute :browser do
|
@@ -482,9 +478,11 @@ class Levitate
|
|
482
478
|
begin
|
483
479
|
sections[send("#{section}_section")].
|
484
480
|
gsub("\n", " ").
|
485
|
-
split(%r!\.\s
|
481
|
+
split(%r!\.\s+!m).
|
486
482
|
first(send("#{section}_sentences")).
|
487
|
-
join(".
|
483
|
+
join(". ").
|
484
|
+
concat(".").
|
485
|
+
sub(%r!\.+\Z!, ".")
|
488
486
|
rescue
|
489
487
|
"FIXME: #{section}"
|
490
488
|
end
|
@@ -753,7 +751,11 @@ class Levitate
|
|
753
751
|
|
754
752
|
def define_changes
|
755
753
|
task :changes do
|
756
|
-
|
754
|
+
if File.read(history_file).index version
|
755
|
+
raise "version not updated"
|
756
|
+
end
|
757
|
+
|
758
|
+
header = "\n\n== Version #{version}\n\n"
|
757
759
|
|
758
760
|
bullets = `git log --format=%s #{last_release}..HEAD`.lines.map { |line|
|
759
761
|
"* #{line}"
|
data/lib/comp_tree.rb
CHANGED
@@ -65,7 +65,7 @@ module CompTree
|
|
65
65
|
# 2
|
66
66
|
# }
|
67
67
|
#
|
68
|
-
# # Compute the area using four parallel threads.
|
68
|
+
# # Compute the area using up to four parallel threads.
|
69
69
|
# puts driver.compute(:area, 4)
|
70
70
|
# # => 63
|
71
71
|
#
|
@@ -74,6 +74,13 @@ module CompTree
|
|
74
74
|
# # => 63
|
75
75
|
# end
|
76
76
|
#
|
77
|
+
# A custom <code>CompTree::Node</code> subclass may optionally be
|
78
|
+
# provided,
|
79
|
+
#
|
80
|
+
# CompTree.build(:node_class => MyNode) { ... }
|
81
|
+
#
|
82
|
+
# This will build the tree with +MyNode+ instances.
|
83
|
+
#
|
77
84
|
def self.build(opts = {})
|
78
85
|
yield Driver.new(opts)
|
79
86
|
end
|
data/lib/comp_tree/algorithm.rb
CHANGED
@@ -13,7 +13,9 @@ module CompTree
|
|
13
13
|
workers.size.times { to_workers.push(nil) }
|
14
14
|
workers.each { |t| t.join }
|
15
15
|
|
16
|
-
|
16
|
+
if node.computed.is_a? Exception
|
17
|
+
raise node.computed
|
18
|
+
end
|
17
19
|
node.result
|
18
20
|
end
|
19
21
|
|
@@ -26,8 +28,7 @@ module CompTree
|
|
26
28
|
}
|
27
29
|
end
|
28
30
|
|
29
|
-
def master_loop(root,
|
30
|
-
max_threads = arg1 == 0 ? nil : arg1
|
31
|
+
def master_loop(root, max_threads, workers, from_workers, to_workers)
|
31
32
|
num_working = 0
|
32
33
|
node = nil
|
33
34
|
while true
|
@@ -62,7 +63,7 @@ module CompTree
|
|
62
63
|
# already computed
|
63
64
|
#
|
64
65
|
nil
|
65
|
-
elsif
|
66
|
+
elsif node.free? and node.children_results
|
66
67
|
#
|
67
68
|
# Node is not computed, not locked, and its children are
|
68
69
|
# computed; ready to compute.
|
@@ -72,7 +73,7 @@ module CompTree
|
|
72
73
|
#
|
73
74
|
# locked or children not computed; recurse to children
|
74
75
|
#
|
75
|
-
node.
|
76
|
+
node.children.each { |child|
|
76
77
|
found = find_node(child) and return found
|
77
78
|
}
|
78
79
|
nil
|
data/lib/comp_tree/driver.rb
CHANGED
@@ -29,11 +29,11 @@ module CompTree
|
|
29
29
|
# to the block. The block returns the result of this node's
|
30
30
|
# computation.
|
31
31
|
#
|
32
|
-
# In
|
33
|
-
# which depends on the nodes
|
32
|
+
# In the following example, a computation node named +:area+ is
|
33
|
+
# defined which depends on the nodes named +:width+ and +:height+.
|
34
34
|
#
|
35
|
-
# driver.define(:area, :width, :height) { |
|
36
|
-
#
|
35
|
+
# driver.define(:area, :width, :height) { |w, h|
|
36
|
+
# w*h
|
37
37
|
# }
|
38
38
|
#
|
39
39
|
def define(name, *child_names, &block)
|
@@ -110,15 +110,16 @@ module CompTree
|
|
110
110
|
raise TypeError, "can't convert #{max_threads.class} into Integer"
|
111
111
|
end
|
112
112
|
if max_threads < 0
|
113
|
-
raise RangeError, "
|
113
|
+
raise RangeError, "max threads must be nonnegative"
|
114
114
|
end
|
115
|
+
|
115
116
|
root = @nodes[name] or raise NoNodeError.new(name)
|
116
117
|
if root.computed
|
117
118
|
root.result
|
118
119
|
elsif max_threads == 1
|
119
120
|
root.compute_now
|
120
121
|
else
|
121
|
-
Algorithm.compute_parallel(root, max_threads)
|
122
|
+
Algorithm.compute_parallel(root, max_threads == 0 ? nil : max_threads)
|
122
123
|
end
|
123
124
|
end
|
124
125
|
end
|
data/lib/comp_tree/node.rb
CHANGED
@@ -11,8 +11,7 @@ module CompTree
|
|
11
11
|
:children,
|
12
12
|
:function,
|
13
13
|
:result,
|
14
|
-
:computed
|
15
|
-
:lock_level
|
14
|
+
:computed
|
16
15
|
)
|
17
16
|
|
18
17
|
#
|
@@ -40,28 +39,9 @@ module CompTree
|
|
40
39
|
# Reset the computation for this node and all children.
|
41
40
|
#
|
42
41
|
def reset
|
43
|
-
|
44
|
-
node.reset_self
|
45
|
-
}
|
46
|
-
end
|
47
|
-
|
48
|
-
def each_downward(&block)
|
49
|
-
block.call(self)
|
50
|
-
@children.each { |child|
|
51
|
-
child.each_downward(&block)
|
52
|
-
}
|
53
|
-
end
|
54
|
-
|
55
|
-
def each_upward(&block)
|
56
|
-
block.call(self)
|
57
|
-
@parents.each { |parent|
|
58
|
-
parent.each_upward(&block)
|
59
|
-
}
|
60
|
-
end
|
61
|
-
|
62
|
-
def each_child
|
42
|
+
reset_self
|
63
43
|
@children.each { |child|
|
64
|
-
|
44
|
+
child.reset
|
65
45
|
}
|
66
46
|
end
|
67
47
|
|
@@ -89,14 +69,12 @@ module CompTree
|
|
89
69
|
# otherwise return nil.
|
90
70
|
#
|
91
71
|
def children_results
|
92
|
-
@children_results
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
}
|
99
|
-
)
|
72
|
+
@children_results ||= @children.map { |child|
|
73
|
+
unless child.computed
|
74
|
+
return nil
|
75
|
+
end
|
76
|
+
child.result
|
77
|
+
}
|
100
78
|
end
|
101
79
|
|
102
80
|
#
|
@@ -116,19 +94,21 @@ module CompTree
|
|
116
94
|
@result
|
117
95
|
end
|
118
96
|
|
119
|
-
def
|
120
|
-
@lock_level
|
97
|
+
def free?
|
98
|
+
@lock_level.zero?
|
121
99
|
end
|
122
100
|
|
123
101
|
def lock
|
124
|
-
|
125
|
-
|
102
|
+
@lock_level = @lock_level.succ
|
103
|
+
@parents.each { |parent|
|
104
|
+
parent.lock
|
126
105
|
}
|
127
106
|
end
|
128
107
|
|
129
108
|
def unlock
|
130
|
-
|
131
|
-
|
109
|
+
@lock_level -= 1 # Fixnum#pred not in 1.8.6
|
110
|
+
@parents.each { |parent|
|
111
|
+
parent.unlock
|
132
112
|
}
|
133
113
|
end
|
134
114
|
end
|
data/lib/comp_tree/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: comp_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.1.
|
5
|
+
version: 1.1.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- James M. Lawrence
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-03-
|
13
|
+
date: 2011-03-08 00:00:00 -05:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|