Download the PHP package willvincent/splaytree without Composer

On this page you can find all versions of the php package willvincent/splaytree. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package splaytree

PHP Splay Tree Implementation

PHP Version License Latest Version CI Tests

A robust and efficient Splay Tree implementation in PHP, designed for scenarios where frequently accessed elements should be quickly retrievable. This library provides a self-balancing binary search tree that automatically adjusts to prioritize recently accessed nodes, making it ideal for use cases like caching, priority queues, or any application where recent access patterns matter.

Table of Contents

Installation

To install the SplayTree library, use Composer:

Basic Usage

Creating a SplayTree

You can instantiate a SplayTree with or without a custom comparator. By default, it uses PHP’s spaceship operator (<=>) for comparisons.

Inserting Elements

Add elements to the tree using the insert method:

Searching for Elements

Search for an element with the search method. If found, it splays the element to the root and returns it; otherwise, it returns null.

Deleting Elements

Remove an element from the tree with the delete method:

API Documentation

Here’s a detailed breakdown of the SplayTree class’s public methods, including descriptions, parameters, return types, and examples.

insert($data): void

Inserts a new element into the tree and splays it to the root.

Parameters:


search($data): mixed|null

Searches for an element. If found, it splays the element to the root and returns it; otherwise, returns null.

Parameters:

Returns:

Example:


delete($data): void

Deletes an element from the tree if it exists.

Parameters:

Example:


min(): mixed|null

Finds the minimum element, splays it to the root, and returns its data.

Returns:

Example:


max(): mixed|null

Finds the maximum element, splays it to the root, and returns its data.

Returns:

Example:


next($data): mixed|null

Finds the successor of the given data, splays it to the root, and returns its data.

Parameters:

Returns:

Example:


prev($data): mixed|null

Finds the predecessor of the given data, splays it to the root, and returns its data.

Parameters:

Returns:

Example:


getSize(): int

Returns the number of elements in the tree.

Returns:

Example:


isEmpty(): bool

Checks if the tree is empty.

Returns:

Example:


clear(): void

Removes all elements from the tree.

Example:


contains($data): bool

Checks if the tree contains the specified data without modifying the tree structure.

Parameters:

Returns:

Example:


toString(callable $printNode): string

Converts the tree to a string representation using a provided callback to format each node’s data.

Parameters:

Returns**:

Example**:


Iteration

The tree implements IteratorAggregate, allowing iteration over elements in order.

Example:

Advanced Usage

Using a Custom Comparator

For complex data types like objects, define a custom comparator:

Splaying Behavior

Operations like search, insert, or delete splay the accessed or modified node to the root, optimizing future access:

Performance Considerations

Testing

The library is thoroughly tested with PHPUnit. To run the tests:

  1. Install dependencies:

  2. Run PHPUnit:

Good news—all tests are passing! You’re ready to use this library with confidence.

Contributing

Contributions are welcome! Please submit issues or pull requests to the GitHub repository. Follow standard guidelines for code style and include tests with your submissions.

License

This project is licensed under the MIT License - see the LICENSE file for details.


All versions of splaytree with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package willvincent/splaytree contains the following files

Loading the files please wait ....