Click or drag to resize

BitCollection Class

[This is preliminary documentation and is subject to change.]

A bit vector implementation with IList semantics. Behaves like a ListT of booleans but with more efficient storage.
Inheritance Hierarchy
SystemObject
  CondensedBitCollection

Namespace:  Condensed
Assembly:  Condensed (in Condensed.dll) Version: 0.1.0.0 (0.1.0.0)
Syntax
[SerializableAttribute]
public class BitCollection : IList<bool>, 
	ICollection<bool>, IEnumerable<bool>, IEnumerable

The BitCollection type exposes the following members.

Constructors
  NameDescription
Public methodBitCollection
Constructs a new instance of the BitCollection class.
Public methodBitCollection(Int32)
Constructs a new instance of the BitCollection class with the specified initial capacity.
Public methodBitCollection(Int32, Boolean, Int32)
Constructs a new instance of the BitCollection class with the specified initial values.
Top
Properties
  NameDescription
Public propertyCapacity
Gets/sets the total number of elements the internal data structure can hold without resizing.
Public propertyCount
Gets the number of elements contained in the collection.
Public propertyIsReadOnly
Gets a value indicating whether the collection is read-only.
Public propertyItem
Gets or sets the value of the bit at a specific position in the BitCollection.
Top
Methods
  NameDescription
Public methodAdd
Adds an item to the collection.
Public methodClear
Removes all items from the collection.
Public methodContains
Determines whether the collection contains a specific value.
Public methodCopyTo
Copies the entire BitCollection to a compatible one-dimensional array of bools, starting at the specified index of the target array.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetEnumerator
Returns an enumerator that iterates through the collection.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodIndexOf
Searches for the specified value and returns the zero-based index of the first occurrence within the collection.
Public methodInsert
Inserts an element into the collection at the specified index.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodRemove
Removes the first occurrence of the specified value from the collection.
Public methodRemoveAt
Removes the value at the specified index.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Remarks

The BitCollection is used internally by the CondensedCollectionT, and, while not part of the CondensedCollection's public API, it's marked public in case others find it useful.

The main noteworthy difference between this collection and System.Collections.BitArray is the ability to insert and remove individual bit elements. Performance of insert/remove operations is not terrific (a lot of bitwise shifting may be required), but it's tolerable for infrequent use or when removing/adding items at/near the end of the collection.

Also, word size is 64 bits instead of BitArray's 32 bits. This was done primarily to cut shift operations in half, but overall performance will suffer on 32-bit platforms.

Contains some logic inspired by the very useful "Bit Twiddling Hacks" compiled by Sean Eron Anderson: http://graphics.stanford.edu/~seander/bithacks.html (code is in the public domain).

Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also