A Bite-Sized BitArray

A few things that would elevate this past "like an array but more compact" to think about:

  • one of the things a bit array could be valuable for is encoding/decoding binary packed data. So appending integers in a particular order and width could be very useful (append Int32 as little endian), as would "extract 7 bits starting from index I into an Int(8/32/64)"
  • providing a "view" of the bits projected into Int8/16/32/64 in both bit and little endian
  • supporting and/or/xor/nor/xnor on equal length bit arrays
  • population count (like bitArray.filter { $0 == true }.count but faster(*))

Oh, and be careful to ignore people who bikes head too many extra features onto your summer volunteer job ;-) (yes, I'm actually aiming that humor straight at me & my requests here)

(*) many CPUs have a "population count" operation counting the number of set bits in a register. (note: http://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=E6D7DF3C490F7CB59E216CFAF796AE56?doi=10.1.1.127.8246&rep=rep1&type=pdf describes a fast software implementation, there are many more out there)

3 Likes