factbase 0.15.2 → 0.15.4

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: 85e37453d7e238f20d15017e452fc39e2068cf86bc1c0bc0c5689439bf732c81
4
- data.tar.gz: dc91da500dd5e512e041de74ad677dbf98ce24a84cb1972bc910884ddb3c48f3
3
+ metadata.gz: 60e6653254c72f386c6b5654e3d13ab0d88c3107cbcf88553832515e969c850e
4
+ data.tar.gz: eaeff76eef8504359dc2841d29fed6d7f1b31da34d7fc349a3f3369e8f5d7548
5
5
  SHA512:
6
- metadata.gz: 323d7a269d425e503365cd694cdafb224ee9bab256992d740af40c4151245d729cd183aba297f6bc963984d8e3d743ffe6e6099e6fbf3b0514a7994876d00533
7
- data.tar.gz: 2ede879be19ca0faf61506cdfb9672117f767d66528c8fa5aa52237180848a011202eef6c3982b102e1b56430ebf9777b94fdfaf9b76e96738b25d45d1a549a3
6
+ metadata.gz: 6036b63bbf2a719329d0a81379257b5a048aa720b819801500fbef660c83599f95a5106a649ff8d05ff3babc7a89416de9a575d81f43ee4df64afd132e78bb6d
7
+ data.tar.gz: d0df44073dcf267f734b137a7a2d6f5ac824497d9635b829d280a8343072185f5b981be78bedddf68f37ba466d9fe8a6d7a233f261634c89c07208a16e9ddb8e
@@ -153,7 +153,7 @@ module Factbase::IndexedTerm
153
153
  end
154
154
  if r.nil?
155
155
  r = n
156
- else
156
+ elsif n.size < r.size * 5 # to skip some obvious matchings
157
157
  r &= n.to_a
158
158
  end
159
159
  break if r.empty?
data/lib/factbase/term.rb CHANGED
@@ -121,7 +121,7 @@ class Factbase::Term
121
121
  rescue NoMethodError => e
122
122
  raise "Probably the term '#{@op}' is not defined at #{self}: #{e.message}"
123
123
  rescue StandardError => e
124
- raise "#{e.message} at #{self}"
124
+ raise "#{e.message.inspect} at #{self} at #{e.backtrace[0]}"
125
125
  end
126
126
 
127
127
  # Simplify it if possible.
@@ -20,24 +20,35 @@ module Factbase::Ordering
20
20
  end
21
21
 
22
22
  def unique(fact, maps, fb)
23
- @uniques = {} if @uniques.nil?
23
+ @seen = Set.new if @seen.nil?
24
24
  raise "Too few operands for 'unique' (at least 1 expected)" if @operands.empty?
25
- dups = 0
26
- @operands.each_with_index do |_, i|
27
- @uniques[i] = [] if @uniques[i].nil?
28
- vv = _values(i, fact, maps, fb)
29
- return false if vv.nil?
30
- vv = [vv] unless vv.respond_to?(:to_a)
31
- exists = false
32
- vv.each do |v|
33
- if @uniques[i].include?(v)
34
- exists = true
35
- else
36
- @uniques[i] << v
37
- end
38
- end
39
- dups += 1 if exists
25
+ vv = (0..(@operands.size - 1)).map { |i| _values(i, fact, maps, fb) }
26
+ return false if vv.any?(nil)
27
+ pass = true
28
+ _cartesian(vv).each do |t|
29
+ pass = false if @seen.include?(t)
30
+ @seen << t
31
+ end
32
+ pass
33
+ end
34
+
35
+ private
36
+
37
+ # Multiplies arrays and returns a list of all possible combinations
38
+ # of their elements. If this array is provided:
39
+ #
40
+ # [ [4, 3], [2, 88, 13] ]
41
+ #
42
+ # This will be the result:
43
+ #
44
+ # [ [4, 2], [4, 88], [4, 13], [3, 2], [3, 88], [3, 13]]
45
+ def _cartesian(vv)
46
+ ff = vv.first.zip
47
+ if vv.one?
48
+ ff
49
+ else
50
+ tail = _cartesian(vv[1..])
51
+ ff.map { |f| tail.map { |t| f + t } }
40
52
  end
41
- dups < @operands.size
42
53
  end
43
54
  end
@@ -9,5 +9,5 @@
9
9
  # License:: MIT
10
10
  class Factbase
11
11
  # Current version of the gem (changed by .rultor.yml on every release)
12
- VERSION = '0.15.2' unless const_defined?(:VERSION)
12
+ VERSION = '0.15.4' unless const_defined?(:VERSION)
13
13
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: factbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.2
4
+ version: 0.15.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko