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 +4 -4
- data/Gemfile +0 -2
- data/README.md +28 -10
- data/cuckoo_filter.gemspec +3 -0
- data/lib/cuckoo_filter/bucket.rb +2 -0
- data/lib/cuckoo_filter/cuckoo_filter.rb +8 -2
- data/lib/cuckoo_filter/version.rb +1 -1
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c147bf11916c1061a594a6c677c78b8c887379f
|
4
|
+
data.tar.gz: 722643649aca8a6fe103d82487c65cc7af8f98b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e90957909720a3fdfdedc627c38c7f7f7e6406bc0b332f17c513cc9222aa4880919aebe07ebf1b9c5ebd5eb6a74149eef4fd8ff8509e43b1fa71e14ffb174ec
|
7
|
+
data.tar.gz: e3b80aa3385304c5a2ce8f51e07d7cf60cd20bb3452e72c46e02cc71a68dc2deb0ba205f12d66eba56128c8908469970e0a4b9b556386a239096d70a58604f17
|
data/Gemfile
CHANGED
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
|
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
|
61
|
-
A:
|
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: *
|
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
|
|
data/cuckoo_filter.gemspec
CHANGED
@@ -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
|
data/lib/cuckoo_filter/bucket.rb
CHANGED
@@ -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) ||
|
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
|
-
|
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
|
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.
|
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-
|
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
|