bloom-filter 0.2.0 → 0.2.2

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ec61bc4b1ff47f3c4733eef85b25f09809746139
4
+ data.tar.gz: 4144685fea073d1e34bb34f3525fea79b4808761
5
+ SHA512:
6
+ metadata.gz: d455b2f9007301813a0f4eaebdae2c0cc4f3924c333b19f3ce5bd643614ffda0e9adfba6830a42b0c88d027b3c65fd83e2df4b7c6fb139f4defb6fcef8c7e28b
7
+ data.tar.gz: 9d2e692903025019a3f46a0a1baeba08bf6cdcbf6d8717ede3fc9470f677052e187c6b137bc67f961e01144f82eef0df6a6bc11be3370dea4c64279fc5a72540
data/CHANGELOG CHANGED
@@ -1,3 +1,15 @@
1
+ === 0.2.1 (2013-01-21)
2
+
3
+ * Clean up compiler warnings.
4
+
5
+ === 0.2.0 (2012-04-27)
6
+
7
+ * Added BloomFilter#bits
8
+
9
+ === 0.1.1 (2012-01-26)
10
+
11
+ * Store table size in dumps.
12
+
1
13
  === 0.1.0 (2012-01-25)
2
14
 
3
15
  * Initial version.
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ MIT
2
+
3
+ Copyright (c) 2015 Bharanee Rathna
4
+
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
7
+ this software and associated documentation files (the "Software"), to deal in
8
+ the Software without restriction, including without limitation the rights to
9
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10
+ the Software, and to permit persons to whom the Software is furnished to do so,
11
+ subject to the following conditions:
12
+
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
20
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
21
+ OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -22,6 +22,7 @@ BloomFilter is a ruby library that implements an in-memory [Bloom Filter](http:/
22
22
  #insert
23
23
  #include?
24
24
  #bits
25
+ #binary
25
26
 
26
27
  ```
27
28
 
@@ -45,17 +46,22 @@ BloomFilter is a ruby library that implements an in-memory [Bloom Filter](http:/
45
46
  filter.dump "/tmp/random.bloom"
46
47
  filter = BloomFilter.load "/tmp/random.bloom"
47
48
 
48
- bits = filter.bits #=> "10010100100111..."
49
+ bits = filter.bits #=> "10010100100111..."
50
+ binary = filter.binary #=> "\x83Ö\xAC\xEA\u00..."
51
+
52
+ filter2 = BloomFilter.new bits: 100_000_0, hashes: 4
53
+ filter2.binary = binary
54
+ filter2.include? "foo" #=> true
49
55
  ```
50
56
 
51
57
  ## See Also
52
58
 
53
59
  [https://github.com/igrigorik/bloomfilter-rb](https://github.com/igrigorik/bloomfilter-rb)
54
60
 
55
- ## License
56
-
57
- [Creative Commons Attribution - CC BY](http://creativecommons.org/licenses/by/3.0)
58
-
59
61
  ## Home Page
60
62
 
61
63
  [https://github.com/deepfryed/bloom-filter](https://github.com/deepfryed/bloom-filter)
64
+
65
+ ## License
66
+
67
+ MIT
@@ -79,6 +79,7 @@ VALUE bloom_initialize(int argc, VALUE *argv, VALUE self) {
79
79
  rb_raise(rb_eNoMemError, "unable to allocate memory for BloomFilter");
80
80
 
81
81
  DATA_PTR(self) = filter;
82
+ return self;
82
83
  }
83
84
 
84
85
 
@@ -95,12 +96,13 @@ VALUE bloom_include(VALUE klass, VALUE string) {
95
96
 
96
97
  VALUE bloom_dump(VALUE klass, VALUE file) {
97
98
  int fd;
99
+ void *buffer;
98
100
  uint64_t nbits;
99
101
  FileHeader header;
100
102
  BloomFilter *filter = bloom_handle(klass);
101
103
 
102
- nbits = (filter->table_size + 7) / 8;
103
- void *buffer = malloc(nbits);
104
+ nbits = (filter->table_size + 7) / 8;
105
+ buffer = malloc(nbits);
104
106
 
105
107
  if (!buffer)
106
108
  rb_raise(rb_eNoMemError, "out of memory dumping BloomFilter");
@@ -139,12 +141,14 @@ VALUE bloom_dump(VALUE klass, VALUE file) {
139
141
  VALUE bloom_bits(VALUE klass) {
140
142
  BloomFilter *filter = bloom_handle(klass);
141
143
 
142
- int i = 0;
143
- int nbits = filter->table_size;
144
- char buffer[nbits];
145
-
144
+ VALUE bitmap;
145
+ char *buffer;
146
146
  unsigned char b;
147
- int bit;
147
+ int i = 0, bit, nbits = filter->table_size;
148
+
149
+ buffer = (char *)malloc(nbits);
150
+ if (!buffer)
151
+ rb_raise(rb_eNoMemError, "out of memory dumping BloomFilter");
148
152
 
149
153
  for (i = 0; i < nbits; i++) {
150
154
  b = filter->table[i / 8];
@@ -156,7 +160,35 @@ VALUE bloom_bits(VALUE klass) {
156
160
  buffer[i] = '1';
157
161
  }
158
162
 
159
- return rb_str_new(buffer, nbits);
163
+ bitmap = rb_str_new(buffer, nbits);
164
+ free(buffer);
165
+ return bitmap;
166
+ }
167
+
168
+ VALUE bloom_binary(VALUE klass) {
169
+ BloomFilter *filter = bloom_handle(klass);
170
+
171
+ VALUE bitmap;
172
+ unsigned char *buffer;
173
+
174
+ int nbytes = (filter->table_size + 7) / 8;
175
+ buffer = (unsigned char *)malloc(nbytes);
176
+
177
+ if (!buffer)
178
+ rb_raise(rb_eNoMemError, "out of memory dumping BloomFilter");
179
+
180
+ bloom_filter_read(filter, buffer);
181
+
182
+ bitmap = rb_str_new((const char *)buffer, nbytes);
183
+ free(buffer);
184
+ return bitmap;
185
+ }
186
+
187
+ VALUE bloom_binary_set(VALUE klass, VALUE buffer) {
188
+ BloomFilter *filter = bloom_handle(klass);
189
+ unsigned char* ptr = (unsigned char *) RSTRING_PTR(buffer);
190
+ bloom_filter_load(filter, ptr);
191
+ return Qtrue;
160
192
  }
161
193
 
162
194
  VALUE bloom_load(VALUE klass, VALUE file) {
@@ -199,12 +231,14 @@ VALUE bloom_load(VALUE klass, VALUE file) {
199
231
  return instance;
200
232
  }
201
233
 
202
- Init_bloom_filter() {
234
+ void Init_bloom_filter() {
203
235
  VALUE cBloom = rb_define_class("BloomFilter", rb_cObject);
204
236
 
205
237
  rb_define_method(cBloom, "initialize", RUBY_METHOD_FUNC(bloom_initialize), -1);
206
238
  rb_define_method(cBloom, "dump", RUBY_METHOD_FUNC(bloom_dump), 1);
207
239
  rb_define_method(cBloom, "bits", RUBY_METHOD_FUNC(bloom_bits), 0);
240
+ rb_define_method(cBloom, "binary", RUBY_METHOD_FUNC(bloom_binary), 0);
241
+ rb_define_method(cBloom, "binary=", RUBY_METHOD_FUNC(bloom_binary_set), 1);
208
242
  rb_define_method(cBloom, "insert", RUBY_METHOD_FUNC(bloom_insert), 1);
209
243
  rb_define_method(cBloom, "include?", RUBY_METHOD_FUNC(bloom_include), 1);
210
244
 
@@ -1 +1 @@
1
- #define RUBY_BLOOM_FILTER_VERSION "0.2.0"
1
+ #define RUBY_BLOOM_FILTER_VERSION "0.2.2"
@@ -12,4 +12,13 @@ describe 'BloomFilter load & dump' do
12
12
  assert filter.include?("foo")
13
13
  assert !filter.include?("bar")
14
14
  end
15
+
16
+ it 'should accept assigning the bits directly' do
17
+ assert filter = BloomFilter.new(bits: 80)
18
+ assert filter.insert("foo")
19
+ assert filter2 = BloomFilter.new(bits: 80)
20
+ assert filter2.binary = filter.binary
21
+ assert filter2.include?("foo")
22
+ assert !filter2.include?("bar")
23
+ end
15
24
  end
metadata CHANGED
@@ -1,46 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bloom-filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
5
- prerelease:
4
+ version: 0.2.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Bharanee Rathna
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-04-27 00:00:00.000000000 Z
11
+ date: 2015-11-16 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake-compiler
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  description: A fast Bloom Filter library for Ruby for unices.
@@ -51,41 +46,42 @@ extensions:
51
46
  - ext/extconf.rb
52
47
  extra_rdoc_files: []
53
48
  files:
49
+ - CHANGELOG
50
+ - LICENSE
51
+ - README.md
54
52
  - ext/bloom-filter.c
55
- - ext/hash-string.c
56
- - ext/bloom_filter.c
57
53
  - ext/bloom-filter.h
54
+ - ext/bloom_filter.c
55
+ - ext/extconf.rb
56
+ - ext/hash-string.c
58
57
  - ext/hash-string.h
59
58
  - ext/version.h
60
- - ext/extconf.rb
59
+ - lib/bloom-filter.rb
61
60
  - test/helper.rb
62
- - test/test_io.rb
63
61
  - test/test_basic.rb
64
- - README.md
65
- - CHANGELOG
66
- - lib/bloom-filter.rb
62
+ - test/test_io.rb
67
63
  homepage: http://github.com/deepfryed/bloom-filter
68
- licenses: []
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
69
67
  post_install_message:
70
68
  rdoc_options: []
71
69
  require_paths:
72
70
  - lib
73
71
  required_ruby_version: !ruby/object:Gem::Requirement
74
- none: false
75
72
  requirements:
76
- - - ! '>='
73
+ - - ">="
77
74
  - !ruby/object:Gem::Version
78
75
  version: '0'
79
76
  required_rubygems_version: !ruby/object:Gem::Requirement
80
- none: false
81
77
  requirements:
82
- - - ! '>='
78
+ - - ">="
83
79
  - !ruby/object:Gem::Version
84
80
  version: '0'
85
81
  requirements: []
86
82
  rubyforge_project:
87
- rubygems_version: 1.8.21
83
+ rubygems_version: 2.2.2
88
84
  signing_key:
89
- specification_version: 3
85
+ specification_version: 4
90
86
  summary: A fast Bloom Filter library for Ruby.
91
87
  test_files: []