Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Changes marshal dump/load format to be size of in-memory bitmap #22

Merged
merged 1 commit into from

2 participants

@aishfenton

No description provided.

@igrigorik igrigorik merged commit b77bf71 into igrigorik:master
@igrigorik
Owner

Nice - thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
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
Something went wrong with that request. Please try again.