Documentation

BitArray
in package

A simple, fast array of bits.

Table of Contents

$bits  : SplFixedArray<string|int, int>
Bits represented as an array of integers.
$size  : int
Size of the bit array in bits.
__construct()  : mixed
Creates a new bit array with a given size.
__toString()  : string
Returns a string representation of the bit array.
appendBit()  : void
Appends a bit to the array.
appendBitArray()  : void
Appends another bit array to this array.
appendBits()  : void
Appends a number of bits (up to 32) to the array.
clear()  : void
Clears the bit array, unsetting every bit.
ensureCapacity()  : void
Ensures that the array has a minimum capacity.
flip()  : void
Flips a specific bit.
get()  : bool
Gets a specific bit.
getBitArray()  : SplFixedArray<string|int, int>
Gets the internal bit array.
getNextSet()  : int
Gets the next set bit position from a given position.
getNextUnset()  : int
Gets the next unset bit position from a given position.
getSize()  : int
Gets the size in bits.
getSizeInBytes()  : int
Gets the size in bytes.
isRange()  : bool
Checks if a range of bits is set or not set.
reverse()  : void
Reverses the array.
set()  : void
Sets a specific bit.
setBulk()  : void
Sets a bulk of bits.
setRange()  : void
Sets a range of bits.
toBytes()  : SplFixedArray<string|int, int>
Converts the bit array to a byte array.
xorBits()  : void
Makes an exclusive-or comparision on the current bit array.

Properties

$bits

Bits represented as an array of integers.

private SplFixedArray<string|int, int> $bits

$size

Size of the bit array in bits.

private int $size

Methods

__construct()

Creates a new bit array with a given size.

public __construct(int $size) : mixed
Parameters
$size : int
Return values
mixed

__toString()

Returns a string representation of the bit array.

public __toString() : string
Return values
string

appendBit()

Appends a bit to the array.

public appendBit(bool $bit) : void
Parameters
$bit : bool
Return values
void

appendBitArray()

Appends another bit array to this array.

public appendBitArray(self $other) : void
Parameters
$other : self
Return values
void

appendBits()

Appends a number of bits (up to 32) to the array.

public appendBits(int $value, int $numBits) : void
Parameters
$value : int
$numBits : int
Tags
throws
InvalidArgumentException

if num bits is not between 0 and 32

Return values
void

clear()

Clears the bit array, unsetting every bit.

public clear() : void
Return values
void

ensureCapacity()

Ensures that the array has a minimum capacity.

public ensureCapacity(int $size) : void
Parameters
$size : int
Return values
void

flip()

Flips a specific bit.

public flip(int $i) : void
Parameters
$i : int
Return values
void

get()

Gets a specific bit.

public get(int $i) : bool
Parameters
$i : int
Return values
bool

getBitArray()

Gets the internal bit array.

public getBitArray() : SplFixedArray<string|int, int>
Return values
SplFixedArray<string|int, int>

getNextSet()

Gets the next set bit position from a given position.

public getNextSet(int $from) : int
Parameters
$from : int
Return values
int

getNextUnset()

Gets the next unset bit position from a given position.

public getNextUnset(int $from) : int
Parameters
$from : int
Return values
int

getSize()

Gets the size in bits.

public getSize() : int
Return values
int

getSizeInBytes()

Gets the size in bytes.

public getSizeInBytes() : int
Return values
int

isRange()

Checks if a range of bits is set or not set.

public isRange(int $start, int $end, bool $value) : bool
Parameters
$start : int
$end : int
$value : bool
Tags
throws
InvalidArgumentException

if end is smaller than start

Return values
bool

reverse()

Reverses the array.

public reverse() : void
Return values
void

set()

Sets a specific bit.

public set(int $i) : void
Parameters
$i : int
Return values
void

setBulk()

Sets a bulk of bits.

public setBulk(int $i, int $newBits) : void
Parameters
$i : int
$newBits : int
Return values
void

setRange()

Sets a range of bits.

public setRange(int $start, int $end) : void
Parameters
$start : int
$end : int
Tags
throws
InvalidArgumentException

if end is smaller than start

Return values
void

toBytes()

Converts the bit array to a byte array.

public toBytes(int $bitOffset, int $numBytes) : SplFixedArray<string|int, int>
Parameters
$bitOffset : int
$numBytes : int
Return values
SplFixedArray<string|int, int>

xorBits()

Makes an exclusive-or comparision on the current bit array.

public xorBits(self $other) : void
Parameters
$other : self
Tags
throws
InvalidArgumentException

if sizes don't match

Return values
void

Search results