2

I am looking for an off-the-shelf dynamic bit vector in C or C++ that I can use. Unfortunately for various reasons I cannot use the BoosT libraries at the moment. std:bitvector looks promising but it is templated so I cannot set the length of the bit vector dynamically. Can anyone advise? Thanks!

skaffman
  • 381,978
  • 94
  • 789
  • 754
dustin ledezma
  • 585
  • 2
  • 5
  • 10
  • can't you use `vector` as a base for your bitvector? – Ali1S232 Jun 04 '11 at 21:00
  • and you can use reserve as many data as you want or just call push_back – Ali1S232 Jun 04 '11 at 21:02
  • 6
    What is it about Boost that disqualifies it? I ask because I want to make sure the *other* third-party classes people might recommend don't also suffer from the same things that prevent you from using Boost. – Rob Kennedy Jun 04 '11 at 21:03
  • Please see http://stackoverflow.com/q/551579. Also, please list your requirements in detail. Do you need to access the bits in packed form with a C pointer? If so, you can implement your own resizable bit container using `vector` or `vector` together with some bitwise operations. – rwong Jun 04 '11 at 21:05
  • also http://stackoverflow.com/q/670308 – rwong Jun 04 '11 at 21:11

2 Answers2

2

You don't have to put a dependency onto all of boost and its installation process just to use dynamic_bitset. If the class suits your purposes, copy the source files for it specifically into your project tree and put it in a separate namespace called "boostcopy" (or something like that).

On a similar note, I made my own resizable array class modeled after dynamic_bitset called "Nstate", which you can template to an arbitrary radix and still get tight packing. Perhaps of interest:

http://hostilefork.com/nstate/

2

I have never used vector<bool> (See Scott Meyers' Effective STL item 18) but it might be just what you are looking for.

dalle
  • 16,659
  • 3
  • 53
  • 75
IronMensan
  • 6,520
  • 1
  • 24
  • 35