# Bit Field Set

[![]( "Apache 2.0 Licensed")](
[![Hex version]( "Hex version")](

Store and manipulate a set of bit flags, mostly used for syncing the state over the wire between peers in a peer to peer network, such as BitTorrent.

## Usage

# Create a new bit field set with the new command.
# (initial content, size in bits, an optional info hash)
bitfield =!(<<0b00110001>>, 8, "my_info_hash")
# => %BitFieldSet{info_hash: "my_info_hash", pieces: #MapSet<[2, 3, 7]>, size: 8}

# set the first bit
bitfield = BitFieldSet.set(bitfield, 0)
# => %BitFieldSet{info_hash: "my_info_hash", pieces: #MapSet<[0, 2, 3, 7]>, size: 8}

bitfield = BitFieldSet.remove(bitfield, 3)
# => %BitFieldSet{info_hash: "my_info_hash", pieces: #MapSet<[0, 2, 7]>, size: 8}

BitFieldSet.to_binary(bitfield) # => <<161>>

## Installation

Bit Field Set is [available in Hex](, the package can be installed by adding  bit_field_set to your list of dependencies in `mix.exs`:

``` elixir
def deps do
  [{:bit_field_set, "~> 0.1.0"}]

This module does not need to be started as an application, just use it as is.

## Development

Fork the project and fetch the dependencies.

  * The project uses [QuickCheck for Elixir]( from [Quviq]( to test its behavior. Please download an follow the install instructions for QuickCheck Mini to run the property tests.

  * Benchmarks are performed by [Benchfella](, a project by [Alexei Sholik]( Nothing special is needed besides fetching the mix dependencies.

## License

Copyright 2016 Martin Gausby

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.