ac-library-rb 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/unittest.yml +16 -3
  3. data/.rubocop.yml +61 -45
  4. data/README.ja.md +36 -8
  5. data/README.md +7 -4
  6. data/Rakefile +7 -3
  7. data/ac-library-rb.gemspec +11 -4
  8. data/ac-library-rb_header.jpg +0 -0
  9. data/bin/console +1 -1
  10. data/document_en/dsu.md +1 -1
  11. data/document_en/fenwick_tree.md +2 -2
  12. data/document_en/lazy_segtree.md +4 -4
  13. data/document_en/math.md +3 -3
  14. data/document_en/max_flow.md +3 -3
  15. data/document_en/min_cost_flow.md +4 -4
  16. data/document_en/modint.md +4 -4
  17. data/document_en/scc.md +67 -0
  18. data/document_en/segtree.md +2 -2
  19. data/document_ja/dsu.md +1 -1
  20. data/document_ja/fenwick_tree.md +2 -2
  21. data/document_ja/lazy_segtree.md +2 -2
  22. data/document_ja/math.md +3 -3
  23. data/document_ja/max_flow.md +4 -7
  24. data/document_ja/min_cost_flow.md +5 -4
  25. data/document_ja/modint.md +4 -4
  26. data/document_ja/scc.md +9 -8
  27. data/document_ja/segtree.md +2 -2
  28. data/lib/ac-library-rb/version.rb +1 -1
  29. data/lib/convolution.rb +1 -1
  30. data/lib/dsu.rb +14 -1
  31. data/lib/fenwick_tree.rb +4 -0
  32. data/lib/lazy_segtree.rb +2 -6
  33. data/lib/max_flow.rb +27 -26
  34. data/lib/modint.rb +4 -4
  35. data/lib/priority_queue.rb +14 -0
  36. data/lib/scc.rb +1 -1
  37. data/lib/two_sat.rb +1 -1
  38. data/lib_lock/ac-library-rb/convolution.rb +1 -1
  39. data/lib_lock/ac-library-rb/dsu.rb +14 -1
  40. data/lib_lock/ac-library-rb/fenwick_tree.rb +4 -0
  41. data/lib_lock/ac-library-rb/lazy_segtree.rb +2 -6
  42. data/lib_lock/ac-library-rb/max_flow.rb +27 -26
  43. data/lib_lock/ac-library-rb/modint.rb +4 -4
  44. data/lib_lock/ac-library-rb/priority_queue.rb +14 -0
  45. data/lib_lock/ac-library-rb/scc.rb +1 -1
  46. data/lib_lock/ac-library-rb/two_sat.rb +1 -1
  47. metadata +39 -7
@@ -5,7 +5,7 @@ module AcLibraryRb
5
5
  class ModInt < Numeric
6
6
  class << self
7
7
  def set_mod(mod)
8
- raise ArgumentError unless mod.is_a? Integer and 1 <= mod
8
+ raise ArgumentError unless mod.is_a?(Integer) && (1 <= mod)
9
9
 
10
10
  $_mod = mod
11
11
  $_mod_is_prime = ModInt.prime?(mod)
@@ -27,7 +27,7 @@ module AcLibraryRb
27
27
 
28
28
  def prime?(n)
29
29
  return false if n <= 1
30
- return true if n == 2 or n == 7 or n == 61
30
+ return true if (n == 2) || (n == 7) || (n == 61)
31
31
  return false if (n & 1) == 0
32
32
 
33
33
  d = n - 1
@@ -35,11 +35,11 @@ module AcLibraryRb
35
35
  [2, 7, 61].each do |a|
36
36
  t = d
37
37
  y = a.pow(t, n)
38
- while t != n - 1 and y != 1 and y != n - 1
38
+ while (t != n - 1) && (y != 1) && (y != n - 1)
39
39
  y = y * y % n
40
40
  t <<= 1
41
41
  end
42
- return false if y != n - 1 and (t & 1) == 0
42
+ return false if (y != n - 1) && ((t & 1) == 0)
43
43
  end
44
44
  true
45
45
  end
@@ -14,11 +14,17 @@ module AcLibraryRb
14
14
  heapify
15
15
  end
16
16
 
17
+ def self.[](*array, &comp)
18
+ new(array, &comp)
19
+ end
20
+
17
21
  attr_reader :heap
22
+ alias to_a heap
18
23
 
19
24
  # Push new element to the heap.
20
25
  def push(item)
21
26
  shift_down(0, @heap.push(item).size - 1)
27
+ self
22
28
  end
23
29
 
24
30
  alias << push
@@ -47,6 +53,14 @@ module AcLibraryRb
47
53
  @heap.empty?
48
54
  end
49
55
 
56
+ def size
57
+ @heap.size
58
+ end
59
+
60
+ def to_s
61
+ "<#{self.class}: @heap:(#{heap.join(', ')}), @comp:<#{@comp.class} #{@comp.source_location.join(':')}>>"
62
+ end
63
+
50
64
  private
51
65
 
52
66
  def heapify
@@ -9,7 +9,7 @@ module AcLibraryRb
9
9
 
10
10
  # add directed edge
11
11
  def add_edge(from, to)
12
- unless 0 <= from && from < @n and 0 <= to && to < @n
12
+ unless 0 <= from && from < @n && 0 <= to && to < @n
13
13
  msg = "Wrong params: from=#{from} and to=#{to} must be in 0...#{@n}"
14
14
  raise ArgumentError.new(msg)
15
15
  end
@@ -13,7 +13,7 @@ module AcLibraryRb
13
13
  attr_reader :answer
14
14
 
15
15
  def add_clause(i, f, j, g)
16
- unless 0 <= i && i < @n and 0 <= j && j < @n
16
+ unless 0 <= i && i < @n && 0 <= j && j < @n
17
17
  raise ArgumentError.new("i:#{i} and j:#{j} must be in (0...#{@n})")
18
18
  end
19
19
 
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ac-library-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - universato
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-09 00:00:00.000000000 Z
11
+ date: 2022-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: prime
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: minitest
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,9 +66,24 @@ dependencies:
52
66
  - - ">="
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
55
- description: |-
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov-cobertura
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: |
56
84
  ac-library-rb is a ruby port of AtCoder Library (ACL).
57
- DSU(UnionFind), FenwickTree, PriorityQueue, Segtree, SCC, 2-SAT, suffix_array, lcp_array, z_algorithm, crt, inv_mod, floor_sum, max_flow, min_cost_flow......
85
+ DSU(UnionFind), FenwickTree, PriorityQueue, Segtree, SCC, 2-SAT,
86
+ suffix_array, lcp_array, z_algorithm, crt, inv_mod, floor_sum, max_flow, min_cost_flow......
58
87
  email:
59
88
  - universato@gmail.com
60
89
  executables: []
@@ -70,6 +99,7 @@ files:
70
99
  - README.md
71
100
  - Rakefile
72
101
  - ac-library-rb.gemspec
102
+ - ac-library-rb_header.jpg
73
103
  - bin/console
74
104
  - bin/lock_lib.rb
75
105
  - bin/setup
@@ -84,6 +114,7 @@ files:
84
114
  - document_en/min_cost_flow.md
85
115
  - document_en/modint.md
86
116
  - document_en/priority_queue.md
117
+ - document_en/scc.md
87
118
  - document_en/segtree.md
88
119
  - document_en/string.md
89
120
  - document_en/two_sat.md
@@ -151,23 +182,24 @@ licenses:
151
182
  metadata:
152
183
  homepage_uri: https://github.com/universato/ac-library-rb
153
184
  source_code_uri: https://github.com/universato/ac-library-rb
185
+ rubygems_mfa_required: 'true'
154
186
  post_install_message:
155
187
  rdoc_options: []
156
188
  require_paths:
157
189
  - lib_lock
158
- - lib_helpers
190
+ - lib_helpers"
159
191
  required_ruby_version: !ruby/object:Gem::Requirement
160
192
  requirements:
161
193
  - - ">="
162
194
  - !ruby/object:Gem::Version
163
- version: 2.5.0
195
+ version: 2.7.0
164
196
  required_rubygems_version: !ruby/object:Gem::Requirement
165
197
  requirements:
166
198
  - - ">="
167
199
  - !ruby/object:Gem::Version
168
200
  version: '0'
169
201
  requirements: []
170
- rubygems_version: 3.2.22
202
+ rubygems_version: 3.3.3
171
203
  signing_key:
172
204
  specification_version: 4
173
205
  summary: ac-library-rb is a ruby port of AtCoder Library (ACL).