Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #22 from aishfenton/master

Changes marshal dump/load format to be size of in-memory bitmap
  • Loading branch information...
commit b77bf71778dc0197f1bbe215406ade230ab6b408 2 parents 163d0cd + 1bf24f1
@igrigorik authored
Showing with 16 additions and 10 deletions.
  1. +1 −0  .gitignore
  2. +4 −10 ext/cbloomfilter/cbloomfilter.c
  3. +11 −0 spec/native_spec.rb
View
1  .gitignore
@@ -7,3 +7,4 @@ ext/Makefile
lib/cbloomfilter.so
tmp
Gemfile.lock
+pkg
View
14 ext/cbloomfilter/cbloomfilter.c
@@ -361,13 +361,11 @@ static VALUE bf_bitmap(VALUE self) {
struct BloomFilter *bf;
Data_Get_Struct(self, struct BloomFilter, bf);
- VALUE str = rb_str_new(0, bf->m);
+ VALUE str = rb_str_new(0, bf->bytes);
unsigned char* ptr = (unsigned char *) RSTRING_PTR(str);
- int i;
- for (i = 0; i < bf->m; i++)
- *ptr++ = bucket_get(bf, i);
-
+ memcpy(ptr, bf->ptr, bf->bytes);
+
return str;
}
@@ -376,11 +374,7 @@ static VALUE bf_load(VALUE self, VALUE bitmap) {
Data_Get_Struct(self, struct BloomFilter, bf);
unsigned char* ptr = (unsigned char *) RSTRING_PTR(bitmap);
- int i;
- for (i = 0; i < bf->m; i++) {
- if (*ptr++)
- bucket_set(bf, i);
- }
+ memcpy(bf->ptr, ptr, bf->bytes);
return Qnil;
}
View
11 spec/native_spec.rb
@@ -140,5 +140,16 @@
bf.send(:same_parameters?, bf2).should be_true
end
+
+ it "should serialize to a file size proporational its bucket size" do
+ fs_size = 0
+ 8.times do |i|
+ bf = Native.new(size: 10_000, bucket: i+1)
+ bf.save('bf.out')
+ prev_size, fs_size = fs_size, File.size('bf.out')
+ prev_size.should < fs_size
+ end
+ end
+
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.