rubysl-tsort 1.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -3
- data/lib/rubysl/tsort/tsort.rb +10 -58
- data/lib/rubysl/tsort/version.rb +1 -1
- data/rubysl-tsort.gemspec +3 -0
- metadata +19 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15567ecf63300d8393e8f0ef5fba571654f92a49
|
4
|
+
data.tar.gz: 084e6fb807ae8703dc7b8116a500e743a5406677
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 833370c8f10c03e3c7b26ca0904697cd1233d7903d9c5435c05137a9df95d7bd4463f93d4fa93c08147d55c7c5caf049133d56a96b02b6f05b4c39b64539d43a
|
7
|
+
data.tar.gz: b451e41b372266d1b8660eba5dd759919d9105e2d601aa6cdad87ecad60a2f11d5c129e12534442b048cc2083d534165f655aff586dfddef7803d081e456902c
|
data/.travis.yml
CHANGED
data/lib/rubysl/tsort/tsort.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
1
|
#--
|
3
2
|
# tsort.rb - provides a module for topological sorting and strongly connected components.
|
4
3
|
#++
|
@@ -32,7 +31,7 @@
|
|
32
31
|
# array using the user-supplied block.
|
33
32
|
#
|
34
33
|
# require 'tsort'
|
35
|
-
#
|
34
|
+
#
|
36
35
|
# class Hash
|
37
36
|
# include TSort
|
38
37
|
# alias tsort_each_node each_key
|
@@ -40,10 +39,10 @@
|
|
40
39
|
# fetch(node).each(&block)
|
41
40
|
# end
|
42
41
|
# end
|
43
|
-
#
|
42
|
+
#
|
44
43
|
# {1=>[2, 3], 2=>[3], 3=>[], 4=>[]}.tsort
|
45
44
|
# #=> [3, 2, 1, 4]
|
46
|
-
#
|
45
|
+
#
|
47
46
|
# {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}.strongly_connected_components
|
48
47
|
# #=> [[4], [2, 3], [1]]
|
49
48
|
#
|
@@ -52,19 +51,19 @@
|
|
52
51
|
# A very simple `make' like tool can be implemented as follows:
|
53
52
|
#
|
54
53
|
# require 'tsort'
|
55
|
-
#
|
54
|
+
#
|
56
55
|
# class Make
|
57
56
|
# def initialize
|
58
57
|
# @dep = {}
|
59
58
|
# @dep.default = []
|
60
59
|
# end
|
61
|
-
#
|
60
|
+
#
|
62
61
|
# def rule(outputs, inputs=[], &block)
|
63
62
|
# triple = [outputs, inputs, block]
|
64
63
|
# outputs.each {|f| @dep[f] = [triple]}
|
65
64
|
# @dep[triple] = inputs
|
66
65
|
# end
|
67
|
-
#
|
66
|
+
#
|
68
67
|
# def build(target)
|
69
68
|
# each_strongly_connected_component_from(target) {|ns|
|
70
69
|
# if ns.length != 1
|
@@ -88,18 +87,18 @@
|
|
88
87
|
# end
|
89
88
|
# }
|
90
89
|
# end
|
91
|
-
#
|
90
|
+
#
|
92
91
|
# def tsort_each_child(node, &block)
|
93
92
|
# @dep[node].each(&block)
|
94
93
|
# end
|
95
94
|
# include TSort
|
96
95
|
# end
|
97
|
-
#
|
96
|
+
#
|
98
97
|
# def command(arg)
|
99
98
|
# print arg, "\n"
|
100
99
|
# system arg
|
101
100
|
# end
|
102
|
-
#
|
101
|
+
#
|
103
102
|
# m = Make.new
|
104
103
|
# m.rule(%w[t1]) { command 'date > t1' }
|
105
104
|
# m.rule(%w[t2]) { command 'date > t2' }
|
@@ -189,7 +188,7 @@ module TSort
|
|
189
188
|
end
|
190
189
|
|
191
190
|
#
|
192
|
-
# Iterates over strongly connected component in the subgraph reachable from
|
191
|
+
# Iterates over strongly connected component in the subgraph reachable from
|
193
192
|
# _node_.
|
194
193
|
#
|
195
194
|
# Return value is unspecified.
|
@@ -241,50 +240,3 @@ module TSort
|
|
241
240
|
raise NotImplementedError.new
|
242
241
|
end
|
243
242
|
end
|
244
|
-
|
245
|
-
if __FILE__ == $0
|
246
|
-
require 'test/unit'
|
247
|
-
|
248
|
-
class TSortHash < Hash # :nodoc:
|
249
|
-
include TSort
|
250
|
-
alias tsort_each_node each_key
|
251
|
-
def tsort_each_child(node, &block)
|
252
|
-
fetch(node).each(&block)
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
class TSortArray < Array # :nodoc:
|
257
|
-
include TSort
|
258
|
-
alias tsort_each_node each_index
|
259
|
-
def tsort_each_child(node, &block)
|
260
|
-
fetch(node).each(&block)
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
class TSortTest < Test::Unit::TestCase # :nodoc:
|
265
|
-
def test_dag
|
266
|
-
h = TSortHash[{1=>[2, 3], 2=>[3], 3=>[]}]
|
267
|
-
assert_equal([3, 2, 1], h.tsort)
|
268
|
-
assert_equal([[3], [2], [1]], h.strongly_connected_components)
|
269
|
-
end
|
270
|
-
|
271
|
-
def test_cycle
|
272
|
-
h = TSortHash[{1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}]
|
273
|
-
assert_equal([[4], [2, 3], [1]],
|
274
|
-
h.strongly_connected_components.map {|nodes| nodes.sort})
|
275
|
-
assert_raise(TSort::Cyclic) { h.tsort }
|
276
|
-
end
|
277
|
-
|
278
|
-
def test_array
|
279
|
-
a = TSortArray[[1], [0], [0], [2]]
|
280
|
-
assert_equal([[0, 1], [2], [3]],
|
281
|
-
a.strongly_connected_components.map {|nodes| nodes.sort})
|
282
|
-
|
283
|
-
a = TSortArray[[], [0]]
|
284
|
-
assert_equal([[0], [1]],
|
285
|
-
a.strongly_connected_components.map {|nodes| nodes.sort})
|
286
|
-
end
|
287
|
-
end
|
288
|
-
|
289
|
-
end
|
290
|
-
|
data/lib/rubysl/tsort/version.rb
CHANGED
data/rubysl-tsort.gemspec
CHANGED
@@ -16,6 +16,9 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
17
|
spec.require_paths = ["lib"]
|
18
18
|
|
19
|
+
spec.required_ruby_version = "~> 2.0"
|
20
|
+
|
19
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
20
22
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "mspec", "~> 1.5"
|
21
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubysl-tsort
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Shirai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
41
55
|
description: Ruby standard library tsort.
|
42
56
|
email:
|
43
57
|
- brixen@gmail.com
|
@@ -66,9 +80,9 @@ require_paths:
|
|
66
80
|
- lib
|
67
81
|
required_ruby_version: !ruby/object:Gem::Requirement
|
68
82
|
requirements:
|
69
|
-
- -
|
83
|
+
- - ~>
|
70
84
|
- !ruby/object:Gem::Version
|
71
|
-
version: '0'
|
85
|
+
version: '2.0'
|
72
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
87
|
requirements:
|
74
88
|
- - '>='
|
@@ -81,3 +95,4 @@ signing_key:
|
|
81
95
|
specification_version: 4
|
82
96
|
summary: Ruby standard library tsort.
|
83
97
|
test_files: []
|
98
|
+
has_rdoc:
|