承接 kariricode/data-structure 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kariricode/data-structure

最新稳定版本:v1.1.3

Composer 安装命令:

composer require kariricode/data-structure

包简介

The KaririCode DataStructure component offers advanced PHP data structures, including lists, stacks, queues, maps, and sets. It features efficient, strongly-typed, object-oriented implementations like ArrayList, LinkedList, BinaryHeap, and TreeMap.

README 文档

README

en pt-br

PHP Composer Data Structures

The KaririCode Data Structure component provides a collection of advanced data structures implemented in PHP, designed with strong typing and object-oriented principles. It includes implementations for various common structures like dynamic arrays, linked lists, heaps, queues, maps, sets, and stacks.

Features

  • ArrayList: A dynamic array providing fast access and amortized O(1) complexity for adding elements.
  • LinkedList: A doubly linked list with O(1) insertion and removal at both ends, and O(n) for arbitrary index access.
  • BinaryHeap: A binary heap (min-heap or max-heap) with O(log n) for insertions, removals, and polling.
  • HashMap: A hash-based map providing average O(1) complexity for put, get, and remove operations.
  • TreeMap: A self-balancing red-black tree map with O(log n) time complexity for put, get, and remove operations.
  • TreeSet: A set implementation backed by TreeMap, ensuring elements are stored in a sorted order.
  • ArrayDeque: A double-ended queue using a circular array with amortized O(1) operations at both ends.
  • ArrayStack: A stack implemented using a dynamic array, providing O(1) complexity for push, pop, and peek operations.

Installation

To install the KaririCode DataStructure component, use the following command:

composer require kariricode/data-structure

Basic Usage

ArrayList Example

use KaririCode\DataStructure\Collection\ArrayList;

$list = new ArrayList();
$list->add("Item 1");
$list->add("Item 2");
echo $list->get(0); // Outputs: Item 1

LinkedList Example

use KaririCode\DataStructure\Collection\LinkedList;

$linkedList = new LinkedList();
$linkedList->add("First");
$linkedList->add("Second");
$linkedList->remove("First");

BinaryHeap Example

use KaririCode\DataStructure\Heap\BinaryHeap;

$heap = new BinaryHeap();
$heap->add(10);
$heap->add(5);
$heap->add(20);
echo $heap->poll(); // Outputs: 5 (min-heap by default)

HashMap Example

use KaririCode\DataStructure\Map\HashMap;

$map = new HashMap();
$map->put("key1", "value1");
echo $map->get("key1"); // Outputs: value1

TreeSet Example

use KaririCode\DataStructure\Set\TreeSet;

$set = new TreeSet();
$set->add("value1");
$set->add("value2");
echo $set->contains("value1"); // Outputs: true

ArrayStack Example

use KaririCode\DataStructure\Stack\ArrayStack;

$stack = new ArrayStack();
$stack->push("First");
$stack->push("Second");
echo $stack->peek(); // Outputs: Second
$stack->pop();       // Removes "Second"

ArrayDeque Example

use KaririCode\DataStructure\Queue\ArrayDeque;

$deque = new ArrayDeque();
$deque->addFirst("First");
$deque->addLast("Last");
echo $deque->peekLast(); // Outputs: Last
$deque->removeLast();    // Removes "Last"

Testing

To run tests for the KaririCode DataStructure component, execute the following command:

make test

License

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

Support and Community

Built with ❤️ by the KaririCode team. Maintained by Walmir Silva - walmir.silva@kariricode.org

统计信息

  • 总下载量: 1.05k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-26