rubygems-update 3.3.26 → 3.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +35 -0
- data/CONTRIBUTING.md +24 -1
- data/Manifest.txt +30 -27
- data/POLICIES.md +10 -8
- data/README.md +2 -2
- data/bin/gem +1 -4
- data/bin/update_rubygems +1 -1
- data/bundler/CHANGELOG.md +59 -0
- data/bundler/README.md +2 -2
- data/bundler/bundler.gemspec +2 -2
- data/bundler/exe/bundle +1 -4
- data/bundler/lib/bundler/build_metadata.rb +2 -2
- data/bundler/lib/bundler/cli/add.rb +1 -1
- data/bundler/lib/bundler/cli/check.rb +1 -1
- data/bundler/lib/bundler/cli/common.rb +1 -0
- data/bundler/lib/bundler/cli/console.rb +2 -2
- data/bundler/lib/bundler/cli/doctor.rb +4 -6
- data/bundler/lib/bundler/cli/gem.rb +62 -40
- data/bundler/lib/bundler/cli/install.rb +2 -3
- data/bundler/lib/bundler/cli/lock.rb +8 -5
- data/bundler/lib/bundler/cli/outdated.rb +1 -3
- data/bundler/lib/bundler/cli/viz.rb +1 -1
- data/bundler/lib/bundler/cli.rb +43 -2
- data/bundler/lib/bundler/compact_index_client/cache.rb +1 -1
- data/bundler/lib/bundler/compact_index_client/updater.rb +40 -39
- data/bundler/lib/bundler/constants.rb +1 -1
- data/bundler/lib/bundler/definition.rb +61 -31
- data/bundler/lib/bundler/dependency.rb +12 -11
- data/bundler/lib/bundler/digest.rb +1 -1
- data/bundler/lib/bundler/dsl.rb +1 -1
- data/bundler/lib/bundler/env.rb +1 -1
- data/bundler/lib/bundler/environment_preserver.rb +1 -0
- data/bundler/lib/bundler/errors.rb +1 -11
- data/bundler/lib/bundler/fetcher/compact_index.rb +9 -11
- data/bundler/lib/bundler/fetcher/dependency.rb +1 -1
- data/bundler/lib/bundler/fetcher/downloader.rb +2 -5
- data/bundler/lib/bundler/fetcher.rb +2 -6
- data/bundler/lib/bundler/force_platform.rb +18 -0
- data/bundler/lib/bundler/friendly_errors.rb +0 -3
- data/bundler/lib/bundler/gem_version_promoter.rb +52 -86
- data/bundler/lib/bundler/graph.rb +3 -3
- data/bundler/lib/bundler/index.rb +5 -13
- data/bundler/lib/bundler/injector.rb +1 -1
- data/bundler/lib/bundler/inline.rb +2 -2
- data/bundler/lib/bundler/installer/parallel_installer.rb +0 -31
- data/bundler/lib/bundler/installer.rb +6 -16
- data/bundler/lib/bundler/lazy_specification.rb +5 -1
- data/bundler/lib/bundler/lockfile_parser.rb +5 -5
- data/bundler/lib/bundler/man/bundle-add.1 +1 -1
- data/bundler/lib/bundler/man/bundle-binstubs.1 +1 -1
- data/bundler/lib/bundler/man/bundle-cache.1 +1 -1
- data/bundler/lib/bundler/man/bundle-check.1 +1 -1
- data/bundler/lib/bundler/man/bundle-clean.1 +1 -1
- data/bundler/lib/bundler/man/bundle-config.1 +1 -1
- data/bundler/lib/bundler/man/bundle-console.1 +1 -1
- data/bundler/lib/bundler/man/bundle-doctor.1 +1 -1
- data/bundler/lib/bundler/man/bundle-exec.1 +1 -1
- data/bundler/lib/bundler/man/bundle-gem.1 +27 -37
- data/bundler/lib/bundler/man/bundle-gem.1.ronn +5 -5
- data/bundler/lib/bundler/man/bundle-help.1 +1 -1
- data/bundler/lib/bundler/man/bundle-info.1 +1 -1
- data/bundler/lib/bundler/man/bundle-init.1 +1 -1
- data/bundler/lib/bundler/man/bundle-inject.1 +1 -1
- data/bundler/lib/bundler/man/bundle-install.1 +1 -30
- data/bundler/lib/bundler/man/bundle-install.1.ronn +0 -29
- data/bundler/lib/bundler/man/bundle-list.1 +1 -1
- data/bundler/lib/bundler/man/bundle-lock.1 +1 -1
- data/bundler/lib/bundler/man/bundle-open.1 +1 -1
- data/bundler/lib/bundler/man/bundle-outdated.1 +1 -1
- data/bundler/lib/bundler/man/bundle-platform.1 +2 -2
- data/bundler/lib/bundler/man/bundle-platform.1.ronn +1 -1
- data/bundler/lib/bundler/man/bundle-plugin.1 +1 -1
- data/bundler/lib/bundler/man/bundle-pristine.1 +1 -1
- data/bundler/lib/bundler/man/bundle-remove.1 +1 -1
- data/bundler/lib/bundler/man/bundle-show.1 +1 -1
- data/bundler/lib/bundler/man/bundle-update.1 +1 -1
- data/bundler/lib/bundler/man/bundle-version.1 +1 -1
- data/bundler/lib/bundler/man/bundle-viz.1 +1 -1
- data/bundler/lib/bundler/man/bundle.1 +1 -1
- data/bundler/lib/bundler/man/gemfile.5 +1 -1
- data/bundler/lib/bundler/mirror.rb +5 -7
- data/bundler/lib/bundler/plugin/index.rb +4 -4
- data/bundler/lib/bundler/plugin/installer/rubygems.rb +0 -4
- data/bundler/lib/bundler/resolver/base.rb +7 -11
- data/bundler/lib/bundler/resolver/candidate.rb +92 -0
- data/bundler/lib/bundler/resolver/incompatibility.rb +15 -0
- data/bundler/lib/bundler/resolver/package.rb +63 -0
- data/bundler/lib/bundler/resolver/root.rb +25 -0
- data/bundler/lib/bundler/resolver/spec_group.rb +26 -36
- data/bundler/lib/bundler/resolver.rb +294 -277
- data/bundler/lib/bundler/rubygems_ext.rb +11 -6
- data/bundler/lib/bundler/rubygems_gem_installer.rb +4 -2
- data/bundler/lib/bundler/rubygems_integration.rb +1 -9
- data/bundler/lib/bundler/runtime.rb +1 -5
- data/bundler/lib/bundler/settings.rb +0 -6
- data/bundler/lib/bundler/shared_helpers.rb +1 -0
- data/bundler/lib/bundler/source/git/git_proxy.rb +193 -67
- data/bundler/lib/bundler/source/git.rb +15 -17
- data/bundler/lib/bundler/source/metadata.rb +0 -1
- data/bundler/lib/bundler/source/path/installer.rb +1 -22
- data/bundler/lib/bundler/source/path.rb +5 -5
- data/bundler/lib/bundler/source/rubygems.rb +13 -67
- data/bundler/lib/bundler/source_list.rb +8 -2
- data/bundler/lib/bundler/spec_set.rb +7 -9
- data/bundler/lib/bundler/templates/Executable +1 -1
- data/bundler/lib/bundler/templates/Executable.bundler +4 -9
- data/bundler/lib/bundler/templates/Executable.standalone +2 -0
- data/bundler/lib/bundler/templates/newgem/Cargo.toml.tt +7 -0
- data/bundler/lib/bundler/templates/newgem/Gemfile.tt +3 -0
- data/bundler/lib/bundler/templates/newgem/README.md.tt +6 -4
- data/bundler/lib/bundler/templates/newgem/Rakefile.tt +2 -1
- data/bundler/lib/bundler/templates/newgem/circleci/config.yml.tt +12 -0
- data/bundler/lib/bundler/templates/newgem/ext/newgem/Cargo.toml.tt +15 -0
- data/bundler/lib/bundler/templates/newgem/ext/newgem/{extconf.rb.tt → extconf-c.rb.tt} +0 -0
- data/bundler/lib/bundler/templates/newgem/ext/newgem/extconf-rust.rb.tt +6 -0
- data/bundler/lib/bundler/templates/newgem/ext/newgem/src/lib.rs.tt +12 -0
- data/bundler/lib/bundler/templates/newgem/github/workflows/main.yml.tt +10 -0
- data/bundler/lib/bundler/templates/newgem/gitignore.tt +3 -0
- data/bundler/lib/bundler/templates/newgem/gitlab-ci.yml.tt +8 -0
- data/bundler/lib/bundler/templates/newgem/newgem.gemspec.tt +8 -2
- data/bundler/lib/bundler/ui/shell.rb +35 -12
- data/bundler/lib/bundler/ui/silent.rb +21 -5
- data/bundler/lib/bundler/vendor/connection_pool/lib/connection_pool/timed_stack.rb +3 -3
- data/bundler/lib/bundler/vendor/connection_pool/lib/connection_pool/wrapper.rb +0 -1
- data/bundler/lib/bundler/vendor/connection_pool/lib/connection_pool.rb +3 -1
- data/bundler/lib/bundler/vendor/fileutils/lib/fileutils.rb +1350 -408
- data/bundler/lib/bundler/vendor/net-http-persistent/README.rdoc +1 -1
- data/bundler/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb +1 -1
- data/bundler/lib/bundler/vendor/pub_grub/LICENSE.txt +21 -0
- data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/assignment.rb +20 -0
- data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/basic_package_source.rb +189 -0
- data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/failure_writer.rb +182 -0
- data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/incompatibility.rb +151 -0
- data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/package.rb +43 -0
- data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/partial_solution.rb +121 -0
- data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/rubygems.rb +45 -0
- data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/solve_failure.rb +19 -0
- data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/static_package_source.rb +53 -0
- data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/term.rb +105 -0
- data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/version.rb +3 -0
- data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/version_constraint.rb +124 -0
- data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/version_range.rb +409 -0
- data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/version_solver.rb +240 -0
- data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub/version_union.rb +178 -0
- data/bundler/lib/bundler/vendor/pub_grub/lib/pub_grub.rb +31 -0
- data/bundler/lib/bundler/vendor/thor/lib/thor/shell/basic.rb +1 -1
- data/bundler/lib/bundler/vendor/uri/lib/uri/common.rb +64 -16
- data/bundler/lib/bundler/vendor/uri/lib/uri/file.rb +7 -1
- data/bundler/lib/bundler/vendor/uri/lib/uri/ftp.rb +2 -1
- data/bundler/lib/bundler/vendor/uri/lib/uri/generic.rb +27 -7
- data/bundler/lib/bundler/vendor/uri/lib/uri/http.rb +40 -2
- data/bundler/lib/bundler/vendor/uri/lib/uri/https.rb +2 -1
- data/bundler/lib/bundler/vendor/uri/lib/uri/ldap.rb +1 -1
- data/bundler/lib/bundler/vendor/uri/lib/uri/ldaps.rb +2 -1
- data/bundler/lib/bundler/vendor/uri/lib/uri/mailto.rb +2 -2
- data/bundler/lib/bundler/vendor/uri/lib/uri/rfc2396_parser.rb +13 -7
- data/bundler/lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb +10 -5
- data/bundler/lib/bundler/vendor/uri/lib/uri/version.rb +1 -1
- data/bundler/lib/bundler/vendor/uri/lib/uri/ws.rb +1 -2
- data/bundler/lib/bundler/vendor/uri/lib/uri/wss.rb +2 -1
- data/bundler/lib/bundler/vendor/uri/lib/uri.rb +3 -2
- data/bundler/lib/bundler/vendored_persistent.rb +1 -33
- data/bundler/lib/bundler/{vendored_tmpdir.rb → vendored_pub_grub.rb} +1 -1
- data/bundler/lib/bundler/version.rb +5 -1
- data/bundler/lib/bundler/worker.rb +5 -7
- data/bundler/lib/bundler.rb +20 -64
- data/lib/rubygems/command_manager.rb +2 -2
- data/lib/rubygems/commands/fetch_command.rb +1 -1
- data/lib/rubygems/commands/install_command.rb +7 -3
- data/lib/rubygems/commands/rdoc_command.rb +3 -2
- data/lib/rubygems/commands/setup_command.rb +2 -2
- data/lib/rubygems/commands/unpack_command.rb +1 -1
- data/lib/rubygems/commands/update_command.rb +1 -7
- data/lib/rubygems/config_file.rb +33 -0
- data/lib/rubygems/core_ext/kernel_warn.rb +1 -2
- data/lib/rubygems/defaults.rb +15 -1
- data/lib/rubygems/dependency.rb +4 -1
- data/lib/rubygems/dependency_installer.rb +24 -24
- data/lib/rubygems/exceptions.rb +1 -3
- data/lib/rubygems/ext/builder.rb +3 -3
- data/lib/rubygems/ext/cargo_builder/link_flag_converter.rb +9 -5
- data/lib/rubygems/ext/cargo_builder.rb +15 -20
- data/lib/rubygems/ext/ext_conf_builder.rb +2 -0
- data/lib/rubygems/indexer.rb +1 -1
- data/lib/rubygems/installer.rb +5 -5
- data/lib/rubygems/optparse/lib/optparse.rb +20 -15
- data/lib/rubygems/package/tar_header.rb +11 -11
- data/lib/rubygems/platform.rb +0 -2
- data/lib/rubygems/request_set/gem_dependency_api.rb +104 -104
- data/lib/rubygems/requirement.rb +7 -7
- data/lib/rubygems/resolver/installer_set.rb +1 -1
- data/lib/rubygems/resolver/molinillo/lib/molinillo/dependency_graph.rb +1 -1
- data/lib/rubygems/resolver/molinillo/lib/molinillo/errors.rb +32 -26
- data/lib/rubygems/resolver/molinillo/lib/molinillo/gem_metadata.rb +1 -1
- data/lib/rubygems/security/policies.rb +40 -40
- data/lib/rubygems/security/trust_dir.rb +1 -1
- data/lib/rubygems/security.rb +3 -16
- data/lib/rubygems/source.rb +2 -2
- data/lib/rubygems/specification.rb +37 -49
- data/lib/rubygems/specification_policy.rb +14 -0
- data/lib/rubygems/stub_specification.rb +2 -2
- data/lib/rubygems/text.rb +1 -1
- data/lib/rubygems/tsort/lib/tsort.rb +308 -310
- data/lib/rubygems/update_suggestion.rb +69 -0
- data/lib/rubygems/util.rb +1 -5
- data/lib/rubygems/validator.rb +1 -1
- data/lib/rubygems.rb +8 -3
- data/rubygems-update.gemspec +2 -2
- data/test/rubygems/helper.rb +7 -3
- data/test/rubygems/test_bundled_ca.rb +1 -1
- data/test/rubygems/test_exit.rb +6 -0
- data/test/rubygems/test_gem.rb +4 -9
- data/test/rubygems/test_gem_bundler_version_finder.rb +2 -1
- data/test/rubygems/test_gem_command_manager.rb +1 -1
- data/test/rubygems/test_gem_commands_install_command.rb +19 -0
- data/test/rubygems/test_gem_commands_setup_command.rb +1 -8
- data/test/rubygems/test_gem_commands_update_command.rb +6 -6
- data/test/rubygems/test_gem_config_file.rb +1 -1
- data/test/rubygems/test_gem_dependency.rb +2 -0
- data/test/rubygems/test_gem_ext_builder.rb +3 -3
- data/test/rubygems/test_gem_ext_cargo_builder/custom_name/Cargo.lock +22 -32
- data/test/rubygems/test_gem_ext_cargo_builder/custom_name/Cargo.toml +1 -1
- data/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/Cargo.lock +22 -32
- data/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/Cargo.toml +1 -1
- data/test/rubygems/test_gem_ext_cargo_builder/rust_ruby_example/src/lib.rs +12 -0
- data/test/rubygems/test_gem_ext_cargo_builder.rb +22 -27
- data/test/rubygems/test_gem_ext_cargo_builder_link_flag_converter.rb +16 -16
- data/test/rubygems/test_gem_ext_cargo_builder_unit.rb +0 -10
- data/test/rubygems/test_gem_indexer.rb +39 -20
- data/test/rubygems/test_gem_installer.rb +68 -2
- data/test/rubygems/test_gem_package_tar_header.rb +13 -13
- data/test/rubygems/test_gem_platform.rb +59 -60
- data/test/rubygems/test_gem_remote_fetcher.rb +4 -4
- data/test/rubygems/test_gem_request_set.rb +2 -2
- data/test/rubygems/test_gem_requirement.rb +1 -1
- data/test/rubygems/test_gem_resolver_api_set.rb +12 -12
- data/test/rubygems/test_gem_resolver_api_specification.rb +19 -19
- data/test/rubygems/test_gem_resolver_git_specification.rb +1 -1
- data/test/rubygems/test_gem_security_policy.rb +10 -10
- data/test/rubygems/test_gem_security_trust_dir.rb +2 -2
- data/test/rubygems/test_gem_specification.rb +50 -37
- data/test/rubygems/test_gem_uninstaller.rb +1 -1
- data/test/rubygems/test_gem_update_suggestion.rb +208 -0
- data/test/rubygems/test_kernel.rb +10 -8
- data/test/rubygems/test_require.rb +70 -55
- metadata +34 -31
- data/bundler/lib/bundler/templates/newgem/travis.yml.tt +0 -6
- data/bundler/lib/bundler/vendor/molinillo/LICENSE +0 -9
- data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/delegates/resolution_state.rb +0 -57
- data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/delegates/specification_provider.rb +0 -88
- data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/action.rb +0 -36
- data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_edge_no_circular.rb +0 -66
- data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/add_vertex.rb +0 -62
- data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/delete_edge.rb +0 -63
- data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/detach_vertex_named.rb +0 -61
- data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/log.rb +0 -126
- data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/set_payload.rb +0 -46
- data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/tag.rb +0 -36
- data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph/vertex.rb +0 -164
- data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb +0 -255
- data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/errors.rb +0 -149
- data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/gem_metadata.rb +0 -6
- data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/modules/specification_provider.rb +0 -112
- data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/modules/ui.rb +0 -67
- data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/resolution.rb +0 -839
- data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/resolver.rb +0 -46
- data/bundler/lib/bundler/vendor/molinillo/lib/molinillo/state.rb +0 -58
- data/bundler/lib/bundler/vendor/molinillo/lib/molinillo.rb +0 -11
- data/bundler/lib/bundler/vendor/tmpdir/lib/tmpdir.rb +0 -154
- data/bundler/lib/bundler/vendored_molinillo.rb +0 -4
- data/bundler/lib/bundler/version_ranges.rb +0 -122
@@ -121,334 +121,332 @@
|
|
121
121
|
# <em>SIAM Journal on Computing</em>, Vol. 1, No. 2, pp. 146-160, June 1972.
|
122
122
|
#
|
123
123
|
|
124
|
-
module Gem
|
125
|
-
|
126
|
-
|
127
|
-
end
|
128
|
-
|
129
|
-
# Returns a topologically sorted array of nodes.
|
130
|
-
# The array is sorted from children to parents, i.e.
|
131
|
-
# the first element has no child and the last node has no parent.
|
132
|
-
#
|
133
|
-
# If there is a cycle, Gem::TSort::Cyclic is raised.
|
134
|
-
#
|
135
|
-
# class G
|
136
|
-
# include Gem::TSort
|
137
|
-
# def initialize(g)
|
138
|
-
# @g = g
|
139
|
-
# end
|
140
|
-
# def tsort_each_child(n, &b) @g[n].each(&b) end
|
141
|
-
# def tsort_each_node(&b) @g.each_key(&b) end
|
142
|
-
# end
|
143
|
-
#
|
144
|
-
# graph = G.new({1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]})
|
145
|
-
# p graph.tsort #=> [4, 2, 3, 1]
|
146
|
-
#
|
147
|
-
# graph = G.new({1=>[2], 2=>[3, 4], 3=>[2], 4=>[]})
|
148
|
-
# p graph.tsort # raises Gem::TSort::Cyclic
|
149
|
-
#
|
150
|
-
def tsort
|
151
|
-
each_node = method(:tsort_each_node)
|
152
|
-
each_child = method(:tsort_each_child)
|
153
|
-
Gem::TSort.tsort(each_node, each_child)
|
154
|
-
end
|
124
|
+
module Gem::TSort
|
125
|
+
class Cyclic < StandardError
|
126
|
+
end
|
155
127
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
128
|
+
# Returns a topologically sorted array of nodes.
|
129
|
+
# The array is sorted from children to parents, i.e.
|
130
|
+
# the first element has no child and the last node has no parent.
|
131
|
+
#
|
132
|
+
# If there is a cycle, Gem::TSort::Cyclic is raised.
|
133
|
+
#
|
134
|
+
# class G
|
135
|
+
# include Gem::TSort
|
136
|
+
# def initialize(g)
|
137
|
+
# @g = g
|
138
|
+
# end
|
139
|
+
# def tsort_each_child(n, &b) @g[n].each(&b) end
|
140
|
+
# def tsort_each_node(&b) @g.each_key(&b) end
|
141
|
+
# end
|
142
|
+
#
|
143
|
+
# graph = G.new({1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]})
|
144
|
+
# p graph.tsort #=> [4, 2, 3, 1]
|
145
|
+
#
|
146
|
+
# graph = G.new({1=>[2], 2=>[3, 4], 3=>[2], 4=>[]})
|
147
|
+
# p graph.tsort # raises Gem::TSort::Cyclic
|
148
|
+
#
|
149
|
+
def tsort
|
150
|
+
each_node = method(:tsort_each_node)
|
151
|
+
each_child = method(:tsort_each_child)
|
152
|
+
Gem::TSort.tsort(each_node, each_child)
|
153
|
+
end
|
179
154
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
def tsort_each(&block) # :yields: node
|
204
|
-
each_node = method(:tsort_each_node)
|
205
|
-
each_child = method(:tsort_each_child)
|
206
|
-
Gem::TSort.tsort_each(each_node, each_child, &block)
|
207
|
-
end
|
155
|
+
# Returns a topologically sorted array of nodes.
|
156
|
+
# The array is sorted from children to parents, i.e.
|
157
|
+
# the first element has no child and the last node has no parent.
|
158
|
+
#
|
159
|
+
# The graph is represented by _each_node_ and _each_child_.
|
160
|
+
# _each_node_ should have +call+ method which yields for each node in the graph.
|
161
|
+
# _each_child_ should have +call+ method which takes a node argument and yields for each child node.
|
162
|
+
#
|
163
|
+
# If there is a cycle, Gem::TSort::Cyclic is raised.
|
164
|
+
#
|
165
|
+
# g = {1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]}
|
166
|
+
# each_node = lambda {|&b| g.each_key(&b) }
|
167
|
+
# each_child = lambda {|n, &b| g[n].each(&b) }
|
168
|
+
# p Gem::TSort.tsort(each_node, each_child) #=> [4, 2, 3, 1]
|
169
|
+
#
|
170
|
+
# g = {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}
|
171
|
+
# each_node = lambda {|&b| g.each_key(&b) }
|
172
|
+
# each_child = lambda {|n, &b| g[n].each(&b) }
|
173
|
+
# p Gem::TSort.tsort(each_node, each_child) # raises Gem::TSort::Cyclic
|
174
|
+
#
|
175
|
+
def self.tsort(each_node, each_child)
|
176
|
+
tsort_each(each_node, each_child).to_a
|
177
|
+
end
|
208
178
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
179
|
+
# The iterator version of the #tsort method.
|
180
|
+
# <tt><em>obj</em>.tsort_each</tt> is similar to <tt><em>obj</em>.tsort.each</tt>, but
|
181
|
+
# modification of _obj_ during the iteration may lead to unexpected results.
|
182
|
+
#
|
183
|
+
# #tsort_each returns +nil+.
|
184
|
+
# If there is a cycle, Gem::TSort::Cyclic is raised.
|
185
|
+
#
|
186
|
+
# class G
|
187
|
+
# include Gem::TSort
|
188
|
+
# def initialize(g)
|
189
|
+
# @g = g
|
190
|
+
# end
|
191
|
+
# def tsort_each_child(n, &b) @g[n].each(&b) end
|
192
|
+
# def tsort_each_node(&b) @g.each_key(&b) end
|
193
|
+
# end
|
194
|
+
#
|
195
|
+
# graph = G.new({1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]})
|
196
|
+
# graph.tsort_each {|n| p n }
|
197
|
+
# #=> 4
|
198
|
+
# # 2
|
199
|
+
# # 3
|
200
|
+
# # 1
|
201
|
+
#
|
202
|
+
def tsort_each(&block) # :yields: node
|
203
|
+
each_node = method(:tsort_each_node)
|
204
|
+
each_child = method(:tsort_each_child)
|
205
|
+
Gem::TSort.tsort_each(each_node, each_child, &block)
|
206
|
+
end
|
226
207
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
208
|
+
# The iterator version of the Gem::TSort.tsort method.
|
209
|
+
#
|
210
|
+
# The graph is represented by _each_node_ and _each_child_.
|
211
|
+
# _each_node_ should have +call+ method which yields for each node in the graph.
|
212
|
+
# _each_child_ should have +call+ method which takes a node argument and yields for each child node.
|
213
|
+
#
|
214
|
+
# g = {1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]}
|
215
|
+
# each_node = lambda {|&b| g.each_key(&b) }
|
216
|
+
# each_child = lambda {|n, &b| g[n].each(&b) }
|
217
|
+
# Gem::TSort.tsort_each(each_node, each_child) {|n| p n }
|
218
|
+
# #=> 4
|
219
|
+
# # 2
|
220
|
+
# # 3
|
221
|
+
# # 1
|
222
|
+
#
|
223
|
+
def self.tsort_each(each_node, each_child) # :yields: node
|
224
|
+
return to_enum(__method__, each_node, each_child) unless block_given?
|
235
225
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
# end
|
245
|
-
# def tsort_each_child(n, &b) @g[n].each(&b) end
|
246
|
-
# def tsort_each_node(&b) @g.each_key(&b) end
|
247
|
-
# end
|
248
|
-
#
|
249
|
-
# graph = G.new({1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]})
|
250
|
-
# p graph.strongly_connected_components #=> [[4], [2], [3], [1]]
|
251
|
-
#
|
252
|
-
# graph = G.new({1=>[2], 2=>[3, 4], 3=>[2], 4=>[]})
|
253
|
-
# p graph.strongly_connected_components #=> [[4], [2, 3], [1]]
|
254
|
-
#
|
255
|
-
def strongly_connected_components
|
256
|
-
each_node = method(:tsort_each_node)
|
257
|
-
each_child = method(:tsort_each_child)
|
258
|
-
Gem::TSort.strongly_connected_components(each_node, each_child)
|
259
|
-
end
|
226
|
+
each_strongly_connected_component(each_node, each_child) {|component|
|
227
|
+
if component.size == 1
|
228
|
+
yield component.first
|
229
|
+
else
|
230
|
+
raise Cyclic.new("topological sort failed: #{component.inspect}")
|
231
|
+
end
|
232
|
+
}
|
233
|
+
end
|
260
234
|
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
235
|
+
# Returns strongly connected components as an array of arrays of nodes.
|
236
|
+
# The array is sorted from children to parents.
|
237
|
+
# Each elements of the array represents a strongly connected component.
|
238
|
+
#
|
239
|
+
# class G
|
240
|
+
# include Gem::TSort
|
241
|
+
# def initialize(g)
|
242
|
+
# @g = g
|
243
|
+
# end
|
244
|
+
# def tsort_each_child(n, &b) @g[n].each(&b) end
|
245
|
+
# def tsort_each_node(&b) @g.each_key(&b) end
|
246
|
+
# end
|
247
|
+
#
|
248
|
+
# graph = G.new({1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]})
|
249
|
+
# p graph.strongly_connected_components #=> [[4], [2], [3], [1]]
|
250
|
+
#
|
251
|
+
# graph = G.new({1=>[2], 2=>[3, 4], 3=>[2], 4=>[]})
|
252
|
+
# p graph.strongly_connected_components #=> [[4], [2, 3], [1]]
|
253
|
+
#
|
254
|
+
def strongly_connected_components
|
255
|
+
each_node = method(:tsort_each_node)
|
256
|
+
each_child = method(:tsort_each_child)
|
257
|
+
Gem::TSort.strongly_connected_components(each_node, each_child)
|
258
|
+
end
|
284
259
|
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
# graph = G.new({1=>[2], 2=>[3, 4], 3=>[2], 4=>[]})
|
309
|
-
# graph.each_strongly_connected_component {|scc| p scc }
|
310
|
-
# #=> [4]
|
311
|
-
# # [2, 3]
|
312
|
-
# # [1]
|
313
|
-
#
|
314
|
-
def each_strongly_connected_component(&block) # :yields: nodes
|
315
|
-
each_node = method(:tsort_each_node)
|
316
|
-
each_child = method(:tsort_each_child)
|
317
|
-
Gem::TSort.each_strongly_connected_component(each_node, each_child, &block)
|
318
|
-
end
|
260
|
+
# Returns strongly connected components as an array of arrays of nodes.
|
261
|
+
# The array is sorted from children to parents.
|
262
|
+
# Each elements of the array represents a strongly connected component.
|
263
|
+
#
|
264
|
+
# The graph is represented by _each_node_ and _each_child_.
|
265
|
+
# _each_node_ should have +call+ method which yields for each node in the graph.
|
266
|
+
# _each_child_ should have +call+ method which takes a node argument and yields for each child node.
|
267
|
+
#
|
268
|
+
# g = {1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]}
|
269
|
+
# each_node = lambda {|&b| g.each_key(&b) }
|
270
|
+
# each_child = lambda {|n, &b| g[n].each(&b) }
|
271
|
+
# p Gem::TSort.strongly_connected_components(each_node, each_child)
|
272
|
+
# #=> [[4], [2], [3], [1]]
|
273
|
+
#
|
274
|
+
# g = {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}
|
275
|
+
# each_node = lambda {|&b| g.each_key(&b) }
|
276
|
+
# each_child = lambda {|n, &b| g[n].each(&b) }
|
277
|
+
# p Gem::TSort.strongly_connected_components(each_node, each_child)
|
278
|
+
# #=> [[4], [2, 3], [1]]
|
279
|
+
#
|
280
|
+
def self.strongly_connected_components(each_node, each_child)
|
281
|
+
each_strongly_connected_component(each_node, each_child).to_a
|
282
|
+
end
|
319
283
|
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
284
|
+
# The iterator version of the #strongly_connected_components method.
|
285
|
+
# <tt><em>obj</em>.each_strongly_connected_component</tt> is similar to
|
286
|
+
# <tt><em>obj</em>.strongly_connected_components.each</tt>, but
|
287
|
+
# modification of _obj_ during the iteration may lead to unexpected results.
|
288
|
+
#
|
289
|
+
# #each_strongly_connected_component returns +nil+.
|
290
|
+
#
|
291
|
+
# class G
|
292
|
+
# include Gem::TSort
|
293
|
+
# def initialize(g)
|
294
|
+
# @g = g
|
295
|
+
# end
|
296
|
+
# def tsort_each_child(n, &b) @g[n].each(&b) end
|
297
|
+
# def tsort_each_node(&b) @g.each_key(&b) end
|
298
|
+
# end
|
299
|
+
#
|
300
|
+
# graph = G.new({1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]})
|
301
|
+
# graph.each_strongly_connected_component {|scc| p scc }
|
302
|
+
# #=> [4]
|
303
|
+
# # [2]
|
304
|
+
# # [3]
|
305
|
+
# # [1]
|
306
|
+
#
|
307
|
+
# graph = G.new({1=>[2], 2=>[3, 4], 3=>[2], 4=>[]})
|
308
|
+
# graph.each_strongly_connected_component {|scc| p scc }
|
309
|
+
# #=> [4]
|
310
|
+
# # [2, 3]
|
311
|
+
# # [1]
|
312
|
+
#
|
313
|
+
def each_strongly_connected_component(&block) # :yields: nodes
|
314
|
+
each_node = method(:tsort_each_node)
|
315
|
+
each_child = method(:tsort_each_child)
|
316
|
+
Gem::TSort.each_strongly_connected_component(each_node, each_child, &block)
|
317
|
+
end
|
345
318
|
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
319
|
+
# The iterator version of the Gem::TSort.strongly_connected_components method.
|
320
|
+
#
|
321
|
+
# The graph is represented by _each_node_ and _each_child_.
|
322
|
+
# _each_node_ should have +call+ method which yields for each node in the graph.
|
323
|
+
# _each_child_ should have +call+ method which takes a node argument and yields for each child node.
|
324
|
+
#
|
325
|
+
# g = {1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]}
|
326
|
+
# each_node = lambda {|&b| g.each_key(&b) }
|
327
|
+
# each_child = lambda {|n, &b| g[n].each(&b) }
|
328
|
+
# Gem::TSort.each_strongly_connected_component(each_node, each_child) {|scc| p scc }
|
329
|
+
# #=> [4]
|
330
|
+
# # [2]
|
331
|
+
# # [3]
|
332
|
+
# # [1]
|
333
|
+
#
|
334
|
+
# g = {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}
|
335
|
+
# each_node = lambda {|&b| g.each_key(&b) }
|
336
|
+
# each_child = lambda {|n, &b| g[n].each(&b) }
|
337
|
+
# Gem::TSort.each_strongly_connected_component(each_node, each_child) {|scc| p scc }
|
338
|
+
# #=> [4]
|
339
|
+
# # [2, 3]
|
340
|
+
# # [1]
|
341
|
+
#
|
342
|
+
def self.each_strongly_connected_component(each_node, each_child) # :yields: nodes
|
343
|
+
return to_enum(__method__, each_node, each_child) unless block_given?
|
357
344
|
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
# end
|
370
|
-
# def tsort_each_child(n, &b) @g[n].each(&b) end
|
371
|
-
# def tsort_each_node(&b) @g.each_key(&b) end
|
372
|
-
# end
|
373
|
-
#
|
374
|
-
# graph = G.new({1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]})
|
375
|
-
# graph.each_strongly_connected_component_from(2) {|scc| p scc }
|
376
|
-
# #=> [4]
|
377
|
-
# # [2]
|
378
|
-
#
|
379
|
-
# graph = G.new({1=>[2], 2=>[3, 4], 3=>[2], 4=>[]})
|
380
|
-
# graph.each_strongly_connected_component_from(2) {|scc| p scc }
|
381
|
-
# #=> [4]
|
382
|
-
# # [2, 3]
|
383
|
-
#
|
384
|
-
def each_strongly_connected_component_from(node, id_map={}, stack=[], &block) # :yields: nodes
|
385
|
-
Gem::TSort.each_strongly_connected_component_from(node, method(:tsort_each_child), id_map, stack, &block)
|
386
|
-
end
|
345
|
+
id_map = {}
|
346
|
+
stack = []
|
347
|
+
each_node.call {|node|
|
348
|
+
unless id_map.include? node
|
349
|
+
each_strongly_connected_component_from(node, each_child, id_map, stack) {|c|
|
350
|
+
yield c
|
351
|
+
}
|
352
|
+
end
|
353
|
+
}
|
354
|
+
nil
|
355
|
+
end
|
387
356
|
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
357
|
+
# Iterates over strongly connected component in the subgraph reachable from
|
358
|
+
# _node_.
|
359
|
+
#
|
360
|
+
# Return value is unspecified.
|
361
|
+
#
|
362
|
+
# #each_strongly_connected_component_from doesn't call #tsort_each_node.
|
363
|
+
#
|
364
|
+
# class G
|
365
|
+
# include Gem::TSort
|
366
|
+
# def initialize(g)
|
367
|
+
# @g = g
|
368
|
+
# end
|
369
|
+
# def tsort_each_child(n, &b) @g[n].each(&b) end
|
370
|
+
# def tsort_each_node(&b) @g.each_key(&b) end
|
371
|
+
# end
|
372
|
+
#
|
373
|
+
# graph = G.new({1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]})
|
374
|
+
# graph.each_strongly_connected_component_from(2) {|scc| p scc }
|
375
|
+
# #=> [4]
|
376
|
+
# # [2]
|
377
|
+
#
|
378
|
+
# graph = G.new({1=>[2], 2=>[3, 4], 3=>[2], 4=>[]})
|
379
|
+
# graph.each_strongly_connected_component_from(2) {|scc| p scc }
|
380
|
+
# #=> [4]
|
381
|
+
# # [2, 3]
|
382
|
+
#
|
383
|
+
def each_strongly_connected_component_from(node, id_map={}, stack=[], &block) # :yields: nodes
|
384
|
+
Gem::TSort.each_strongly_connected_component_from(node, method(:tsort_each_child), id_map, stack, &block)
|
385
|
+
end
|
411
386
|
|
412
|
-
|
413
|
-
|
414
|
-
|
387
|
+
# Iterates over strongly connected components in a graph.
|
388
|
+
# The graph is represented by _node_ and _each_child_.
|
389
|
+
#
|
390
|
+
# _node_ is the first node.
|
391
|
+
# _each_child_ should have +call+ method which takes a node argument
|
392
|
+
# and yields for each child node.
|
393
|
+
#
|
394
|
+
# Return value is unspecified.
|
395
|
+
#
|
396
|
+
# #Gem::TSort.each_strongly_connected_component_from is a class method and
|
397
|
+
# it doesn't need a class to represent a graph which includes Gem::TSort.
|
398
|
+
#
|
399
|
+
# graph = {1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}
|
400
|
+
# each_child = lambda {|n, &b| graph[n].each(&b) }
|
401
|
+
# Gem::TSort.each_strongly_connected_component_from(1, each_child) {|scc|
|
402
|
+
# p scc
|
403
|
+
# }
|
404
|
+
# #=> [4]
|
405
|
+
# # [2, 3]
|
406
|
+
# # [1]
|
407
|
+
#
|
408
|
+
def self.each_strongly_connected_component_from(node, each_child, id_map={}, stack=[]) # :yields: nodes
|
409
|
+
return to_enum(__method__, node, each_child, id_map, stack) unless block_given?
|
415
410
|
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
minimum_id = child_id if child_id && child_id < minimum_id
|
420
|
-
else
|
421
|
-
sub_minimum_id =
|
422
|
-
Gem::TSort.each_strongly_connected_component_from(child, each_child, id_map, stack) {|c|
|
423
|
-
yield c
|
424
|
-
}
|
425
|
-
minimum_id = sub_minimum_id if sub_minimum_id < minimum_id
|
426
|
-
end
|
427
|
-
}
|
411
|
+
minimum_id = node_id = id_map[node] = id_map.size
|
412
|
+
stack_length = stack.length
|
413
|
+
stack << node
|
428
414
|
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
415
|
+
each_child.call(node) {|child|
|
416
|
+
if id_map.include? child
|
417
|
+
child_id = id_map[child]
|
418
|
+
minimum_id = child_id if child_id && child_id < minimum_id
|
419
|
+
else
|
420
|
+
sub_minimum_id =
|
421
|
+
each_strongly_connected_component_from(child, each_child, id_map, stack) {|c|
|
422
|
+
yield c
|
423
|
+
}
|
424
|
+
minimum_id = sub_minimum_id if sub_minimum_id < minimum_id
|
433
425
|
end
|
426
|
+
}
|
434
427
|
|
435
|
-
|
428
|
+
if node_id == minimum_id
|
429
|
+
component = stack.slice!(stack_length .. -1)
|
430
|
+
component.each {|n| id_map[n] = nil}
|
431
|
+
yield component
|
436
432
|
end
|
437
433
|
|
438
|
-
|
439
|
-
|
440
|
-
# #tsort_each_node is used to iterate for all nodes over a graph.
|
441
|
-
#
|
442
|
-
def tsort_each_node # :yields: node
|
443
|
-
raise NotImplementedError.new
|
444
|
-
end
|
434
|
+
minimum_id
|
435
|
+
end
|
445
436
|
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
437
|
+
# Should be implemented by a extended class.
|
438
|
+
#
|
439
|
+
# #tsort_each_node is used to iterate for all nodes over a graph.
|
440
|
+
#
|
441
|
+
def tsort_each_node # :yields: node
|
442
|
+
raise NotImplementedError.new
|
443
|
+
end
|
444
|
+
|
445
|
+
# Should be implemented by a extended class.
|
446
|
+
#
|
447
|
+
# #tsort_each_child is used to iterate for child nodes of _node_.
|
448
|
+
#
|
449
|
+
def tsort_each_child(node) # :yields: child
|
450
|
+
raise NotImplementedError.new
|
453
451
|
end
|
454
452
|
end
|