jruby-bloomfilter 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/.rvmrc +1 -0
- data/README +0 -0
- data/benchmark/memory.rb +28 -0
- data/lib/bloomfilter.rb +46 -0
- data/lib/ext/java-bloomfilter-0.9.3.jar +0 -0
- data/spec/bloomfilter_spec.rb +36 -0
- data/spec/spec_helper.rb +6 -0
- metadata +73 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm --create use jruby-1.6.2@bloomfilter
|
data/README
ADDED
File without changes
|
data/benchmark/memory.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
$:<< 'lib'
|
2
|
+
|
3
|
+
require 'benchmark'
|
4
|
+
require 'bloomfilter'
|
5
|
+
|
6
|
+
n = 100_000
|
7
|
+
|
8
|
+
Benchmark.bm do |b|
|
9
|
+
filter = Bloomfilter.new(100_000, 0.01)
|
10
|
+
|
11
|
+
b.report('insert') do
|
12
|
+
n.times do |i|
|
13
|
+
filter << 'a'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
b.report('lookup present') do
|
18
|
+
n.times do
|
19
|
+
filter.include?('a')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
b.report('lookup missing') do
|
24
|
+
n.times do
|
25
|
+
filter.include?('b')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/bloomfilter.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'java'
|
4
|
+
require 'ext/java-bloomfilter-0.9.3'
|
5
|
+
|
6
|
+
require 'serializer'
|
7
|
+
|
8
|
+
module Jar
|
9
|
+
import com.skjegstad.utils.BloomFilter
|
10
|
+
end
|
11
|
+
|
12
|
+
class Bloomfilter
|
13
|
+
include Serialization
|
14
|
+
|
15
|
+
def initialize(options = {})
|
16
|
+
if options[:size] && options[:false_positive_percentage]
|
17
|
+
@filter = Jar::BloomFilter.new(options[:false_positive_percentage], options[:size])
|
18
|
+
elsif options[:filter]
|
19
|
+
@filter = options[:filter]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def << (k)
|
24
|
+
@filter.add(k)
|
25
|
+
end
|
26
|
+
|
27
|
+
def include?(k)
|
28
|
+
@filter.contains(k)
|
29
|
+
end
|
30
|
+
|
31
|
+
def count
|
32
|
+
@filter.count
|
33
|
+
end
|
34
|
+
|
35
|
+
# def store(path)
|
36
|
+
# raise 'Cannot call store without specifying :serializer in initlialize options' unless @serializer
|
37
|
+
# @serializer.store(path, @filter)
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# def self.load(type, path)
|
41
|
+
# serializer = Serialization.serializer(type)
|
42
|
+
# filter = serializer.load(path)
|
43
|
+
# Bloomfilter.new(:filter => filter)
|
44
|
+
# end
|
45
|
+
|
46
|
+
end
|
Binary file
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative 'spec_helper'
|
4
|
+
|
5
|
+
require 'tempfile'
|
6
|
+
|
7
|
+
describe Bloomfilter do
|
8
|
+
before :all do
|
9
|
+
@filter = Bloomfilter.new(:size => 1_000, :false_positive_percentage => 0.01)
|
10
|
+
@path = Tempfile.new('bloomfilter').path
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should not have any elements from start' do
|
14
|
+
@filter.count.should == 0
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#<<' do
|
18
|
+
it 'should be possible to add elements which updates the count' do
|
19
|
+
@filter << 'hello'
|
20
|
+
@filter.count.should == 1
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#include?' do
|
25
|
+
it 'should return false if an element does not exist' do
|
26
|
+
@filter.include?('world').should be_false
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should return true if an element exists' do
|
30
|
+
@filter.include?('hello').should be_true
|
31
|
+
|
32
|
+
@filter << 'world'
|
33
|
+
@filter.include?('world').should be_true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jruby-bloomfilter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 1.0.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Daniel Gaiottino
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-07-11 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: jets3t-rb
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.0.0
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
description: JRuby wrapper (+ some extra functionality) to http://code.google.com/p/java-bloomfilter
|
27
|
+
email:
|
28
|
+
- daniel@burtcorp.com
|
29
|
+
executables: []
|
30
|
+
|
31
|
+
extensions: []
|
32
|
+
|
33
|
+
extra_rdoc_files: []
|
34
|
+
|
35
|
+
files:
|
36
|
+
- .gitignore
|
37
|
+
- .rvmrc
|
38
|
+
- README
|
39
|
+
- benchmark/memory.rb
|
40
|
+
- lib/bloomfilter.rb
|
41
|
+
- lib/ext/java-bloomfilter-0.9.3.jar
|
42
|
+
- spec/bloomfilter_spec.rb
|
43
|
+
- spec/spec_helper.rb
|
44
|
+
homepage: http://github.com/gaiottino/bloomfilter
|
45
|
+
licenses: []
|
46
|
+
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project: jruby-bloomfilter
|
67
|
+
rubygems_version: 1.8.5
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: JRuby wrapper for java-bloomfilter
|
71
|
+
test_files:
|
72
|
+
- spec/bloomfilter_spec.rb
|
73
|
+
- spec/spec_helper.rb
|