factbase 0.19.7 → 0.19.8
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 +4 -4
- data/Gemfile.lock +5 -3
- data/Rakefile +1 -1
- data/lib/factbase/lazy_taped.rb +57 -54
- data/lib/factbase/terms/traced.rb +1 -1
- data/lib/factbase/version.rb +1 -1
- data/lib/factbase.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 03d4be418b18984640fa333733a6b688aa2879b2e7def6d0ad901bce47490cd2
|
|
4
|
+
data.tar.gz: c6f24e2c444eb03eb739489d4cd09f927ece90a8c44f480c3b04fef1876b574d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f73778d27a87c5a436769565032c5b064b24354ce62fad61822fd29941664e96c6d70f8481bf146bc72ef32669fc4969bae050eb70ef2f5c1fa0e19ee9395000
|
|
7
|
+
data.tar.gz: 299d0afc68fa48166fd4e01366e82ce1d22f8aa8c2f1dc2cfc9bd397763080f8db1762b20caa7738bafd0a5d606e9fa1725c13f400e13b40193ff13528b05b59
|
data/Gemfile.lock
CHANGED
|
@@ -25,6 +25,7 @@ GEM
|
|
|
25
25
|
date (3.5.1)
|
|
26
26
|
decoor (0.1.0)
|
|
27
27
|
docile (1.4.1)
|
|
28
|
+
drb (2.2.3)
|
|
28
29
|
elapsed (0.3.1)
|
|
29
30
|
loog (~> 0.6)
|
|
30
31
|
tago (~> 0.1)
|
|
@@ -37,7 +38,8 @@ GEM
|
|
|
37
38
|
loog (0.8.0)
|
|
38
39
|
ellipsized
|
|
39
40
|
logger (~> 1.0)
|
|
40
|
-
minitest (6.0.
|
|
41
|
+
minitest (6.0.2)
|
|
42
|
+
drb (~> 2.0)
|
|
41
43
|
prism (~> 1.5)
|
|
42
44
|
minitest-reporters (1.7.1)
|
|
43
45
|
ansi
|
|
@@ -55,7 +57,7 @@ GEM
|
|
|
55
57
|
os (1.1.4)
|
|
56
58
|
others (0.1.1)
|
|
57
59
|
parallel (1.27.0)
|
|
58
|
-
parser (3.3.10.
|
|
60
|
+
parser (3.3.10.2)
|
|
59
61
|
ast (~> 2.4.1)
|
|
60
62
|
racc
|
|
61
63
|
prism (1.9.0)
|
|
@@ -90,7 +92,7 @@ GEM
|
|
|
90
92
|
rubocop-ast (1.49.0)
|
|
91
93
|
parser (>= 3.3.7.2)
|
|
92
94
|
prism (~> 1.7)
|
|
93
|
-
rubocop-minitest (0.
|
|
95
|
+
rubocop-minitest (0.39.1)
|
|
94
96
|
lint_roller (~> 1.1)
|
|
95
97
|
rubocop (>= 1.75.0, < 2.0)
|
|
96
98
|
rubocop-ast (>= 1.38.0, < 2.0)
|
data/Rakefile
CHANGED
|
@@ -88,7 +88,7 @@ desc 'Profile a benchmark (e.g., flamegraph[bench_slow_query])'
|
|
|
88
88
|
task :flamegraph, [:name] do |_t, args|
|
|
89
89
|
require 'stackprof'
|
|
90
90
|
bname = args[:name] || 'all'
|
|
91
|
-
puts "Starting profiling for '#{bname}'..."
|
|
91
|
+
puts "Starting profiling for '#{bname}'..." # rubocop:disable Lint/Debugger
|
|
92
92
|
StackProf.run(mode: :cpu, out: 'stackprof-cpu-myapp.dump', raw: true) do
|
|
93
93
|
Rake::Task['benchmark'].invoke(bname)
|
|
94
94
|
end
|
data/lib/factbase/lazy_taped.rb
CHANGED
|
@@ -11,23 +11,23 @@ require_relative 'lazy_taped_hash'
|
|
|
11
11
|
class Factbase::LazyTaped
|
|
12
12
|
def initialize(origin)
|
|
13
13
|
@origin = origin
|
|
14
|
+
@staged = []
|
|
14
15
|
@copied = false
|
|
15
|
-
@
|
|
16
|
-
@pairs = nil
|
|
17
|
-
@inverted_pairs = nil
|
|
16
|
+
@copies = {}.compare_by_identity
|
|
18
17
|
@inserted = []
|
|
19
18
|
@deleted = []
|
|
20
19
|
@added = []
|
|
21
20
|
end
|
|
22
21
|
|
|
23
|
-
# Returns
|
|
24
|
-
#
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
# Returns the original map this copy was derived from.
|
|
23
|
+
# Returns nil if the base hasn't been copied yet or if the fact is new.
|
|
24
|
+
def source_of(copy)
|
|
25
|
+
return nil unless @copied
|
|
26
|
+
@copies.key(copy)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def copied?
|
|
30
|
+
@copied
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
# Returns the unique object IDs of maps that were inserted (newly created).
|
|
@@ -51,101 +51,104 @@ class Factbase::LazyTaped
|
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
def find_by_object_id(oid)
|
|
54
|
-
|
|
54
|
+
r = @staged.find { |m| m.object_id == oid }
|
|
55
|
+
r = @origin.find { |m| m.object_id == oid } if r.nil? && !copied?
|
|
56
|
+
r
|
|
55
57
|
end
|
|
56
58
|
|
|
57
59
|
def size
|
|
58
|
-
|
|
60
|
+
copied? ? @staged.size : (@origin.size + @staged.size)
|
|
59
61
|
end
|
|
60
62
|
|
|
61
63
|
def empty?
|
|
62
|
-
|
|
64
|
+
copied? ? @staged.empty? : (@origin.empty? && @staged.empty?)
|
|
63
65
|
end
|
|
64
66
|
|
|
65
67
|
def <<(map)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
@staged << map
|
|
69
|
+
_track(map, map)
|
|
68
70
|
@inserted.append(map.object_id)
|
|
69
71
|
end
|
|
70
72
|
|
|
71
73
|
def each
|
|
72
74
|
return to_enum(__method__) unless block_given?
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
yield LazyTapedHash.new(m, self, @added)
|
|
75
|
+
st_size = @staged.size
|
|
76
|
+
orig_size = @origin.size
|
|
77
|
+
unless copied?
|
|
78
|
+
orig_size.times do |i|
|
|
79
|
+
m = @origin[i]
|
|
80
|
+
yield _tape(m) unless m.nil?
|
|
80
81
|
end
|
|
81
82
|
end
|
|
83
|
+
st_size.times do |i|
|
|
84
|
+
m = @staged[i]
|
|
85
|
+
yield _tape(m) unless m.nil?
|
|
86
|
+
end
|
|
82
87
|
end
|
|
83
88
|
|
|
84
89
|
def delete_if
|
|
85
90
|
ensure_copied!
|
|
86
|
-
@
|
|
91
|
+
@staged.delete_if do |m|
|
|
87
92
|
r = yield m
|
|
88
|
-
@deleted.append(
|
|
93
|
+
@deleted.append(source_of(m).object_id) if r
|
|
89
94
|
r
|
|
90
95
|
end
|
|
91
96
|
end
|
|
92
97
|
|
|
93
98
|
def to_a
|
|
94
|
-
(@
|
|
99
|
+
(copied? ? @staged : (@origin + @staged)).to_a
|
|
95
100
|
end
|
|
96
101
|
|
|
97
102
|
def repack(other)
|
|
98
103
|
ensure_copied!
|
|
99
|
-
copied = other.map { |o| @
|
|
104
|
+
copied = other.map { |o| @copies[o] || o }
|
|
100
105
|
Factbase::Taped.new(copied, inserted: @inserted, deleted: @deleted, added: @added)
|
|
101
106
|
end
|
|
102
107
|
|
|
103
108
|
def &(other)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
join(other, &:&)
|
|
109
|
+
return Factbase::Taped.new([], inserted: @inserted, deleted: @deleted, added: @added) if other == []
|
|
110
|
+
return Factbase::Taped.new([], inserted: @inserted, deleted: @deleted, added: @added) if empty?
|
|
111
|
+
_join(other, &:&)
|
|
108
112
|
end
|
|
109
113
|
|
|
110
114
|
def |(other)
|
|
111
115
|
return Factbase::Taped.new(to_a, inserted: @inserted, deleted: @deleted, added: @added) if other == []
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
end
|
|
115
|
-
join(other, &:|)
|
|
116
|
+
return Factbase::Taped.new(other, inserted: @inserted, deleted: @deleted, added: @added) if empty?
|
|
117
|
+
_join(other, &:|)
|
|
116
118
|
end
|
|
117
119
|
|
|
118
120
|
def ensure_copied!
|
|
119
|
-
return if
|
|
120
|
-
@
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
@
|
|
124
|
-
|
|
125
|
-
@pairs[n] = m
|
|
126
|
-
@inverted_pairs[m] = n
|
|
127
|
-
n
|
|
128
|
-
end
|
|
121
|
+
return if copied?
|
|
122
|
+
@origin.each do |o|
|
|
123
|
+
c = o.transform_values(&:dup)
|
|
124
|
+
_track(c, o)
|
|
125
|
+
@staged << c
|
|
126
|
+
end
|
|
129
127
|
@copied = true
|
|
130
128
|
end
|
|
131
129
|
|
|
132
130
|
def get_copied_map(original_map)
|
|
133
131
|
ensure_copied!
|
|
134
|
-
@
|
|
132
|
+
@copies[original_map] || original_map
|
|
135
133
|
end
|
|
136
134
|
|
|
137
135
|
private
|
|
138
136
|
|
|
139
|
-
def
|
|
137
|
+
def _join(other)
|
|
140
138
|
ensure_copied!
|
|
141
|
-
n = yield
|
|
139
|
+
n = yield to_a, other.to_a
|
|
142
140
|
raise 'Cannot join with another Taped' if other.respond_to?(:inserted)
|
|
143
141
|
raise 'Can only join with array' unless other.is_a?(Array)
|
|
144
|
-
Factbase::Taped.new(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
142
|
+
Factbase::Taped.new(n, inserted: @inserted, deleted: @deleted, added: @added)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def _track(copy, original)
|
|
146
|
+
@copies[original] = copy
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def _tape(map)
|
|
150
|
+
return LazyTapedHash.new(map, self, @added) unless copied?
|
|
151
|
+
copy = @copies[map] || map
|
|
152
|
+
Factbase::Taped::TapedHash.new(copy, @added)
|
|
150
153
|
end
|
|
151
154
|
end
|
|
@@ -27,7 +27,7 @@ class Factbase::Traced < Factbase::TermBase
|
|
|
27
27
|
t = @operands[0]
|
|
28
28
|
raise "A term is expected, but '#{t}' provided" unless t.is_a?(Factbase::Term)
|
|
29
29
|
r = t.evaluate(fact, maps, fb)
|
|
30
|
-
puts "#{self} -> #{r}"
|
|
30
|
+
puts "#{self} -> #{r}" # rubocop:disable Lint/Debugger
|
|
31
31
|
r
|
|
32
32
|
end
|
|
33
33
|
end
|
data/lib/factbase/version.rb
CHANGED
data/lib/factbase.rb
CHANGED
|
@@ -181,7 +181,6 @@ class Factbase
|
|
|
181
181
|
end
|
|
182
182
|
seen = {}.compare_by_identity
|
|
183
183
|
garbage = {}.compare_by_identity
|
|
184
|
-
pairs = taped.pairs
|
|
185
184
|
taped.deleted.each do |oid|
|
|
186
185
|
original = @maps.find { |m| m.object_id == oid }
|
|
187
186
|
next if original.nil?
|
|
@@ -200,7 +199,8 @@ class Factbase
|
|
|
200
199
|
b = taped.find_by_object_id(oid)
|
|
201
200
|
next if b.nil?
|
|
202
201
|
next if seen.key?(b)
|
|
203
|
-
|
|
202
|
+
original = taped.source_of(b)
|
|
203
|
+
garbage[original] = true if original
|
|
204
204
|
@maps << b
|
|
205
205
|
churn.append(0, 0, 1)
|
|
206
206
|
end
|