BitCollection Class |
[This is preliminary documentation and is subject to change.]
Namespace: Condensed
The BitCollection type exposes the following members.
| Name | Description | |
|---|---|---|
| BitCollection |
Constructs a new instance of the BitCollection class.
| |
| BitCollection(Int32) |
Constructs a new instance of the BitCollection class with the specified initial capacity.
| |
| BitCollection(Int32, Boolean, Int32) |
Constructs a new instance of the BitCollection class with the specified initial values.
|
| Name | Description | |
|---|---|---|
| Capacity |
Gets/sets the total number of elements the internal data structure can hold without resizing.
| |
| Count |
Gets the number of elements contained in the collection.
| |
| IsReadOnly |
Gets a value indicating whether the collection is read-only.
| |
| Item |
Gets or sets the value of the bit at a specific position in the BitCollection.
|
| Name | Description | |
|---|---|---|
| Add |
Adds an item to the collection.
| |
| Clear |
Removes all items from the collection.
| |
| Contains |
Determines whether the collection contains a specific value.
| |
| CopyTo |
Copies the entire BitCollection to a compatible one-dimensional array of bools, starting at the specified index of the target array.
| |
| Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
| Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
| GetEnumerator |
Returns an enumerator that iterates through the collection.
| |
| GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
| GetType | Gets the Type of the current instance. (Inherited from Object.) | |
| IndexOf |
Searches for the specified value and returns the zero-based index of the first occurrence within the collection.
| |
| Insert |
Inserts an element into the collection at the specified index.
| |
| MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
| Remove |
Removes the first occurrence of the specified value from the collection.
| |
| RemoveAt |
Removes the value at the specified index.
| |
| ToString | Returns a string that represents the current object. (Inherited from Object.) |
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).