tsort 0.1.0 → 0.1.1
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/.github/dependabot.yml +6 -0
- data/.github/workflows/test.yml +2 -4
- data/lib/tsort.rb +10 -10
- data/tsort.gemspec +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fec6e698aaafb515cbb1d1d3da7c47f8a23d6962ea46b20beacaff24a602ebc5
|
|
4
|
+
data.tar.gz: 4360b342f4438c3407c8fc76085868626fcfc0a98df805edde686c57e287f5c8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3e2701ffd89ed3afd5a18683cc34018d985a3a6325b8d01d53dfc4d4d0da1bc50396a70d308ac808b89a2adb2838bd8273b92435e4132422ec214ea659e474ff
|
|
7
|
+
data.tar.gz: f70e00dcf6db0b210e6fe0dd98d70c2899edc25c5829482340f56a93091db53fe69ebc2c35103307837e1950d5c458cccba129b16e158e2ec9f998072ed31b15
|
data/.github/workflows/test.yml
CHANGED
|
@@ -11,14 +11,12 @@ jobs:
|
|
|
11
11
|
os: [ ubuntu-latest, macos-latest ]
|
|
12
12
|
runs-on: ${{ matrix.os }}
|
|
13
13
|
steps:
|
|
14
|
-
- uses: actions/checkout@
|
|
14
|
+
- uses: actions/checkout@v3
|
|
15
15
|
- name: Set up Ruby
|
|
16
16
|
uses: ruby/setup-ruby@v1
|
|
17
17
|
with:
|
|
18
18
|
ruby-version: ${{ matrix.ruby }}
|
|
19
19
|
- name: Install dependencies
|
|
20
|
-
run:
|
|
21
|
-
gem install bundler --no-document
|
|
22
|
-
bundle install
|
|
20
|
+
run: bundle install
|
|
23
21
|
- name: Run test
|
|
24
22
|
run: rake test
|
data/lib/tsort.rb
CHANGED
|
@@ -172,8 +172,8 @@ module TSort
|
|
|
172
172
|
# each_child = lambda {|n, &b| g[n].each(&b) }
|
|
173
173
|
# p TSort.tsort(each_node, each_child) # raises TSort::Cyclic
|
|
174
174
|
#
|
|
175
|
-
def
|
|
176
|
-
|
|
175
|
+
def self.tsort(each_node, each_child)
|
|
176
|
+
tsort_each(each_node, each_child).to_a
|
|
177
177
|
end
|
|
178
178
|
|
|
179
179
|
# The iterator version of the #tsort method.
|
|
@@ -220,10 +220,10 @@ module TSort
|
|
|
220
220
|
# # 3
|
|
221
221
|
# # 1
|
|
222
222
|
#
|
|
223
|
-
def
|
|
223
|
+
def self.tsort_each(each_node, each_child) # :yields: node
|
|
224
224
|
return to_enum(__method__, each_node, each_child) unless block_given?
|
|
225
225
|
|
|
226
|
-
|
|
226
|
+
each_strongly_connected_component(each_node, each_child) {|component|
|
|
227
227
|
if component.size == 1
|
|
228
228
|
yield component.first
|
|
229
229
|
else
|
|
@@ -277,8 +277,8 @@ module TSort
|
|
|
277
277
|
# p TSort.strongly_connected_components(each_node, each_child)
|
|
278
278
|
# #=> [[4], [2, 3], [1]]
|
|
279
279
|
#
|
|
280
|
-
def
|
|
281
|
-
|
|
280
|
+
def self.strongly_connected_components(each_node, each_child)
|
|
281
|
+
each_strongly_connected_component(each_node, each_child).to_a
|
|
282
282
|
end
|
|
283
283
|
|
|
284
284
|
# The iterator version of the #strongly_connected_components method.
|
|
@@ -339,14 +339,14 @@ module TSort
|
|
|
339
339
|
# # [2, 3]
|
|
340
340
|
# # [1]
|
|
341
341
|
#
|
|
342
|
-
def
|
|
342
|
+
def self.each_strongly_connected_component(each_node, each_child) # :yields: nodes
|
|
343
343
|
return to_enum(__method__, each_node, each_child) unless block_given?
|
|
344
344
|
|
|
345
345
|
id_map = {}
|
|
346
346
|
stack = []
|
|
347
347
|
each_node.call {|node|
|
|
348
348
|
unless id_map.include? node
|
|
349
|
-
|
|
349
|
+
each_strongly_connected_component_from(node, each_child, id_map, stack) {|c|
|
|
350
350
|
yield c
|
|
351
351
|
}
|
|
352
352
|
end
|
|
@@ -405,7 +405,7 @@ module TSort
|
|
|
405
405
|
# # [2, 3]
|
|
406
406
|
# # [1]
|
|
407
407
|
#
|
|
408
|
-
def
|
|
408
|
+
def self.each_strongly_connected_component_from(node, each_child, id_map={}, stack=[]) # :yields: nodes
|
|
409
409
|
return to_enum(__method__, node, each_child, id_map, stack) unless block_given?
|
|
410
410
|
|
|
411
411
|
minimum_id = node_id = id_map[node] = id_map.size
|
|
@@ -418,7 +418,7 @@ module TSort
|
|
|
418
418
|
minimum_id = child_id if child_id && child_id < minimum_id
|
|
419
419
|
else
|
|
420
420
|
sub_minimum_id =
|
|
421
|
-
|
|
421
|
+
each_strongly_connected_component_from(child, each_child, id_map, stack) {|c|
|
|
422
422
|
yield c
|
|
423
423
|
}
|
|
424
424
|
minimum_id = sub_minimum_id if sub_minimum_id < minimum_id
|
data/tsort.gemspec
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tsort
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tanaka Akira
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2022-12-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Topological sorting using Tarjan's algorithm
|
|
14
14
|
email:
|
|
@@ -17,6 +17,7 @@ executables: []
|
|
|
17
17
|
extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
|
19
19
|
files:
|
|
20
|
+
- ".github/dependabot.yml"
|
|
20
21
|
- ".github/workflows/test.yml"
|
|
21
22
|
- ".gitignore"
|
|
22
23
|
- Gemfile
|
|
@@ -49,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
49
50
|
- !ruby/object:Gem::Version
|
|
50
51
|
version: '0'
|
|
51
52
|
requirements: []
|
|
52
|
-
rubygems_version: 3.
|
|
53
|
+
rubygems_version: 3.4.0.dev
|
|
53
54
|
signing_key:
|
|
54
55
|
specification_version: 4
|
|
55
56
|
summary: Topological sorting using Tarjan's algorithm
|