cuckoo_filter 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: 707afee2fc96bb39d3c1b6e1c9acaf343ca18bba
4
- data.tar.gz: 5a9d7af30d472875b0cca4a591dfcc62a8e89a01
3
+ metadata.gz: 9c147bf11916c1061a594a6c677c78b8c887379f
4
+ data.tar.gz: 722643649aca8a6fe103d82487c65cc7af8f98b1
5
5
  SHA512:
6
- metadata.gz: e25982c4ed2dba998b33fc59bdccc9935769ff604b06d4598a716eb6c5564391f992f2a7273e2ddd4523bf2581168f34fb602e9e60ef0dc235a33163c8b4027a
7
- data.tar.gz: a32123806cbce6aded4d69a9dfee5207c632e6aaf6b1bb74b0ba3b97e06db447f51631d2215757ea7840b7687a67c4509b43da871ed1b7de6e423bc3514d557b
6
+ metadata.gz: 0e90957909720a3fdfdedc627c38c7f7f7e6406bc0b332f17c513cc9222aa4880919aebe07ebf1b9c5ebd5eb6a74149eef4fd8ff8509e43b1fa71e14ffb174ec
7
+ data.tar.gz: e3b80aa3385304c5a2ce8f51e07d7cf60cd20bb3452e72c46e02cc71a68dc2deb0ba205f12d66eba56128c8908469970e0a4b9b556386a239096d70a58604f17
data/Gemfile CHANGED
@@ -2,5 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in cuckoo_filter.gemspec
4
4
  gemspec
5
-
6
- gem 'fnv-hash'
data/README.md CHANGED
@@ -54,20 +54,38 @@ cf.delete("foo")
54
54
 
55
55
  ## Frequenty Anticipated Questions
56
56
 
57
- - Q: *Is this useful?*
58
- A: Yes, but mainly for academic purposes.
57
+ - Q: *Is this useful?* </br>
58
+ A: Yes, but have a look at the benchmarks below to see if it satisfies your performance requirements before using it in a real world app.
59
59
 
60
- - Q: *Why not for practical purposes?*
61
- A: Because Ruby is not a performance-oriented language. It is made to be expressive, so it lacks a lot of low-level constructs needed to make this implementation fast and efficient enough.
60
+ - Q: *Why did you make this?*</br>
61
+ A: For fun and education, of course! Although that is not stopping it from having any real world usage!
62
62
 
63
- - Q: *Then why did you make this?*
64
- A: For fun and education, of course!
65
-
66
- - Q: *But why Ruby? Why not Go/Rust/Elixir/FooBar*
63
+ - Q: *But why Ruby? Why not Go/Rust/Elixir/FooBar*</br>
67
64
  A: Because why not? I like Ruby and I couldn't find a full blown implementation in it.
68
65
 
69
- - Q: *Can I use it in a real project?*
70
- A: If it satisfies your criteria, then why not? Let me know if you do!
66
+ - Q: *Can I use it in a real project?*</br>
67
+ A: If it satisfies your criteria, then why not? Have a look at the benchmarks for performance stats. Let me know if you do!
68
+
69
+ ## Benchmarks
70
+
71
+ You can run the benchmark script to see the iterations per second performance of different methods on an initially half full filter.
72
+
73
+ ```
74
+ $ ruby test/benchmark.rb
75
+
76
+ Setting up for benchmarking...
77
+ Done.
78
+ Warming up --------------------------------------
79
+ # warmup stats -> can be ignored
80
+
81
+ Calculating -------------------------------------
82
+ Iterations per second - Insertions
83
+ 214.863M (±47.1%) i/s - 1.214B in 9.859735s
84
+ Iterations per second - Lookups
85
+ 355.392M (±10.9%) i/s - 3.371B in 9.697599s
86
+ Iterations per second - Deletions
87
+ 343.890M (± 9.6%) i/s - 3.286B
88
+ ```
71
89
 
72
90
  ## Development
73
91
 
@@ -25,4 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "byebug"
26
26
  spec.add_development_dependency "pry"
27
27
  spec.add_development_dependency "codecov"
28
+ spec.add_development_dependency "benchmark-ips"
29
+
30
+ spec.add_runtime_dependency "fnv-hash"
28
31
  end
@@ -19,6 +19,8 @@ module CuckooFilter
19
19
  #
20
20
  # @return [Boolean] whether the insertion was successful
21
21
  def insert(fingerprint)
22
+ return false unless has_space?
23
+
22
24
  @slots.each do |slot|
23
25
  if slot.empty?
24
26
  slot.set(fingerprint)
@@ -49,6 +49,8 @@ module CuckooFilter
49
49
  #
50
50
  # @return [Boolean] true if successful insertion, else false
51
51
  def insert(item)
52
+ return false unless has_space?
53
+
52
54
  fingerprint = fingerprint(item)
53
55
  first_index = hash(item)
54
56
  second_index = alt_index(first_index, fingerprint)
@@ -99,12 +101,12 @@ module CuckooFilter
99
101
  first_index = hash(item)
100
102
  second_index = alt_index(first_index, fingerprint)
101
103
 
102
- if @buckets[first_index].remove(fingerprint) || @buckets[second_index].remove(fingerprint)
104
+ if @buckets[first_index].remove(fingerprint) || @buckets[second_index].remove(fingerprint)
103
105
  decrement_filled_count
104
106
  return true
105
107
  end
106
108
 
107
- return false
109
+ false
108
110
  end
109
111
 
110
112
  private
@@ -142,5 +144,9 @@ module CuckooFilter
142
144
  def size_mask
143
145
  ((1 << Math.log2(@num_buckets).to_i) - 1)
144
146
  end
147
+
148
+ def has_space?
149
+ @filled < @size
150
+ end
145
151
  end
146
152
  end
@@ -1,3 +1,3 @@
1
1
  module CuckooFilter
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cuckoo_filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pawan Dubey
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-16 00:00:00.000000000 Z
11
+ date: 2017-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,6 +94,34 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: benchmark-ips
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: fnv-hash
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
97
125
  description:
98
126
  email:
99
127
  - hi@pawandubey.com