class BitsVector extends BaseVector

Traits

Constants

CB_ZERO_ARG

Properties

protected array $items from  BaseVector

Methods

int
count()

No description

array
toArray()

No description

mixed
first()

No description

mixed
firstOr(mixed $default)

No description

bool
any(callable $callable)

Determines if at least an element of the collection satisfies a condition.

bool
all(callable $callable)

Determines if all elements of the collection satisfies a condition.

static BaseCollection
from(iterable $items)

Create a new collection instance from the specified iterable.

bool
isEmpty()

Determine if a collection is empty.

__construct(iterable $bits = [])

No description

mixed
get(int $key)

No description

mixed
getOr(int $key, mixed $defaultValue)

No description

set(int $key, mixed $value)

No description

unset(int $key)

No description

bool
contains(mixed $value)

No description

clear()

No description

push(mixed $item)

No description

append(iterable $iterable)

Append all elements of the specified iterable to the current vector.

update(iterable $iterable)

Append all elements of the specified iterable to the current vector.

replace(iterable $iterable, int $offset = 0, int $len = 0)

Replace a part of the vector by the specified iterable.

map(callable $callable)

Create a new vector by applying a callback on each element of the vector.

filter(callable $callable)

Create a new vector by filtering each element of the vector according the return value of the specified callback function.

mapKeys(callable $callable)

No description

mapToHashMap(callable $callable)

Allows to map each vector elements into key/value pairs and collect them into a HashMap.

flatMap(callable $callable)

No description

filterKeys(callable $callable)

No description

chunk(int $length)

No description

slice(int $offset, int $length)

No description

implode(string $delimiter)

No description

bigrams()

No description

trigrams()

No description

ngrams(int $n)

No description

bool
offsetExists(mixed $offset)

No description

mixed
offsetGet(mixed $offset)

No description

void
offsetSet(mixed $offset, mixed $value)

No description

void
offsetUnset(mixed $offset)

No description

getIterator()

Retrieve an iterator on the elements of the vector.

static BitsVector
new(int $capacity)

No description

static BitsVector
fromInteger(int $n)

No description

static BitsVector
fromBinaryString(string $bits)

No description

static BitsVector
fromHexString(string $number)

No description

static BitsVector
fromDecoratedHexString(string $expression)

No description

static BitsVector
fromString(string $string)

No description

static BitsVector
random(int $length)

No description

string
toBinaryString()

No description

int
toInteger()

No description

string
toHexString()

No description

array
toBytesArray()

No description

pad(int $length)

Pad the vector with 0 at the leftmost position ("zerofill")

truncate(int $length)

No description

shapeCapacity(int $length)

Truncate or pad the array as needed to ensure a specified length.

copyInteger(int $integer, int $offset, int $length)

Copy the bits of the specified integer to the bits vector at the specified offset.

Details

in WithCollection at line 12
abstract int count()

No description

Return Value

int

in WithCollection at line 13
abstract array toArray()

No description

Return Value

array

in WithCollection at line 15
mixed first()

No description

Return Value

mixed

in WithCollection at line 23
mixed firstOr(mixed $default)

No description

Parameters

mixed $default

Return Value

mixed

in WithCollection at line 45
bool any(callable $callable)

Determines if at least an element of the collection satisfies a condition.

The execution of callbacks stop after a callable returned true.

Parameters

callable $callable

A method returning a boolean with key and value or only value as arguments.

Return Value

bool

True if callback is true for at least one of the elements

Exceptions

ReflectionException

in WithCollection at line 78
bool all(callable $callable)

Determines if all elements of the collection satisfies a condition.

The execution of callbacks stop after a callable returned false.

Parameters

callable $callable

A method returning a boolean with key and value or only value as arguments.

Return Value

bool

True if callback is true for all the elements

Exceptions

ReflectionException

in BaseVector at line 45
static BaseCollection from(iterable $items)

Create a new collection instance from the specified iterable.

Parameters

iterable $items

The elements to put in the new collection

Return Value

BaseCollection

The collection with the elements from the iterable

in BaseVector at line 95
bool isEmpty()

Determine if a collection is empty.

Return Value

bool

true if the collection has 0 element; if not, false.

at line 195
__construct(iterable $bits = [])

No description

Parameters

iterable $bits

in BaseVector at line 53
mixed get(int $key)

No description

Parameters

int $key

Return Value

mixed

in BaseVector at line 61
mixed getOr(int $key, mixed $defaultValue)

No description

Parameters

int $key
mixed $defaultValue

Return Value

mixed

at line 200
BaseVector set(int $key, mixed $value)

No description

Parameters

int $key
mixed $value

Return Value

BaseVector

in BaseVector at line 71
BaseVector unset(int $key)

No description

Parameters

int $key

Return Value

BaseVector

at line 205
bool contains(mixed $value)

No description

Parameters

mixed $value

Return Value

bool

in BaseVector at line 99
BaseVector clear()

No description

Return Value

BaseVector

at line 210
BaseVector push(mixed $item)

No description

Parameters

mixed $item

Return Value

BaseVector

at line 215
BaseVector append(iterable $iterable)

Append all elements of the specified iterable to the current vector.

If a value already exists, the value is still added as a duplicate.

This method returns the instance itself, so you can use it in fluent pattern.

Parameters

iterable $iterable

Return Value

BaseVector

at line 220
BaseVector update(iterable $iterable)

Append all elements of the specified iterable to the current vector.

If a value already exists, it is skipped.

This method returns the instance itself, so you can use it in fluent pattern.

Parameters

iterable $iterable

Return Value

BaseVector

in BaseVector at line 159
BaseVector replace(iterable $iterable, int $offset = 0, int $len = 0)

Replace a part of the vector by the specified iterable.

This method returns the instance itself, so you can use it in fluent pattern.

Parameters

iterable $iterable
int $offset

Allow to replace a part inside the vector by an iterable with keys starting at 0, by adding the specified offset

int $len

The maximum amount of elements to read. If 0, the read isn't bounded

Return Value

BaseVector

in BaseVector at line 198
BaseVector map(callable $callable)

Create a new vector by applying a callback on each element of the vector.

Parameters

callable $callable

The callback function to run for each element.

Return Value

BaseVector

A new map with the mapped elements.

in BaseVector at line 226
BaseVector filter(callable $callable)

Create a new vector by filtering each element of the vector according the return value of the specified callback function.

Example:

$words = new Vector(["foo", "bar", "quux", "xizzy"]);

$threeLettersWords = $words->filter(
    fn(string $word) => strlen($word) === 3
);

// The new vector contains "foo" and "bar".

Parameters

callable $callable

A callback function, which returns a boolean. When true, the element is kept. When false, the element is discarded.

Return Value

BaseVector

A new map with filtered elements

Exceptions

ReflectionException
InvalidArgumentException

in BaseVector at line 242
BaseVector mapKeys(callable $callable)

No description

Parameters

callable $callable

Return Value

BaseVector

in BaseVector at line 259
HashMap mapToHashMap(callable $callable)

Allows to map each vector elements into key/value pairs and collect them into a HashMap.

Parameters

callable $callable

A method to return [$key, $value] array

Return Value

HashMap

in BaseVector at line 282
BaseVector flatMap(callable $callable)

No description

Parameters

callable $callable

Return Value

BaseVector

in BaseVector at line 298
BaseVector filterKeys(callable $callable)

No description

Parameters

callable $callable

Return Value

BaseVector

in BaseVector at line 304
Vector chunk(int $length)

No description

Parameters

int $length

Return Value

Vector

in BaseVector at line 308
BaseVector slice(int $offset, int $length)

No description

Parameters

int $offset
int $length

Return Value

BaseVector

in BaseVector at line 313
OmniString implode(string $delimiter)

No description

Parameters

string $delimiter

Return Value

OmniString

in BaseVector at line 317
Vector bigrams()

No description

Return Value

Vector

in BaseVector at line 321
Vector trigrams()

No description

Return Value

Vector

in BaseVector at line 325
Vector ngrams(int $n)

No description

Parameters

int $n

Return Value

Vector

in BaseVector at line 361
bool offsetExists(mixed $offset)

No description

Parameters

mixed $offset

Return Value

bool

in BaseVector at line 367
mixed offsetGet(mixed $offset)

No description

Parameters

mixed $offset

Return Value

mixed

at line 225
void offsetSet(mixed $offset, mixed $value)

No description

Parameters

mixed $offset
mixed $value

Return Value

void

in BaseVector at line 384
void offsetUnset(mixed $offset)

No description

Parameters

mixed $offset

Return Value

void

in BaseVector at line 402
ArrayIterator getIterator()

Retrieve an iterator on the elements of the vector.

This iterator also allows unsetting and modifying values and keys while iterating.

Return Value

ArrayIterator

at line 15
static BitsVector new(int $capacity)

No description

Parameters

int $capacity

Return Value

BitsVector

at line 23
static BitsVector fromInteger(int $n)

No description

Parameters

int $n

Return Value

BitsVector

at line 27
static BitsVector fromBinaryString(string $bits)

No description

Parameters

string $bits

Return Value

BitsVector

at line 32
static BitsVector fromHexString(string $number)

No description

Parameters

string $number

Return Value

BitsVector

at line 41
static BitsVector fromDecoratedHexString(string $expression)

No description

Parameters

string $expression

Return Value

BitsVector

at line 46
static BitsVector fromString(string $string)

No description

Parameters

string $string

Return Value

BitsVector

at line 53
static BitsVector random(int $length)

No description

Parameters

int $length

Return Value

BitsVector

Exceptions

Exception

at line 71
string toBinaryString()

No description

Return Value

string

at line 75
int toInteger()

No description

Return Value

int

at line 88
string toHexString()

No description

Return Value

string

at line 99
array toBytesArray()

No description

Return Value

array

at line 115
BitsVector pad(int $length)

Pad the vector with 0 at the leftmost position ("zerofill")

Parameters

int $length

The expected length of the vector

Return Value

BitsVector

at line 129
BitsVector truncate(int $length)

No description

Parameters

int $length

Return Value

BitsVector

at line 143
BitsVector shapeCapacity(int $length)

Truncate or pad the array as needed to ensure a specified length.

Parameters

int $length

Return Value

BitsVector

at line 165
BitsVector copyInteger(int $integer, int $offset, int $length)

Copy the bits of the specified integer to the bits vector at the specified offset.

Parameters

int $integer

The integer to copy bits from

int $offset

The position in the vector where to start to copy

int $length

The length the bits of the integer occupy in the vector

Return Value

BitsVector