factbase 0.19.3 → 0.19.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: aba67403ce0d88eedb16e819e8000c675c43e45908d9e937a08394aa27b76ce2
4
- data.tar.gz: 955fe52ce4c8d8fca527f3471fee46d73f1f56a85b7778440df964e26de2d62f
3
+ metadata.gz: bc6cb6bd378d266fcaa401091228e6dc4084474f5f16e89c9fb29dd56d577c77
4
+ data.tar.gz: 8c1e86c86b01371f159d29c0187a263598d7d5b6c2949200b7813dff22fd6fca
5
5
  SHA512:
6
- metadata.gz: 7fb94faf1459fc521be7d810831c870530898605664f8c2ae74fb15c66846b4c84957e63cb593e9c2f8d6c21f5584227d057a08e51d618994aaeeb3e4e427505
7
- data.tar.gz: 8ca685bc0115e1bc8ab7aa478218c179eb898cfb6a1fd7d38b8b082c3bfd479f48dd72ef82e06700cd6547bd0673d596d885521f8d43e92da879e9b01ebc2d90
6
+ metadata.gz: afa7d0dd3cace0292ce9de22c102dfed04772f568f9ad725e5d937024918b6c2c103a87221bbee3e3902167f0c3ec886567cb791593e8693e2723e66fa2d62f7
7
+ data.tar.gz: 55891ef31903c5d07a6d153bb23bff4264e3d2c414ed4655e2388702d51d1bcdcb75a490f40b8e62007a32dbe571ee0146ab190b890bb5935ad9393d215e0e54
data/Gemfile CHANGED
@@ -10,6 +10,7 @@ gem 'benchmark', '~>0.5', require: false
10
10
  gem 'minitest', '~>6.0', require: false
11
11
  gem 'minitest-reporters', '~>1.7', require: false
12
12
  gem 'os', '~>1.1', require: false
13
+ gem 'psych', '5.3.1', require: false # GPL
13
14
  gem 'qbash', '~>0.4', require: false
14
15
  gem 'rake', '~>13.2', require: false
15
16
  gem 'rdoc', '7.1.0', require: false # GPL
@@ -19,6 +20,6 @@ gem 'rubocop-performance', '~>1.25', require: false
19
20
  gem 'rubocop-rake', '~>0.7', require: false
20
21
  gem 'simplecov', '~>0.22', require: false
21
22
  gem 'simplecov-cobertura', '~>3.0', require: false
22
- gem 'stackprof', '~>0.2', require: false, platforms: [:ruby]
23
+ gem 'stackprof', '0.2.27', require: false, platforms: [:ruby] # GPL
23
24
  gem 'threads', '~>0.4', require: false
24
- gem 'yard', '~>0.9', require: false
25
+ gem 'yard', '0.9.38', require: false # GPL
data/Gemfile.lock CHANGED
@@ -25,12 +25,12 @@ GEM
25
25
  date (3.5.1)
26
26
  decoor (0.1.0)
27
27
  docile (1.4.1)
28
- elapsed (0.2.2)
28
+ elapsed (0.3.1)
29
29
  loog (~> 0.6)
30
30
  tago (~> 0.1)
31
31
  ellipsized (0.3.0)
32
32
  erb (6.0.1)
33
- json (2.18.0)
33
+ json (2.18.1)
34
34
  language_server-protocol (3.17.0.5)
35
35
  lint_roller (1.1.0)
36
36
  logger (1.7.0)
@@ -58,11 +58,11 @@ GEM
58
58
  parser (3.3.10.1)
59
59
  ast (~> 2.4.1)
60
60
  racc
61
- prism (1.8.0)
61
+ prism (1.9.0)
62
62
  psych (5.3.1)
63
63
  date
64
64
  stringio
65
- qbash (0.6.0)
65
+ qbash (0.7.2)
66
66
  backtrace (> 0)
67
67
  elapsed (> 0)
68
68
  loog (> 0)
@@ -76,7 +76,7 @@ GEM
76
76
  tsort
77
77
  regexp_parser (2.11.3)
78
78
  rexml (3.4.4)
79
- rubocop (1.82.1)
79
+ rubocop (1.84.1)
80
80
  json (~> 2.3)
81
81
  language_server-protocol (~> 3.17.0.2)
82
82
  lint_roller (~> 1.1.0)
@@ -84,7 +84,7 @@ GEM
84
84
  parser (>= 3.3.0.2)
85
85
  rainbow (>= 2.2.2, < 4.0)
86
86
  regexp_parser (>= 2.9.3, < 3.0)
87
- rubocop-ast (>= 1.48.0, < 2.0)
87
+ rubocop-ast (>= 1.49.0, < 2.0)
88
88
  ruby-progressbar (~> 1.7)
89
89
  unicode-display_width (>= 2.4.0, < 4.0)
90
90
  rubocop-ast (1.49.0)
@@ -113,7 +113,7 @@ GEM
113
113
  simplecov_json_formatter (0.1.4)
114
114
  stackprof (0.2.27)
115
115
  stringio (3.2.0)
116
- tago (0.6.0)
116
+ tago (0.7.0)
117
117
  threads (0.5.0)
118
118
  backtrace (~> 0)
119
119
  concurrent-ruby (~> 1.0)
@@ -141,6 +141,7 @@ DEPENDENCIES
141
141
  minitest (~> 6.0)
142
142
  minitest-reporters (~> 1.7)
143
143
  os (~> 1.1)
144
+ psych (= 5.3.1)
144
145
  qbash (~> 0.4)
145
146
  rake (~> 13.2)
146
147
  rdoc (= 7.1.0)
@@ -150,9 +151,9 @@ DEPENDENCIES
150
151
  rubocop-rake (~> 0.7)
151
152
  simplecov (~> 0.22)
152
153
  simplecov-cobertura (~> 3.0)
153
- stackprof (~> 0.2)
154
+ stackprof (= 0.2.27)
154
155
  threads (~> 0.4)
155
- yard (~> 0.9)
156
+ yard (= 0.9.38)
156
157
 
157
158
  BUNDLED WITH
158
159
  2.6.8
data/README.md CHANGED
@@ -42,9 +42,9 @@ file = '/tmp/simple.fb'
42
42
  f1 = Factbase.new
43
43
  f = f1.insert
44
44
  f.foo = 42
45
- File.save(file, f1.export)
45
+ File.binwrite(file, f1.export)
46
46
  f2 = Factbase.new
47
- f2.import(File.read(file))
47
+ f2.import(File.binread(file))
48
48
  assert(f2.query('(eq foo 42)').each.to_a.size == 1)
49
49
  ```
50
50
 
@@ -210,54 +210,54 @@ This is the result of the benchmark:
210
210
 
211
211
  <!-- benchmark_begin -->
212
212
  ```text
213
-
213
+
214
214
  query all facts from an empty factbase 0.00
215
215
  insert 20000 facts 0.67
216
216
  export 20000 facts 0.02
217
- import 411032 bytes (20000 facts) 0.03
217
+ import 410821 bytes (20000 facts) 0.01
218
218
  insert 10 facts 0.04
219
- query 10 times w/txn 2.52
220
- query 10 times w/o txn 0.05
221
- modify 10 attrs w/txn 1.84
222
- delete 10 facts w/txn 2.98
219
+ query 10 times w/txn 2.36
220
+ query 10 times w/o txn 0.07
221
+ modify 10 attrs w/txn 1.71
222
+ delete 10 facts w/txn 3.38
223
223
  build index on 5000 facts 0.05
224
- export 5000 facts with index 0.03
225
- import 5000 facts with persisted index 0.05
226
- query 5000 facts using persisted index 0.11
224
+ export 5000 facts with index 0.05
225
+ import 5000 facts with persisted index 0.03
226
+ query 5000 facts using persisted index 0.10
227
227
  export 5000 facts without index 0.00
228
- import 5000 facts without index 0.04
229
- query 5000 facts building index on-the-fly 0.10
230
- (and (eq what 'issue-was-closed') (exists... -> 200 1.21
231
- (and (eq what 'issue-was-closed') (exists... -> 200/txn 1.20
232
- (and (eq what 'issue-was-closed') (exists... -> zero 1.21
233
- (and (eq what 'issue-was-closed') (exists... -> zero/txn 1.23
234
- transaction rollback on factbase with 100000 facts 0.25
235
- (gt time '2024-03-23T03:21:43Z') 0.33
236
- (gt cost 50) 0.21
237
- (eq title 'Object Thinking 5000') 0.05
238
- (and (eq foo 42.998) (or (gt bar 200) (absent z... 0.05
239
- (and (exists foo) (not (exists blue))) 1.68
240
- (eq id (agg (always) (max id))) 2.76
241
- (join "c<=cost,b<=bar" (eq id (agg (always) (ma... 4.02
242
- (and (eq what "foo") (join "w<=what" (and (eq i... 7.68
243
- delete! 0.56
244
- (and (eq issue *) (eq repository *) (eq what '*') (eq where '*')) 2.75
245
- Taped.append() x50000 0.16
246
- Taped.each() x125 1.63
247
- Taped.delete_if() x375 0.84
248
- 50000 facts: read-only txn (no copy needed) 7.60
249
- 50000 facts: rollback txn (no copy needed) 7.47
250
- 50000 facts: insert in txn (copy triggered) 3.64
251
- 50000 facts: modify in txn (copy triggered) 39.42
252
- 100000 facts: read-only txn (no copy needed) 15.23
253
- 100000 facts: rollback txn (no copy needed) 15.17
254
- 100000 facts: insert in txn (copy triggered) 7.45
255
- 100000 facts: modify in txn (copy triggered) 73.97
228
+ import 5000 facts without index 0.01
229
+ query 5000 facts building index on-the-fly 0.09
230
+ (and (eq what 'issue-was-closed') (exists... -> 200 1.11
231
+ (and (eq what 'issue-was-closed') (exists... -> 200/txn 1.23
232
+ (and (eq what 'issue-was-closed') (exists... -> zero 1.18
233
+ (and (eq what 'issue-was-closed') (exists... -> zero/txn 1.30
234
+ transaction rollback on factbase with 100000 facts 0.28
235
+ (gt time '2024-03-23T03:21:43Z') 0.37
236
+ (gt cost 50) 0.18
237
+ (eq title 'Object Thinking 5000') 0.03
238
+ (and (eq foo 42.998) (or (gt bar 200) (absent z... 0.03
239
+ (and (exists foo) (not (exists blue))) 1.73
240
+ (eq id (agg (always) (max id))) 2.77
241
+ (join "c<=cost,b<=bar" (eq id (agg (always) (ma... 4.70
242
+ (and (eq what "foo") (join "w<=what" (and (eq i... 7.58
243
+ delete! 0.51
244
+ (and (eq issue *) (eq repository *) (eq what '*') (eq where '*')) 0.43
245
+ Taped.append() x50000 0.02
246
+ Taped.each() x125 1.15
247
+ Taped.delete_if() x375 0.97
248
+ 50000 facts: read-only txn (no copy needed) 5.30
249
+ 50000 facts: rollback txn (no copy needed) 5.16
250
+ 50000 facts: insert in txn (copy triggered) 3.23
251
+ 50000 facts: modify in txn (copy triggered) 34.56
252
+ 100000 facts: read-only txn (no copy needed) 12.28
253
+ 100000 facts: rollback txn (no copy needed) 12.19
254
+ 100000 facts: insert in txn (copy triggered) 6.57
255
+ 100000 facts: modify in txn (copy triggered) 70.11
256
256
  ```
257
257
 
258
258
  The results were calculated in [this GHA job][benchmark-gha]
259
- on 2025-12-11 at 13:29,
259
+ on 2026-02-04 at 05:19,
260
260
  on Linux with 4 CPUs.
261
261
  <!-- benchmark_end -->
262
262
 
263
- [benchmark-gha]: https://github.com/yegor256/factbase/actions/runs/20134646978
263
+ [benchmark-gha]: https://github.com/yegor256/factbase/actions/runs/21659492807
data/Rakefile CHANGED
@@ -35,7 +35,7 @@ task :picks do
35
35
  next if OS.windows?
36
36
  %w[test lib].each do |d|
37
37
  Dir["#{d}/**/*.rb"].each do |f|
38
- qbash("bundle exec ruby #{Shellwords.escape(f)}", log: $stdout, env: { 'PICKS' => 'yes' })
38
+ qbash("bundle exec ruby #{Shellwords.escape(f)}", stdout: $stdout, env: { 'PICKS' => 'yes' })
39
39
  end
40
40
  end
41
41
  end
@@ -15,8 +15,8 @@ class Factbase::IndexedFact
15
15
  # Ctor.
16
16
  # @param [Factbase::Fact] origin The original fact
17
17
  # @param [Hash] idx The index
18
- # @param [Boolean] fresh True if this is a newly inserted fact (not yet in index)
19
- def initialize(origin, idx, fresh: false)
18
+ # @param [Set] fresh The shared set of fresh fact IDs
19
+ def initialize(origin, idx, fresh)
20
20
  @origin = origin
21
21
  @idx = idx
22
22
  @fresh = fresh
@@ -30,7 +30,7 @@ class Factbase::IndexedFact
30
30
  others do |*args|
31
31
  # Only clear index when modifying properties on existing (non-fresh) facts
32
32
  # Fresh facts are not in the index yet, so modifications don't affect it
33
- @idx.clear if args[0].to_s.end_with?('=') && !@fresh
33
+ @idx.clear if args[0].to_s.end_with?('=') && !@fresh.include?(object_id)
34
34
  @origin.send(*args)
35
35
  end
36
36
  end
@@ -21,17 +21,21 @@ class Factbase::IndexedFactbase
21
21
  # Constructor.
22
22
  # @param [Factbase] origin Original factbase to decorate
23
23
  # @param [Hash] idx Index to use
24
- def initialize(origin, idx = {})
24
+ # @param [Set] fresh The set of IDs of newly inserted facts
25
+ def initialize(origin, idx = {}, fresh = Set.new)
25
26
  raise 'Wrong type of original' unless origin.respond_to?(:query)
26
27
  @origin = origin
27
28
  raise 'Wrong type of index' unless idx.is_a?(Hash)
28
29
  @idx = idx
30
+ @fresh = fresh
29
31
  end
30
32
 
31
33
  # Insert a new fact and return it.
32
34
  # @return [Factbase::Fact] The fact just inserted
33
35
  def insert
34
- Factbase::IndexedFact.new(@origin.insert, @idx, fresh: true)
36
+ f = Factbase::IndexedFact.new(@origin.insert, @idx, @fresh)
37
+ @fresh.add(f.object_id)
38
+ f
35
39
  end
36
40
 
37
41
  # Convert a query to a term.
@@ -49,7 +53,9 @@ class Factbase::IndexedFactbase
49
53
  def query(term, maps = nil)
50
54
  term = to_term(term) if term.is_a?(String)
51
55
  q = @origin.query(term, maps)
52
- Factbase::IndexedQuery.new(q, @idx, self)
56
+ q = Factbase::IndexedQuery.new(q, @idx, self, @fresh)
57
+ @fresh.clear
58
+ q
53
59
  end
54
60
 
55
61
  # Run an ACID transaction.
@@ -57,9 +63,10 @@ class Factbase::IndexedFactbase
57
63
  def txn
58
64
  result =
59
65
  @origin.txn do |fbt|
60
- yield Factbase::IndexedFactbase.new(fbt, @idx)
66
+ yield Factbase::IndexedFactbase.new(fbt, @idx, @fresh)
61
67
  end
62
68
  @idx.clear
69
+ @fresh.clear
63
70
  result
64
71
  end
65
72
 
@@ -101,6 +108,7 @@ class Factbase::IndexedFactbase
101
108
  @origin.import(bytes)
102
109
  @idx.clear
103
110
  end
111
+ @fresh.clear
104
112
  end
105
113
 
106
114
  # Size, the total number of facts in the factbase.
@@ -17,10 +17,12 @@ class Factbase::IndexedQuery
17
17
  # Constructor.
18
18
  # @param [Factbase::Query] origin Original query
19
19
  # @param [Hash] idx The index
20
- def initialize(origin, idx, fb)
20
+ # @param [Set] fresh The set of IDs of newly inserted facts
21
+ def initialize(origin, idx, fb, fresh)
21
22
  @origin = origin
22
23
  @idx = idx
23
24
  @fb = fb
25
+ @fresh = fresh
24
26
  end
25
27
 
26
28
  # Print it as a string.
@@ -37,7 +39,7 @@ class Factbase::IndexedQuery
37
39
  return to_enum(__method__, fb, params) unless block_given?
38
40
  a = @origin.each(fb, params).to_a
39
41
  a.each do |f|
40
- yield Factbase::IndexedFact.new(f, @idx)
42
+ yield Factbase::IndexedFact.new(f, @idx, @fresh)
41
43
  end
42
44
  a.size
43
45
  end
@@ -108,7 +108,7 @@ class Factbase::Syntax
108
108
  comment = false if comment && c == "\n"
109
109
  next if comment
110
110
  if quotes.include?(c)
111
- if string && acc[acc.length - 1] == '\\'
111
+ if string && acc[-1] == '\\'
112
112
  acc = acc[0..-2]
113
113
  else
114
114
  string = !string
@@ -27,7 +27,7 @@ class Factbase::Defn < Factbase::TermBase
27
27
  fn = @operands[0]
28
28
  raise "A symbol expected as first argument of 'defn'" unless fn.is_a?(Symbol)
29
29
  raise "Can't use '#{fn}' name as a term" if Factbase::Term.method_defined?(fn)
30
- raise "Term '#{fn}' is already defined" if Factbase::Term.private_instance_methods(false).include?(fn)
30
+ raise "Term '#{fn}' is already defined" if Factbase::Term.private_method_defined?(fn, false)
31
31
  raise "The '#{fn}' is a bad name for a term" unless fn.match?(/^[a-z_]+$/)
32
32
  e = "class Factbase::Term\nprivate\ndef #{fn}(fact, maps, fb)\n#{@operands[1]}\nend\nend"
33
33
  # rubocop:disable Security/Eval
@@ -25,7 +25,7 @@ class Factbase::Undef < Factbase::TermBase
25
25
  assert_args(1)
26
26
  fn = @operands[0]
27
27
  raise "A symbol expected as first argument of 'undef'" unless fn.is_a?(Symbol)
28
- if Factbase::Term.private_instance_methods(false).include?(fn)
28
+ if Factbase::Term.private_method_defined?(fn, false)
29
29
  Factbase::Term.class_eval("undef :#{fn}", __FILE__, __LINE__ - 1) # undef :foo
30
30
  end
31
31
  true
@@ -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.19.3' unless const_defined?(:VERSION)
12
+ VERSION = '0.19.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.19.3
4
+ version: 0.19.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko