ShortcutSkipList
in package
implements
Iterator, ArrayAccess, Countable, Serializable
Represents a ShortcutSkipList, an array of SkipLists indexed by a dynamic dictionary.
Interfaces, Classes, Traits and Enums
- Iterator
- ArrayAccess
- Countable
- Serializable
Table of Contents
- $chars : int
- $comparator : callable|null
- $maxLevel : int
- $skipLists : array<string|int, mixed>
- $string_converter : callable|null
- $totalCount : int
- __call() : mixed
- Magic method to call closure as object method
- __construct() : mixed
- Constructor method of ShortcutSkipList
- add() : SkipNode
- Adds a value to the ShortcutSkipList if not present
- addMany() : void
- Adds multiple values to the ShortcutSkipList
- count() : int
- Returns the number of elements in the ShortcutSkipList
- current() : mixed
- Returns the current value during iteration
- delete() : bool
- Deletes a value from the ShortcutSkipList
- getRandomM() : array<string|int, mixed>
- Returns an array of random elements from the ShortcutSkipList
- key() : string
- 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 all SkipLists of the ShortcutSkipList, one by one
- rewind() : void
- Rewinds the iterator to the first element
- search() : SkipNode|null
- Searches for a value in the ShortcutSkipList. SkipNode returned.
- searchRange() : array<string|int, mixed>
- Searches for values in a range in the ShortcutSkipList
- serialize() : string
- Serializes the ShortcutSkipList except the Closures
- setComparator() : mixed
- Sets the comparator function used for sorting
- setStringConverter() : mixed
- Sets the string converter function used for converting values to string
- unserialize() : void
- Unserializes the ShortcutSkipList except the Closures
- valid() : bool
- Checks if the current position of the iterator is valid
Properties
$chars
private
int
$chars
Number of characters to use as shortcut
$comparator
private
callable|null
$comparator
The comparison function used for sorting
$maxLevel
private
int
$maxLevel
The maximum level of the SkipLists
$skipLists
private
array<string|int, mixed>
$skipLists
Array of SkipLists
$string_converter
private
callable|null
$string_converter
A function to convert each value to a string
$totalCount
private
int
$totalCount
Total number of values in all SkipLists
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 of ShortcutSkipList
public
__construct([int $maxLevel = 10 ][, int $chars = 2 ][, callable|null $comparator = null ][, callable|null $string_converter = null ]) : mixed
Parameters
- $maxLevel : int = 10
-
The maximum level of the SkipLists (default 10)
- $chars : int = 2
-
Number of characters to use as shortcut
- $comparator : callable|null = null
-
The comparison function used for sorting (default null)
- $string_converter : callable|null = null
-
A function to convert each value to a string (default null)
Tags
Return values
mixed —add()
Adds a value to the ShortcutSkipList if not present
public
add(mixed $val) : SkipNode
Parameters
- $val : mixed
-
The value to add to the ShortcutSkipList
Return values
SkipNode —The SkipNode containing the added value or the SkipNode already present with the value specified
addMany()
Adds multiple values to the ShortcutSkipList
public
addMany(array<string|int, mixed> &$arr) : void
Parameters
- $arr : array<string|int, mixed>
-
An array of values to add to the ShortcutSkipList
Return values
void —count()
Returns the number of elements in the ShortcutSkipList
public
count() : int
Return values
int —The number of elements in the ShortcutSkipList
current()
Returns the current value during iteration
public
current() : mixed
Return values
mixed —The current value
delete()
Deletes a value from the ShortcutSkipList
public
delete(mixed $val) : bool
Parameters
- $val : mixed
-
The value to delete from the ShortcutSkipList
Return values
bool —true if the value was successfully deleted, false otherwise
getRandomM()
Returns an array of random elements from the ShortcutSkipList
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 SkipLists
key()
Returns the current key during iteration
public
key() : string
Return values
string —The current shortcut index of $skipLists array
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 all SkipLists of the ShortcutSkipList, one by one
public
printList() : mixed
Return values
mixed —rewind()
Rewinds the iterator to the first element
public
rewind() : void
Return values
void —search()
Searches for a value in the ShortcutSkipList. 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 ShortcutSkipList
searchRange()
Searches for values in a range in the ShortcutSkipList
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 ShortcutSkipList except the Closures
public
serialize() : string
Return values
string —The serialized representation of the ShortcutSkipList
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 —setStringConverter()
Sets the string converter function used for converting values to string
public
setStringConverter(mixed $string_converter) : mixed
Parameters
- $string_converter : mixed
Return values
mixed —unserialize()
Unserializes the ShortcutSkipList except the Closures
public
unserialize(string $data) : void
Parameters
- $data : string
-
The serialized representation of the ShortcutSkipList
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