regexgen 0.2.1 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb6f68dd7f81cc6714b77b64161cce3b36943b9d9ad832386a576294888eee6c
4
- data.tar.gz: 1ebb00e814c7c25587eb209922370516fd388e615d7c1a7bd1c30faa026d14db
3
+ metadata.gz: e86e086268d6721f47706182ff5ea253c144a1c17a204ebe35ecb8c1f706cc89
4
+ data.tar.gz: a88cd0e49107c29290c840d66a859a67538977b18fc3294b5df97894b99897ae
5
5
  SHA512:
6
- metadata.gz: 2b9683000022bf3961a3cfd376e2eb97e4d17f24d73408fb456fd4c6d4dbcfec9c1add69405b75e58b76e19ece25b72f1c9a717d151ccec10f4f1ff168e5acf6
7
- data.tar.gz: e440c3632860395f6da1713d60781fd1a29cfaaca4b80e568cf4704c0c7580541c6ddc0b7f8feaa0359608f100224209d5eeb068b3038f077fc5cdab8c8ac50f
6
+ metadata.gz: 9ea1ab6014151731615350e3eaeb5e975fb346e23b442c673077f424e806fae63c2a2db9058a041a8c32e523287c6417bdad0f54b6991c30c7f46e3ddc0fbcc1
7
+ data.tar.gz: ff525455e5a7ecbd1a2bbde4a618f1b192ebadfaf7c13c3d7f4bbdd750103b472c700bcbddda2a937466486c60310b28a5123d0030c97264903d9c11787cafd3
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2020-08-10 13:40:30 UTC using RuboCop version 0.89.0.
3
+ # on 2020-08-18 06:34:11 UTC using RuboCop version 0.89.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -9,7 +9,7 @@
9
9
  # Offense count: 5
10
10
  # Configuration parameters: IgnoredMethods.
11
11
  Metrics/AbcSize:
12
- Max: 66
12
+ Max: 73
13
13
 
14
14
  # Offense count: 7
15
15
  # Configuration parameters: IgnoredMethods.
@@ -19,7 +19,7 @@ Metrics/CyclomaticComplexity:
19
19
  # Offense count: 6
20
20
  # Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
21
21
  Metrics/MethodLength:
22
- Max: 39
22
+ Max: 47
23
23
 
24
24
  # Offense count: 1
25
25
  # Configuration parameters: CountComments, CountAsOne.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- regexgen (0.2.1)
4
+ regexgen (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -26,19 +26,19 @@ GEM
26
26
  reverse_markdown (2.0.0)
27
27
  nokogiri
28
28
  rexml (3.2.4)
29
- rubocop (0.89.0)
29
+ rubocop (0.89.1)
30
30
  parallel (~> 1.10)
31
31
  parser (>= 2.7.1.1)
32
32
  rainbow (>= 2.2.2, < 4.0)
33
33
  regexp_parser (>= 1.7)
34
34
  rexml
35
- rubocop-ast (>= 0.1.0, < 1.0)
35
+ rubocop-ast (>= 0.3.0, < 1.0)
36
36
  ruby-progressbar (~> 1.7)
37
37
  unicode-display_width (>= 1.4.0, < 2.0)
38
38
  rubocop-ast (0.3.0)
39
39
  parser (>= 2.7.1.4)
40
40
  ruby-progressbar (1.10.1)
41
- solargraph (0.39.13)
41
+ solargraph (0.39.14)
42
42
  backport (~> 1.1)
43
43
  benchmark
44
44
  bundler (>= 1.17.2)
@@ -41,20 +41,34 @@ module Regexgen
41
41
  # c is a letter of the alphabet
42
42
  # A ∩ B is intersection (A & B)
43
43
  # |A| is the cardinality of A (A.size)
44
- def minimize(root, alphabet)
44
+ def minimize(root)
45
45
  states = root.visit
46
46
  final_states = states.select(&:accepting).to_set
47
47
 
48
+ # Create a map of incoming transitions to each state, grouped by
49
+ # character.
50
+ transitions = Hash.new { |h, k| h[k] = Hash.new { |h_, k_| h_[k_] = Set.new } }
51
+ states.each_with_object(transitions) do |s, acc|
52
+ s.transitions.each do |t, st|
53
+ acc[st][t] << s
54
+ end
55
+ end
56
+
48
57
  p = Set[states, final_states]
49
58
  w = Set.new(p)
50
59
  until w.empty?
51
60
  a = w.shift
52
- alphabet.each do |c|
53
- x = states.each_with_object(Set.new) do |s, acc|
54
- next unless s.transitions.key?(c)
55
61
 
56
- acc.add(s) if a.include?(s.transitions[c])
62
+ # Collect states that have transitions leading to states in a, grouped
63
+ # by character.
64
+ t = Hash.new { |h, k| h[k] = Set.new }
65
+ a.each_with_object(t) do |s, acc|
66
+ transitions[s].each do |t_, x|
67
+ acc[t_].merge(x)
57
68
  end
69
+ end
70
+
71
+ t.each_value do |x|
58
72
  p.to_a.each do |y|
59
73
  intersection = x & y
60
74
  next if intersection.empty?
@@ -27,7 +27,7 @@ module Regexgen
27
27
  end
28
28
 
29
29
  def minimize
30
- Regexgen.minimize(@root, @alphabet)
30
+ Regexgen.minimize(@root)
31
31
  end
32
32
 
33
33
  def to_s
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Regexgen
4
- VERSION = '0.2.1'
4
+ VERSION = '0.3.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: regexgen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Madlon-Kay
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-11 00:00:00.000000000 Z
11
+ date: 2020-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug