SortedTreeNodeCollection extends TreeNodeCollection
Sorted Tree Node Collection
Note: This collection works only with integers as offset keys and not with much datasets. You have been warned!
Table of Contents
Methods
- __construct() : mixed
- Constructor
- __serialize() : mixed
- Returns class state to be serialized.
- __unserialize() : mixed
- Fills the current node with the given serialized information
- append() : mixed
- Adds a node to the internal list in a sorted approach
- asort() : mixed
- Sorts the internal nodes array
- contains() : bool
- Checks if a specific node is inside the collection
- dataFromArray() : mixed
- Sets the data of the node collection by a given array
- nodeCompare() : int
- Compares a node with another one
- serialize() : string
- Returns the serialized instance
- toArray() : array<string|int, mixed>
- Returns the collection in an array representation for e.g. serialization
- unserialize() : mixed
- Create class state from serialized array.
- binarySearch() : int
- Binary search that returns the offset of a given node
- normalize() : mixed
- Normalizes the array by reordering the keys
- offsetOf() : int
- Returns the offset key of given node
Methods
__construct()
Constructor
public
__construct([array<string|int, mixed> $data = [] ]) : mixed
You can move an initial data array to initialize the instance and further objects. This is useful for the deserialization.
Parameters
- $data : array<string|int, mixed> = []
__serialize()
Returns class state to be serialized.
public
__serialize() : mixed
Tags
Attributes
- #[ReturnTypeWillChange]
__unserialize()
Fills the current node with the given serialized information
public
__unserialize(mixed $arrayRepresentation) : mixed
Parameters
- $arrayRepresentation : mixed
Tags
Attributes
- #[ReturnTypeWillChange]
append()
Adds a node to the internal list in a sorted approach
public
append(TreeNode $node) : mixed
Parameters
- $node : TreeNode
Tags
Attributes
- #[ReturnTypeWillChange]
asort()
Sorts the internal nodes array
public
asort([int $flags = SORT_REGULAR ]) : mixed
Parameters
- $flags : int = SORT_REGULAR
-
Optional parameter, ignored. Added to be compatible with asort method signature in PHP 8.
Tags
Attributes
- #[ReturnTypeWillChange]
contains()
Checks if a specific node is inside the collection
public
contains(TreeNode $node) : bool
Parameters
- $node : TreeNode
Return values
booldataFromArray()
Sets the data of the node collection by a given array
public
dataFromArray(array<string|int, mixed> $data) : mixed
Parameters
- $data : array<string|int, mixed>
nodeCompare()
Compares a node with another one
public
nodeCompare(TreeNode $node, TreeNode $otherNode) : int
Parameters
Tags
Return values
intserialize()
Returns the serialized instance
public
serialize() : string
Tags
Attributes
- #[ReturnTypeWillChange]
Return values
stringtoArray()
Returns the collection in an array representation for e.g. serialization
public
toArray() : array<string|int, mixed>
Return values
array<string|int, mixed>unserialize()
Create class state from serialized array.
public
unserialize(string $serializedString) : mixed
Parameters
- $serializedString : string
Tags
Attributes
- #[ReturnTypeWillChange]
binarySearch()
Binary search that returns the offset of a given node
protected
binarySearch(TreeNode $node, int $start, int $end) : int
Parameters
- $node : TreeNode
- $start : int
- $end : int
Return values
intnormalize()
Normalizes the array by reordering the keys
protected
normalize() : mixed
offsetOf()
Returns the offset key of given node
protected
offsetOf(TreeNode $node) : int
Parameters
- $node : TreeNode