tsort 0.1.0 → 0.2.0
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 +11 -6
- data/lib/tsort.rb +13 -10
- data/tsort.gemspec +9 -2
- 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: 527cd18fa865da8f384920a5c3795381a8247d47f196cc6505ffa6d84b549c47
|
4
|
+
data.tar.gz: 2c6dac335ffb26fb3a4adbae6019673d1ead73be51a3421a92e420244fa8e61a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46f71bedfd194d0dcc880efa7397d7dd30b481c42dc032137e34671d022c27a7562c9c09589098839493e2f8f44d7034005b3836e583ffa3c6d20d24ea27ad67
|
7
|
+
data.tar.gz: 528ec3b30bca156d3d61ade5f5dc34086bc80921635df5a3bbba1f68b1073b2cf3f2946585e4083087b6ff20c7724dede3e087d63e129cd03427108b3549358b
|
data/.github/workflows/test.yml
CHANGED
@@ -3,22 +3,27 @@ name: test
|
|
3
3
|
on: [push, pull_request]
|
4
4
|
|
5
5
|
jobs:
|
6
|
-
|
6
|
+
ruby-versions:
|
7
|
+
uses: ruby/actions/.github/workflows/ruby_versions.yml@master
|
8
|
+
with:
|
9
|
+
engine: cruby
|
10
|
+
min_version: 2.5
|
11
|
+
|
12
|
+
test:
|
13
|
+
needs: ruby-versions
|
7
14
|
name: build (${{ matrix.ruby }} / ${{ matrix.os }})
|
8
15
|
strategy:
|
9
16
|
matrix:
|
10
|
-
ruby:
|
17
|
+
ruby: ${{ fromJson(needs.ruby-versions.outputs.versions) }}
|
11
18
|
os: [ ubuntu-latest, macos-latest ]
|
12
19
|
runs-on: ${{ matrix.os }}
|
13
20
|
steps:
|
14
|
-
- uses: actions/checkout@
|
21
|
+
- uses: actions/checkout@v4
|
15
22
|
- name: Set up Ruby
|
16
23
|
uses: ruby/setup-ruby@v1
|
17
24
|
with:
|
18
25
|
ruby-version: ${{ matrix.ruby }}
|
19
26
|
- name: Install dependencies
|
20
|
-
run:
|
21
|
-
gem install bundler --no-document
|
22
|
-
bundle install
|
27
|
+
run: bundle install
|
23
28
|
- name: Run test
|
24
29
|
run: rake test
|
data/lib/tsort.rb
CHANGED
@@ -122,6 +122,9 @@
|
|
122
122
|
#
|
123
123
|
|
124
124
|
module TSort
|
125
|
+
|
126
|
+
VERSION = "0.2.0"
|
127
|
+
|
125
128
|
class Cyclic < StandardError
|
126
129
|
end
|
127
130
|
|
@@ -172,8 +175,8 @@ module TSort
|
|
172
175
|
# each_child = lambda {|n, &b| g[n].each(&b) }
|
173
176
|
# p TSort.tsort(each_node, each_child) # raises TSort::Cyclic
|
174
177
|
#
|
175
|
-
def
|
176
|
-
|
178
|
+
def self.tsort(each_node, each_child)
|
179
|
+
tsort_each(each_node, each_child).to_a
|
177
180
|
end
|
178
181
|
|
179
182
|
# The iterator version of the #tsort method.
|
@@ -220,10 +223,10 @@ module TSort
|
|
220
223
|
# # 3
|
221
224
|
# # 1
|
222
225
|
#
|
223
|
-
def
|
226
|
+
def self.tsort_each(each_node, each_child) # :yields: node
|
224
227
|
return to_enum(__method__, each_node, each_child) unless block_given?
|
225
228
|
|
226
|
-
|
229
|
+
each_strongly_connected_component(each_node, each_child) {|component|
|
227
230
|
if component.size == 1
|
228
231
|
yield component.first
|
229
232
|
else
|
@@ -277,8 +280,8 @@ module TSort
|
|
277
280
|
# p TSort.strongly_connected_components(each_node, each_child)
|
278
281
|
# #=> [[4], [2, 3], [1]]
|
279
282
|
#
|
280
|
-
def
|
281
|
-
|
283
|
+
def self.strongly_connected_components(each_node, each_child)
|
284
|
+
each_strongly_connected_component(each_node, each_child).to_a
|
282
285
|
end
|
283
286
|
|
284
287
|
# The iterator version of the #strongly_connected_components method.
|
@@ -339,14 +342,14 @@ module TSort
|
|
339
342
|
# # [2, 3]
|
340
343
|
# # [1]
|
341
344
|
#
|
342
|
-
def
|
345
|
+
def self.each_strongly_connected_component(each_node, each_child) # :yields: nodes
|
343
346
|
return to_enum(__method__, each_node, each_child) unless block_given?
|
344
347
|
|
345
348
|
id_map = {}
|
346
349
|
stack = []
|
347
350
|
each_node.call {|node|
|
348
351
|
unless id_map.include? node
|
349
|
-
|
352
|
+
each_strongly_connected_component_from(node, each_child, id_map, stack) {|c|
|
350
353
|
yield c
|
351
354
|
}
|
352
355
|
end
|
@@ -405,7 +408,7 @@ module TSort
|
|
405
408
|
# # [2, 3]
|
406
409
|
# # [1]
|
407
410
|
#
|
408
|
-
def
|
411
|
+
def self.each_strongly_connected_component_from(node, each_child, id_map={}, stack=[]) # :yields: nodes
|
409
412
|
return to_enum(__method__, node, each_child, id_map, stack) unless block_given?
|
410
413
|
|
411
414
|
minimum_id = node_id = id_map[node] = id_map.size
|
@@ -418,7 +421,7 @@ module TSort
|
|
418
421
|
minimum_id = child_id if child_id && child_id < minimum_id
|
419
422
|
else
|
420
423
|
sub_minimum_id =
|
421
|
-
|
424
|
+
each_strongly_connected_component_from(child, each_child, id_map, stack) {|c|
|
422
425
|
yield c
|
423
426
|
}
|
424
427
|
minimum_id = sub_minimum_id if sub_minimum_id < minimum_id
|
data/tsort.gemspec
CHANGED
@@ -1,6 +1,13 @@
|
|
1
|
+
name = File.basename(__FILE__, ".gemspec")
|
2
|
+
version = ["lib", Array.new(name.count("-")+1).join("/")].find do |dir|
|
3
|
+
break File.foreach(File.join(__dir__, dir, "#{name.tr('-', '/')}.rb")) do |line|
|
4
|
+
/^\s*VERSION\s*=\s*"(.*)"/ =~ line and break $1
|
5
|
+
end rescue nil
|
6
|
+
end
|
7
|
+
|
1
8
|
Gem::Specification.new do |spec|
|
2
|
-
spec.name =
|
3
|
-
spec.version =
|
9
|
+
spec.name = name
|
10
|
+
spec.version = version
|
4
11
|
spec.authors = ["Tanaka Akira"]
|
5
12
|
spec.email = ["akr@fsij.org"]
|
6
13
|
|
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.
|
4
|
+
version: 0.2.0
|
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: 2023-11-07 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.5.0.dev
|
53
54
|
signing_key:
|
54
55
|
specification_version: 4
|
55
56
|
summary: Topological sorting using Tarjan's algorithm
|