splitclient-rb 7.3.5.pre.rc1-java → 7.3.5.pre.rc2-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 52ee386fb2542467575c4f58ddfd25b3d33ff33e
4
- data.tar.gz: 6a6d7cd53ca3d0c7ad30c8fa8d3621c43e9a63d2
3
+ metadata.gz: 4057a9d01946967eb3b35a624eb4456c72c67c4b
4
+ data.tar.gz: 28ab3e1971b46453a94392bb5c1b2230a9b1c226
5
5
  SHA512:
6
- metadata.gz: fb3e3c3dac2de8df3994d40bb10ba3dddf1e1ca8ae382a144980ddb8ba61ff76fb4dad4f40ce4755ed0f81e63650f84ca238c9b4c1353db86dfa39891131be88
7
- data.tar.gz: f68eb21afac8f031a56eecb358d1e79520f38036b44f20f0596e07163b1cf1c4b50263f419b9388d556d2e919f206bffa17bd4f16e7f25276ba6d592487b3268
6
+ metadata.gz: 1e90fe6953a748f65a96c38b96924821aef9403c52ba525bc5157c4840047c82213c8cb184dae31f2f206841bf028f6d058ab0254df5e7fef0bc9fc0b589a248
7
+ data.tar.gz: 1b43e98f1e5a400988d2d87e29c5a37075720469b71187f0760019cd9f76850bd2a54fcf084de25ad9c15093a95f7d8e908593051989cc89092c5de03feefcce
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bitarray'
4
+
5
+ module SplitIoClient
6
+ module Cache
7
+ module Filter
8
+ class BloomFilter
9
+ def initialize(capacity, false_positive_probability = 0.001)
10
+ @capacity = capacity.round
11
+ m = best_m(capacity, false_positive_probability)
12
+ @ba = BitArray.new(m.round)
13
+ @k = best_k(capacity)
14
+ end
15
+
16
+ def add(string)
17
+ return false if contains?(string)
18
+
19
+ positions = hashes(string)
20
+
21
+ positions.each { |position| @ba[position] = 1 }
22
+
23
+ true
24
+ end
25
+
26
+ def contains?(string)
27
+ !hashes(string).any? { |ea| @ba[ea] == 0 }
28
+ end
29
+
30
+ def clear
31
+ @ba.size.times { |i| @ba[i] = 0 }
32
+ end
33
+
34
+ private
35
+
36
+ # m is the required number of bits in the array
37
+ def best_m(capacity, false_positive_probability)
38
+ -(capacity * Math.log(false_positive_probability)) / (Math.log(2) ** 2)
39
+ end
40
+
41
+ # k is the number of hash functions that minimizes the probability of false positives
42
+ def best_k(capacity)
43
+ (Math.log(2) * (@ba.size / capacity)).round
44
+ end
45
+
46
+ def hashes(data)
47
+ m = @ba.size
48
+ h = Digest::MD5.hexdigest(data.to_s).to_i(16)
49
+ x = h % m
50
+ h /= m
51
+ y = h % m
52
+ h /= m
53
+ z = h % m
54
+ [x] + 1.upto(@k - 1).collect do |i|
55
+ x = (x + y) % m
56
+ y = (y + z) % m
57
+ x
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -10,13 +10,13 @@ module SplitIoClient
10
10
  end
11
11
 
12
12
  def add(feature_name, key)
13
- @filter.insert("#{feature_name}#{key}")
13
+ @filter.add("#{feature_name}#{key}")
14
14
  rescue StandardError => e
15
15
  @config.log_found_exception(__method__.to_s, e)
16
16
  end
17
17
 
18
18
  def contains?(feature_name, key)
19
- @filter.include?("#{feature_name}#{key}")
19
+ @filter.contains?("#{feature_name}#{key}")
20
20
  rescue StandardError => e
21
21
  @config.log_found_exception(__method__.to_s, e)
22
22
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bloomfilter-rb'
4
-
5
3
  module SplitIoClient
6
4
  class SplitFactory
7
5
  ROOT_PROCESS_ID = Process.pid
@@ -218,7 +216,7 @@ module SplitIoClient
218
216
  return
219
217
  end
220
218
 
221
- bf = BloomFilter::Native.new(size: 95_850_584, hashes: 2)
219
+ bf = Cache::Filter::BloomFilter.new(30_000_000)
222
220
  filter_adapter = Cache::Filter::FilterAdapter.new(@config, bf)
223
221
  cache = Concurrent::Hash.new
224
222
  @unique_keys_tracker = Engine::Impressions::UniqueKeysTracker.new(@config, filter_adapter, @impressions_sender_adapter, cache)
@@ -1,3 +1,3 @@
1
1
  module SplitIoClient
2
- VERSION = '7.3.5.pre.rc1'
2
+ VERSION = '7.3.5.pre.rc2'
3
3
  end
@@ -12,6 +12,7 @@ require 'splitclient-rb/cache/adapters/memory_adapter'
12
12
  require 'splitclient-rb/cache/adapters/redis_adapter'
13
13
  require 'splitclient-rb/cache/fetchers/segment_fetcher'
14
14
  require 'splitclient-rb/cache/fetchers/split_fetcher'
15
+ require 'splitclient-rb/cache/filter/bloom_filter'
15
16
  require 'splitclient-rb/cache/filter/filter_adapter'
16
17
  require 'splitclient-rb/cache/hashers/impression_hasher'
17
18
  require 'splitclient-rb/cache/observers/impression_observer'
@@ -50,7 +50,7 @@ Gem::Specification.new do |spec|
50
50
  spec.add_development_dependency 'timecop', '~> 0.9'
51
51
  spec.add_development_dependency 'webmock', '~> 3.14'
52
52
 
53
- spec.add_runtime_dependency 'bloomfilter-rb', '~> 2.1'
53
+ spec.add_runtime_dependency 'bitarray', '~> 1.3'
54
54
  spec.add_runtime_dependency 'concurrent-ruby', '~> 1.0'
55
55
  spec.add_runtime_dependency 'faraday', '>= 0.8', '< 2.0'
56
56
  spec.add_runtime_dependency 'json', '>= 1.8', '< 3.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: splitclient-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.3.5.pre.rc1
4
+ version: 7.3.5.pre.rc2
5
5
  platform: java
6
6
  authors:
7
7
  - Split Software
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-06 00:00:00.000000000 Z
11
+ date: 2022-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -197,15 +197,15 @@ dependencies:
197
197
  requirements:
198
198
  - - "~>"
199
199
  - !ruby/object:Gem::Version
200
- version: '2.1'
201
- name: bloomfilter-rb
200
+ version: '1.3'
201
+ name: bitarray
202
202
  prerelease: false
203
203
  type: :runtime
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
206
  - - "~>"
207
207
  - !ruby/object:Gem::Version
208
- version: '2.1'
208
+ version: '1.3'
209
209
  - !ruby/object:Gem::Dependency
210
210
  requirement: !ruby/object:Gem::Requirement
211
211
  requirements:
@@ -402,6 +402,7 @@ files:
402
402
  - lib/splitclient-rb/cache/adapters/redis_adapter.rb
403
403
  - lib/splitclient-rb/cache/fetchers/segment_fetcher.rb
404
404
  - lib/splitclient-rb/cache/fetchers/split_fetcher.rb
405
+ - lib/splitclient-rb/cache/filter/bloom_filter.rb
405
406
  - lib/splitclient-rb/cache/filter/filter_adapter.rb
406
407
  - lib/splitclient-rb/cache/hashers/impression_hasher.rb
407
408
  - lib/splitclient-rb/cache/observers/impression_observer.rb