-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dump load #15
base: main
Are you sure you want to change the base?
Dump load #15
Conversation
attr_reader :field, :reverse_byte, :size | ||
include Enumerable | ||
|
||
VERSION = "1.4.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed from 1.3.0
.
include Enumerable | ||
|
||
VERSION = "1.4.0" | ||
HEADER_LENGTH = 8 + 1 # QC (@size, @reverse_byte) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use this here, but need it for BitArrayFile
.
|
||
def ==(rhs) | ||
@size == rhs.size && @reverse_byte == rhs.reverse_byte && @field == rhs.field | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the ability to compare two BitArray
objects. This makes it a bit easier to add tests.
end | ||
|
||
combined | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote this because it allows parallelising bloom filter creation. I don't personally need this method, but figured it might be useful for others.
private def byte_position(position) | ||
@reverse_byte ? position : 7 - position | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following two methods, dump
and load
, are new.
private def seek_to(position) | ||
@io.seek(position + HEADER_LENGTH) | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's actually fairly easy to implement the rest of BitArray
, allowing this to be read/write instead of read-only. But it's quite a bit slower, at least for large bitarrays and nobody's likely to care for small bitarrays. Seemed to be unnecessary bloat.
@@ -0,0 +1,65 @@ | |||
require "minitest/autorun" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that I'm more familiar with rspec. Please excuse me if these tests aren't how most people would write Minitest
tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a way, Minitest is to RSpec as Sinatra is to Rails. Minitest is far less opinionated and freeform which has upsides and downsides, but a big upside is pretty much any approach that works and fits into a project's own style is all good! :)
I've merged the previous one but this will take a little bit more review - thanks for now though! |
73f65aa
to
9c070df
Compare
Rebased off of |
What
This PR allows
BitArray
to be dumped to disk and subsequently loaded from disk. It also adds the ability to union two bitarrays. And there's a new class,BitArrayFile
, allowing for read-only access to a dumpedBitArray
, providing a means to query the array without having to load it in to RAM.Tests
Additionally, I tested this with a bitarray consisting of a little over 2 billion bits. I was able to
dump
,load
, and useBitArrayFile
to query the bits.