ac-library-rb 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/README.ja.md +79 -4
- data/README.md +63 -0
- data/Rakefile +2 -1
- data/ac-library-rb.gemspec +2 -2
- data/bin/lock_lib.rb +8 -6
- data/lib/ac-library-rb/version.rb +1 -1
- data/lib/modint.rb +3 -1
- data/lib/suffix_array.rb +8 -8
- data/lib_lock/ac-library-rb/modint.rb +3 -1
- data/lib_lock/ac-library-rb/suffix_array.rb +8 -8
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f2e1122b67c3de38764556c098f3baca940daf337deae414b37ca57c0d23066
|
4
|
+
data.tar.gz: a5623bda479b49cd40885aa202b64c3075b292db06c3f0b2fea6ba2882e8e281
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f38c20da10aa7b69cc140b8c79e7f3152271b77fe265f6ad8b93114a986b714b7b004cec5365477d6661192ed319da126868e8151ac00236633a5e5c6ac22a6
|
7
|
+
data.tar.gz: ed0b8ff7db0eff11fdf751acba9b111488d14babb845c747fb7856888d600b34e5f53208b6aa2fdbddb9ad1001996040dafb6a240498d59a5517fd6d8dfa0229
|
data/.rubocop.yml
CHANGED
data/README.ja.md
CHANGED
@@ -15,13 +15,88 @@ ACLの詳細は、以下をご覧ください.
|
|
15
15
|
|
16
16
|
[ライブラリ目次: index.md](https://github.com/universato/ac-library-rb/blob/master/document_ja/index.md)
|
17
17
|
|
18
|
-
|
18
|
+
公式に、ac-library-rbの利用として、以下の方法を想定しています。
|
19
|
+
- 直接コピペして使う方法
|
20
|
+
- `lib`ディレクトリに、ac-library-rbのライブラリのコードがあります。
|
21
|
+
- `lib_lock`ディレクトリに、Gem用にモジュール化されたコードがあります。
|
22
|
+
(別途モジュール化するの、ちょっとトリッキーですが……)
|
23
|
+
- Gemとして使う方法(詳細は後述)
|
19
24
|
|
20
|
-
|
25
|
+
他に、有志作成のバンドルツール[expander-rb](https://github.com/surpace/expander-rb)(by surpaceさん)を利用する方法もあります。
|
21
26
|
|
22
|
-
|
27
|
+
目次は、[index.md](https://github.com/universato/ac-library-rb/blob/master/document_ja/index.md)をご覧ください。
|
23
28
|
|
24
|
-
|
29
|
+
## Gemとなったac-library-rbを使う方法
|
30
|
+
|
31
|
+
コピペ以外にGemとなったac-library-rbを使う方法を紹介します。
|
32
|
+
|
33
|
+
### gemのインストール方法
|
34
|
+
|
35
|
+
ac-library-rbに限った話ではないですが、一般的な2種類のgemのインストール方法を紹介します。
|
36
|
+
|
37
|
+
- Gemとして使う方法
|
38
|
+
- `gem`コマンドにより、`gem install ac-library-rb`
|
39
|
+
- gemのbundlerを用いる方法
|
40
|
+
|
41
|
+
#### gemコマンドによるインストール方法
|
42
|
+
|
43
|
+
Ruby本体に付属のgemコマンドを用い、そのまま`gem install ac-library-rb`を実行します。
|
44
|
+
|
45
|
+
#### gemのbundlerを用いたインストール方法
|
46
|
+
|
47
|
+
bundlerをインストールしてない場合は、`gem install bundler`というコマンドを打ちインストールします。
|
48
|
+
|
49
|
+
次に、ac-library-rbを使いたいディレクトリ配下にGemfileを置きます。Gemfileという名称のファイルです。
|
50
|
+
このGemfileの中で、次のように書きます。
|
51
|
+
```
|
52
|
+
gem "ac-library-rb"
|
53
|
+
```
|
54
|
+
そして、`budnle install`というコマンドにより、Gemfileに書かれたac-library-rbをインストールします。
|
55
|
+
|
56
|
+
このとき、bundlerを通してRubyファイルを実行する必要があるため、`bundle exec`コマンドを用います。
|
57
|
+
|
58
|
+
`$ bundle exec ruby sample.rb`
|
59
|
+
|
60
|
+
### (インストール後の)Rubyファイルでの書き方
|
61
|
+
|
62
|
+
#### 一括ロード
|
63
|
+
|
64
|
+
Rubyファイル上で一括でac-library-rbのライブラリを使えるようにするには、下記のように書きます。
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
require "ac-library-rb/all"
|
68
|
+
|
69
|
+
dsu = AcLibraryRb::DSU.new
|
70
|
+
|
71
|
+
include AcLibraryRb
|
72
|
+
dsu = DSU.new
|
73
|
+
```
|
74
|
+
|
75
|
+
`include AcLibraryRb`とモジュールをインクルードすることで、
|
76
|
+
何度も`AcLibraryRb`といわゆる名前空間を書く必要がなくなります。
|
77
|
+
|
78
|
+
また、`/all`なしで`require "ac-library-rb"`とした場合は、`include AcLibraryRb`も同時に実行されます。
|
79
|
+
```ruby
|
80
|
+
require "ac-library-rb"
|
81
|
+
|
82
|
+
dsu = DSU.new
|
83
|
+
```
|
84
|
+
|
85
|
+
#### 個別ロード
|
86
|
+
|
87
|
+
特定のライブラリのみをインストールしたいときは下記のように`ac-library-rb/`のあとにライブラリ名を指定します。
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
require "ac-library-rb/dsu"
|
91
|
+
dsu = AcLibraryRb::DSU.new
|
92
|
+
|
93
|
+
require "ac-library-rb/priority_queue"
|
94
|
+
pq = AcLibraryRb::PriorityQueue.new
|
95
|
+
```
|
96
|
+
|
97
|
+
本gem名はハイフン区切りですが、ac-library-rb内のライブラリ名はアンダースコア区切りであるため、注意して下さい。
|
98
|
+
一般的にRubyのライブラリ名はアンダースコアが推奨されていますが、
|
99
|
+
ACL本家のレポジトリ名がac-libraryとハイフン区切りで、それに合わせているため、レポジトリ名・gem名がハイフン区切りとなっています。
|
25
100
|
|
26
101
|
## Rubyバージョン
|
27
102
|
|
data/README.md
CHANGED
@@ -25,6 +25,69 @@ Therefore, 2.7.1 is recommended and may not work with other versions.
|
|
25
25
|
|
26
26
|
Please read [index.md](https://github.com/universato/ac-library-rb/blob/master/document_en/index.md).
|
27
27
|
|
28
|
+
## How to use ac-library-rb as a Gem
|
29
|
+
|
30
|
+
We will show you how to use ac-library-rb as a gem.
|
31
|
+
## How to install
|
32
|
+
|
33
|
+
This is not limited to ac-library-rb, but I will show you how to install the two common types of gem.
|
34
|
+
|
35
|
+
- By `gem` command, `gem install ac-library-rb`.
|
36
|
+
- By using the gem bundler's commands.
|
37
|
+
|
38
|
+
By #### gem command, `gem install ac-library-rb`
|
39
|
+
|
40
|
+
Execute `gem install ac-library-rb` by using the gem command included in Ruby itself.
|
41
|
+
|
42
|
+
#### How to use the gem bundler
|
43
|
+
|
44
|
+
If you have not installed bundler, type `gem install bundler` to install it.
|
45
|
+
|
46
|
+
Next, place Gemfile under the directory where you want to use ac-library-rb.
|
47
|
+
|
48
|
+
In this Gemfile, write:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
gem "ac-library-rb".
|
52
|
+
```
|
53
|
+
|
54
|
+
Then, install ac-library-rb by using the command `budnle install`.
|
55
|
+
|
56
|
+
At this point, we need to run the Ruby file through bundler, so we use the command `bundle exec`.
|
57
|
+
|
58
|
+
`$ bundle exec ruby sample.rb`.
|
59
|
+
|
60
|
+
### How to write in Ruby files (after installation)
|
61
|
+
|
62
|
+
#### Bulk loading
|
63
|
+
|
64
|
+
To enable the ac-library-rb library to be used in bulk on Ruby files, write as follows.
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
require "ac-library-rb/all"
|
68
|
+
|
69
|
+
dsu = AcLibraryRb::DSU.new
|
70
|
+
|
71
|
+
include AcLibraryRb
|
72
|
+
dsu = DSU.new
|
73
|
+
```
|
74
|
+
|
75
|
+
#### Individual loading
|
76
|
+
|
77
|
+
If you want to install only a specific library, specify the library name after `ac-library-rb/` as shown below.
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
require "ac-library-rb/dsu"
|
81
|
+
dsu = AcLibraryRb::DSU.new
|
82
|
+
|
83
|
+
require "ac-library-rb/priority_queue"
|
84
|
+
pq = AcLibraryRb::PriorityQueue.new
|
85
|
+
```
|
86
|
+
|
87
|
+
Note that the gem names are separated by hyphens, but the library names in ac-library-rb are separated by underscores.
|
88
|
+
In general, underscores are recommended for Ruby library names.
|
89
|
+
However, the repository names in the original ACL are separated by a hyphen, ac-library, so ac-library-rb is also separated by a hyphen.
|
90
|
+
|
28
91
|
## Development
|
29
92
|
|
30
93
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/Rakefile
CHANGED
@@ -2,7 +2,8 @@ require "bundler/gem_tasks"
|
|
2
2
|
require "rake/testtask"
|
3
3
|
|
4
4
|
Rake::TestTask.new(:test) do |t|
|
5
|
-
require_relative "./bin/lock_lib.rb"
|
5
|
+
# require_relative "./bin/lock_lib.rb"
|
6
|
+
t.warning = false
|
6
7
|
t.libs << "test"
|
7
8
|
t.libs << "lib"
|
8
9
|
t.test_files = FileList["test/**/*_test.rb"]
|
data/ac-library-rb.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.description = gem_description
|
14
14
|
spec.homepage = "https://github.com/universato/ac-library-rb"
|
15
15
|
spec.license = "CC0"
|
16
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
16
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
17
17
|
|
18
18
|
spec.metadata["homepage_uri"] = spec.homepage
|
19
19
|
spec.metadata["source_code_uri"] = "https://github.com/universato/ac-library-rb"
|
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
|
24
24
|
# Specify which files should be added to the gem when it is released.
|
25
25
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
26
|
-
spec.files = Dir.chdir(File.expand_path(
|
26
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
27
27
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
28
28
|
end
|
29
29
|
spec.bindir = "exe"
|
data/bin/lock_lib.rb
CHANGED
@@ -1,22 +1,24 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
|
3
3
|
# copy libraries from `lib` to `lib_lock/ac-library` and add `module AcLibraryRb`
|
4
|
-
lib_path = File.expand_path('
|
5
|
-
lock_dir = File.expand_path('
|
4
|
+
lib_path = File.expand_path('../lib/**', __dir__)
|
5
|
+
lock_dir = File.expand_path('../lib_lock/ac-library-rb', __dir__)
|
6
6
|
Dir.glob(lib_path) do |file|
|
7
7
|
next unless FileTest.file?(file)
|
8
8
|
|
9
9
|
path = Pathname.new(lock_dir) + Pathname.new(file).basename
|
10
10
|
File.open(path, "w") do |f|
|
11
|
+
library_code = File.readlines(file).map{ |line| line == "\n" ? "\n" : ' ' + line }
|
12
|
+
|
11
13
|
f.puts "module AcLibraryRb"
|
12
|
-
f.puts
|
14
|
+
f.puts library_code
|
13
15
|
f.puts "end"
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
17
|
-
#
|
18
|
-
lib_path = File.expand_path('
|
19
|
-
lock_dir = File.expand_path('
|
19
|
+
# copy library from `lib/core_ext` to `lib_lock/ac-library-rb/core_ext`
|
20
|
+
lib_path = File.expand_path('../lib/core_ext/**', __dir__)
|
21
|
+
lock_dir = File.expand_path('../lib_lock/ac-library-rb/core_ext', __dir__)
|
20
22
|
Dir.glob(lib_path) do |file|
|
21
23
|
next unless FileTest.file?(file)
|
22
24
|
|
data/lib/modint.rb
CHANGED
@@ -161,7 +161,9 @@ class ModInt < Numeric
|
|
161
161
|
|
162
162
|
def inv_internal(a)
|
163
163
|
if $_mod_is_prime
|
164
|
-
|
164
|
+
raise(RangeError, 'no inverse') if a == 0
|
165
|
+
|
166
|
+
a.pow($_mod - 2, $_mod)
|
165
167
|
else
|
166
168
|
g, x = ModInt.inv_gcd(a, $_mod)
|
167
169
|
g == 1 ? x : raise(RangeError, 'no inverse')
|
data/lib/suffix_array.rb
CHANGED
@@ -76,9 +76,7 @@ def sa_is(s, upper)
|
|
76
76
|
end_l = lms[lms_map[l] + 1] || n
|
77
77
|
end_r = lms[lms_map[r] + 1] || n
|
78
78
|
same = true
|
79
|
-
if end_l - l
|
80
|
-
same = false
|
81
|
-
else
|
79
|
+
if end_l - l == end_r - r
|
82
80
|
while l < end_l
|
83
81
|
break if s[l] != s[r]
|
84
82
|
|
@@ -86,6 +84,8 @@ def sa_is(s, upper)
|
|
86
84
|
r += 1
|
87
85
|
end
|
88
86
|
same = false if l == n || s[l] != s[r]
|
87
|
+
else
|
88
|
+
same = false
|
89
89
|
end
|
90
90
|
rec_upper += 1 if not same
|
91
91
|
rec_s[lms_map[sorted_lms[i]]] = rec_upper
|
@@ -100,7 +100,11 @@ end
|
|
100
100
|
|
101
101
|
# suffix array for array of integers or string
|
102
102
|
def suffix_array(s, upper = nil)
|
103
|
-
if
|
103
|
+
if upper
|
104
|
+
s.each{ |s|
|
105
|
+
raise ArgumentError if s < 0 || upper < s
|
106
|
+
}
|
107
|
+
else
|
104
108
|
case s
|
105
109
|
when Array
|
106
110
|
# compression
|
@@ -118,10 +122,6 @@ def suffix_array(s, upper = nil)
|
|
118
122
|
upper = 255
|
119
123
|
s = s.bytes
|
120
124
|
end
|
121
|
-
else
|
122
|
-
s.each{ |s|
|
123
|
-
raise ArgumentError if s < 0 || upper < s
|
124
|
-
}
|
125
125
|
end
|
126
126
|
|
127
127
|
return sa_is(s, upper)
|
@@ -162,7 +162,9 @@ module AcLibraryRb
|
|
162
162
|
|
163
163
|
def inv_internal(a)
|
164
164
|
if $_mod_is_prime
|
165
|
-
|
165
|
+
raise(RangeError, 'no inverse') if a == 0
|
166
|
+
|
167
|
+
a.pow($_mod - 2, $_mod)
|
166
168
|
else
|
167
169
|
g, x = ModInt.inv_gcd(a, $_mod)
|
168
170
|
g == 1 ? x : raise(RangeError, 'no inverse')
|
@@ -77,9 +77,7 @@ module AcLibraryRb
|
|
77
77
|
end_l = lms[lms_map[l] + 1] || n
|
78
78
|
end_r = lms[lms_map[r] + 1] || n
|
79
79
|
same = true
|
80
|
-
if end_l - l
|
81
|
-
same = false
|
82
|
-
else
|
80
|
+
if end_l - l == end_r - r
|
83
81
|
while l < end_l
|
84
82
|
break if s[l] != s[r]
|
85
83
|
|
@@ -87,6 +85,8 @@ module AcLibraryRb
|
|
87
85
|
r += 1
|
88
86
|
end
|
89
87
|
same = false if l == n || s[l] != s[r]
|
88
|
+
else
|
89
|
+
same = false
|
90
90
|
end
|
91
91
|
rec_upper += 1 if not same
|
92
92
|
rec_s[lms_map[sorted_lms[i]]] = rec_upper
|
@@ -101,7 +101,11 @@ module AcLibraryRb
|
|
101
101
|
|
102
102
|
# suffix array for array of integers or string
|
103
103
|
def suffix_array(s, upper = nil)
|
104
|
-
if
|
104
|
+
if upper
|
105
|
+
s.each{ |s|
|
106
|
+
raise ArgumentError if s < 0 || upper < s
|
107
|
+
}
|
108
|
+
else
|
105
109
|
case s
|
106
110
|
when Array
|
107
111
|
# compression
|
@@ -119,10 +123,6 @@ module AcLibraryRb
|
|
119
123
|
upper = 255
|
120
124
|
s = s.bytes
|
121
125
|
end
|
122
|
-
else
|
123
|
-
s.each{ |s|
|
124
|
-
raise ArgumentError if s < 0 || upper < s
|
125
|
-
}
|
126
126
|
end
|
127
127
|
|
128
128
|
return sa_is(s, upper)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ac-library-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- universato
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
11
|
+
date: 2021-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -144,14 +144,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
144
144
|
requirements:
|
145
145
|
- - ">="
|
146
146
|
- !ruby/object:Gem::Version
|
147
|
-
version: 2.
|
147
|
+
version: 2.5.0
|
148
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
153
|
requirements: []
|
154
|
-
rubygems_version: 3.2.
|
154
|
+
rubygems_version: 3.2.15
|
155
155
|
signing_key:
|
156
156
|
specification_version: 4
|
157
157
|
summary: ac-library-rb is a ruby port of AtCoder Library (ACL).
|