TBits
[Properties (by Name)][Methods (by Name)][Events (by Name)]
Class to store collections of bits (binary values that can be 0 or 1)
Declaration
Source position: classesh.inc line 384
Type
TBits = class (TObject)
private
FBits : ^TBitArray;
FSize : LongInt;
FBSize : LongInt;
findIndex : LongInt;
findState : Boolean;
procedure SetBit(bit: LongInt; value: Boolean);
procedure SetSize(value: LongInt);
protected
procedure CheckBitIndex(Bit: LongInt; CurrentSize: Boolean);
public
constructor Create(TheSize: LongInt); Virtual;
destructor Destroy; Override;
function GetFSize : LongInt;
procedure SetOn(Bit: LongInt);
procedure Clear(Bit: LongInt);
procedure Clearall;
procedure CopyBits(BitSet: TBits);
procedure AndBits(BitSet: TBits);
procedure OrBits(BitSet: TBits);
procedure XorBits(BitSet: TBits);
procedure NotBits(BitSet: TBits);
function Get(Bit: LongInt) : Boolean;
procedure Grow(NBit: LongInt);
function Equals(Obj: TObject) : Boolean; Override; Overload;
function Equals(BitSet: TBits) : Boolean; Overload;
procedure SetIndex(Index: LongInt);
function FindFirstBit(State: Boolean) : LongInt;
function FindNextBit : LongInt;
function FindPrevBit : LongInt;
function OpenBit : LongInt;
Bits[Bit: LongInt]: Boolean; default;
Size : LongInt;
end
;
Description
TBits can be used to store collections of bits in an indexed array. This is especially useful for storing collections of booleans: Normally the size of a boolean is the size of the smallest enumerated type, i.e. 1 byte. Since a bit can take 2 values it can be used to store a boolean as well. Since TBits can store 8 bits in a byte, it takes 8 times less space to store an array of booleans in a TBits class then it would take to store them in a conventional array.
TBits introduces methods to store and retrieve bit values, apply masks, and search for bits.
Members
Member | Type | Visibility | Description |
---|---|---|---|
AndBits | Method | public | Performs an and operation on the bits. |
Bits | Property | public | Access to all bits in the array. |
CheckBitIndex | Method | protected | |
Clear | Method | public | Clears a particular bit. |
Clearall | Method | public | Clears all bits in the array. |
CopyBits | Method | public | Copy bits from one bits set to another |
Create | Method | public | Creates a new bits collection. |
Destroy | Method | public | Destroys a bit collection |
Equals | Method | public | Determines whether the bits of 2 arrays are equal. |
FBits | Field | private | |
FBSize | Field | private | |
FindFirstBit | Method | public | Find first bit with a particular value |
findIndex | Field | private | |
FindNextBit | Method | public | Searches the next bit with a particular value. |
FindPrevBit | Method | public | Searches the previous bit with a particular value. |
findState | Field | private | |
FSize | Field | private | |
Get | Method | public | Retrieve the value of a particular bit |
GetFSize | Method | public | Returns the number of records used to store the bits. |
Grow | Method | public | Expands the bits array to the requested size. |
NotBits | Method | public | Performs a not operation on the bits. |
OpenBit | Method | public | Returns the position of the first bit that is set to False. |
OrBits | Method | public | Performs an or operation on the bits. |
SetBit | Method | private | |
SetIndex | Method | public | Sets the start position for FindNextBit and FindPrevBit |
SetOn | Method | public | Turn a particular bit on. |
SetSize | Method | private | |
Size | Property | public | Current size of the array of bits. |
XorBits | Method | public | Performs a xor operation on the bits. |
Inheritance
Class | Description |
---|---|
TBits | Class to store collections of bits (binary values that can be 0 or 1) |