This is a mirror of official site: http://jasper-net.blogspot.com/

BitVector32 in .NET

| Monday, May 16, 2011
After talking about BitArray class in .NET as a lesser-used data collection type designed for improving the efficiency and ease of dealing with bits and small integers, I think it’s also worth talking about a related structure, BitVector32, located in System.Collection.Specialized namespace. As the namespace suggests, this is also a specialized collection type that is built with the intention to improve the efficiency of operating on bits and small integers.

Bit Vector is a known data structure in computer programming for specific applications and in one way or another each programming framework provides a good way to deal with this structure. Essentially, bit vectors provide a mechanism for dealing with bits and small integers in a space-efficient manner.

It’s important to emphasize on the fact that unlike BitArray that is a class, BitVector32 is a structure and is built based on another structure, System.Collections.Specialized.Bitvector32.Section. BitVector32 has a better efficiency than BitArray as the latter one can grow as much as needed (as I described before) but the former one has a constant 32 bits storage.

A BitVector32 can be set up in two different ways: using sections for small integers or bit flags for Booleans. Generally, using the section to work with a BitVector32 requires special attention as a tiny mistake can yield strange results.

BitVector32 provides two constructors:

BitVector32(BitVector32): Initiates the structure using the data in another BitVector32 object.
BitVector32(Int32): Initiates the structure using the data represented by an integer number.

Read more: Keyvan Nayyeri

Posted via email from Jasper-net

0 comments: