halfdan / ruby-bitfield

This Ruby C extension wraps boost::dynamic_bitset and makes it available as a native Ruby class. The bitset behaves like an an array allowing only values of 0 and 1
BSD 2-Clause "Simplified" License
3 stars 1 forks source link

Bitset serialization #2

Open DanielHeath opened 5 years ago

DanielHeath commented 5 years ago

As of https://github.com/boostorg/dynamic_bitset/commit/d644c83b137b5eae5aa0d5b350d2861c19b45f63, dynamic_bitset supports the serialize interface.

It'd be really handy to be able to serialize / deserialize large bitsets (eg to save a computed bloom filter).

Would a PR be accepted? I'm willing to give it a go, but I've forgotten most of the C++ I've learned.

halfdan commented 4 years ago

@DanielHeath Hi there - apologies for the late reply. In case you're still interested I'm more than happy to accept a PR :)

DanielHeath commented 4 years ago

I ended up writing my own pure-ruby bitfield, which turned out to be easy to serialize and faster for my use case.

The trick was to use a ruby string with the ASCII encoding for the buffer; this made bit-twiddling easy, since you can use chr / ord to get the numbers.