Project

bitindex

0.0
No commit activity in last 3 years
No release in over 3 years
This library contains a Writer and Reader interface to create files where the position of a bit within the file indicates a true or false value.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 2.10
 Project Readme

Bitindex Build Status

Bitindex is a simple gem for writing binary files where the position of a 1 in the bits of the file indicates a true value and 0 indicates a false. The default is to read from left to right so that a file that consists of 1000 1000 could be read to return true for the value 0 and the value 4 and false for all other integer values.

require 'bitindex'

file = 'example.bits'
size_in_bytes = 1024
w = Bitindex::Writer.new file, size_in_bytes
w.write [1,2,3,8000]

r = Bitindex::Reader.new file
r.set? 1      # true
r.set? 8000   # true
r.set? 8001   # false
r.set? 2**32  # false
r.all_set(0..10) # [1,2,3]

Install

require 'bitindex'

Specifics

A project I was working was given a file that mapped the 32bit address space into a 530MB file where bits set to 1 indicated integer values that were set. I decided to expand the library to handle both the reading and writing of these files. Creating files of that size on my desktop (few year old MacBook Pro) takes about 10 minutes. But reading from the file is fairly quick.

Future enhancements:

  • compressing and decompressing the file
  • optimizing the Writer so that it faster for index files with long sequences of 1s or 0s A block_size option has been added to enable long blocks of zeros. On my laptop, the creation of a 530M index with index values went from 10 minutes to about a minute using {block_size: 1024*1024}.
  • allowing the Writer to set and unset individual bits

Limitations

This library ignores the potential difference of hardware, bit ordering and all that stuff and relys on the ruby implementation to handle those details. It is suitable for creating and using files under a common platform and operating system.