Documentation

SkipList
in package
implements Iterator, ArrayAccess, Countable, Serializable

Represents a SkipList

Interfaces, Classes, Traits and Enums

Iterator
ArrayAccess
Countable
Serializable

Table of Contents

$comparator  : callable|null
$head  : SkipNode
$level  : int
$maxLevel  : int
$number_elements  : int
$position  : SkipNode
__call()  : mixed
Magic method to call closure as object method
__construct()  : mixed
Constructor method
add()  : SkipNode
Adds a value to the SkipList if not present
addMany()  : void
Adds multiple values to the SkipList
count()  : int
Returns the number of elements in the SkipList
current()  : mixed
Returns the current value during iteration
delete()  : bool
Deletes a value from the SkipList
getRandom()  : mixed|null
Returns a random element from the SkipList
getRandomM()  : array<string|int, mixed>
Returns an array of random elements from the SkipList
key()  : null
Returns the current key during iteration
next()  : void
Moves the iterator to the next element
offsetExists()  : bool
Checks if an offset exists
offsetGet()  : mixed|null
Returns the value at the specified offset
offsetSet()  : void
Sets the value at the specified offset
offsetUnset()  : void
Unsets the value at the specified offset
printList()  : mixed
Prints the values in the SkipList, separated by levels
rewind()  : void
Rewinds the iterator to the first element
search()  : SkipNode|null
Searches for a value in the SkipList. SkipNode returned.
searchRange()  : array<string|int, mixed>
Searches for values in a range in the SkipList
serialize()  : string
Serializes the SkipList except the Closures
setComparator()  : mixed
Sets the comparator function used for sorting
toArray()  : array<string|int, mixed>
Returns an array representation of the SkipList
unserialize()  : void
Unserializes the SkipList except the Closures
valid()  : bool
Checks if the current position of the iterator is valid
randomLevel()  : int
Generates a random level for a new node in the SkipList

Properties

$comparator

private callable|null $comparator

The comparison function used for sorting

$level

private int $level

The current level of the SkipList

$maxLevel

private int $maxLevel

The maximum level of the SkipList

$number_elements

private int $number_elements

The number of elements in the SkipList

Methods

__call()

Magic method to call closure as object method

public __call(string $method, array<string|int, mixed> $args) : mixed
Parameters
$method : string

The name of the method

$args : array<string|int, mixed>

The arguments passed to the method

Return values
mixed

The result of the method

__construct()

Constructor method

public __construct([int $maxLevel = 10 ][, callable|null $comparator = null ]) : mixed
Parameters
$maxLevel : int = 10

The maximum level of the SkipList (default 10)

$comparator : callable|null = null

The comparison function used for sorting (default null)

Tags
throws
ErrorException

If the maximum level is less than 1

Return values
mixed

add()

Adds a value to the SkipList if not present

public add(mixed $val) : SkipNode
Parameters
$val : mixed

The value to add to the SkipList

Return values
SkipNode

The SkipNode containing the added value or the SkipNode already present with the value specified

addMany()

Adds multiple values to the SkipList

public addMany(array<string|int, mixed> &$arr) : void
Parameters
$arr : array<string|int, mixed>

An array of values to add to the SkipList

Return values
void

count()

Returns the number of elements in the SkipList

public count() : int
Return values
int

The number of elements in the SkipList

current()

Returns the current value during iteration

public current() : mixed
Return values
mixed

The current value

delete()

Deletes a value from the SkipList

public delete(mixed $val) : bool
Parameters
$val : mixed

The value to delete from the SkipList

Return values
bool

true if the value was successfully deleted, false otherwise

getRandom()

Returns a random element from the SkipList

public getRandom() : mixed|null
Return values
mixed|null

A random element from the SkipList, or null if the SkipList is empty

getRandomM()

Returns an array of random elements from the SkipList

public getRandomM(int $number) : array<string|int, mixed>
Parameters
$number : int

The number of random elements to return

Return values
array<string|int, mixed>

An array of random elements from the SkipList

key()

Returns the current key during iteration

public key() : null
Return values
null

next()

Moves the iterator to the next element

public next() : void
Return values
void

offsetExists()

Checks if an offset exists

public offsetExists(mixed $offset) : bool
Parameters
$offset : mixed

The offset to check

Return values
bool

True if the offset exists, false otherwise

offsetGet()

Returns the value at the specified offset

public offsetGet(mixed $offset) : mixed|null
Parameters
$offset : mixed

The offset to retrieve the value from

Return values
mixed|null

The value at the specified offset, or null if the offset is out of bounds

offsetSet()

Sets the value at the specified offset

public offsetSet(mixed $offset, mixed $value) : void
Parameters
$offset : mixed

The offset to set the value at

$value : mixed

The value to set at the specified offset

Return values
void

offsetUnset()

Unsets the value at the specified offset

public offsetUnset(mixed $offset) : void
Parameters
$offset : mixed

The offset to unset the value at

Return values
void

printList()

Prints the values in the SkipList, separated by levels

public printList([Closure $string_converter = null ]) : mixed
Parameters
$string_converter : Closure = null

A function to convert each value to a string

Return values
mixed

rewind()

Rewinds the iterator to the first element

public rewind() : void
Return values
void

Searches for a value in the SkipList. SkipNode returned.

public search(mixed $val) : SkipNode|null
Parameters
$val : mixed

The value to search for

Return values
SkipNode|null

The SkipNode containing the value, or null if the value is not in the SkipList

searchRange()

Searches for values in a range in the SkipList

public searchRange(mixed $val, mixed $valEnd) : array<string|int, mixed>
Parameters
$val : mixed

The starting value of the range

$valEnd : mixed

The ending value of the range

Return values
array<string|int, mixed>

An array of values in the range

serialize()

Serializes the SkipList except the Closures

public serialize() : string
Return values
string

The serialized representation of the SkipList

setComparator()

Sets the comparator function used for sorting

public setComparator(callable|null $comparator) : mixed
Parameters
$comparator : callable|null

The comparison function used for sorting

Return values
mixed

toArray()

Returns an array representation of the SkipList

public toArray() : array<string|int, mixed>
Return values
array<string|int, mixed>

An array representation of the SkipList

unserialize()

Unserializes the SkipList except the Closures

public unserialize(string $data) : void
Parameters
$data : string

The serialized representation of the SkipList

Return values
void

valid()

Checks if the current position of the iterator is valid

public valid() : bool
Return values
bool

True if the position is valid, false otherwise

randomLevel()

Generates a random level for a new node in the SkipList

private randomLevel() : int
Return values
int

The level of the new node

Search results