opmvpc / constructs
数据结构
1.0.1
2020-06-05 13:57 UTC
Requires
- php: >=7.2
- symfony/var-dumper: ^4.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- nunomaduro/phpinsights: ^1.7
- phpunit/phpunit: ^8.5
- vimeo/psalm: ^3.11
This package is auto-updated.
Last update: 2024-09-05 23:10:02 UTC
README
Constructs
Constructs提供具有流畅API的简单数据结构。
- 安装
- 列表
- ArrayList
- LinkedList
- 栈
- ArrayStack
- LinkedStack
- 队列
- ArrayQueue
- 三元组
- ArrayHeap
- SearchThree
- 辅助工具
- toArray()
- dump() & dumpAndDie()
🛠 安装
只需将此软件包添加到您的composer项目中
$ composer require opmvpc/constructs
然后,在您的代码中导入Constructs的主类或单个类。
列表
可用方法
public static function make(): ListContract; public function size(): int; public function contains($item): bool; public function add($item): ListContract; public function remove($item): ListContract; public function get(int $i); public function toArray(): array;
ArrayList
用法
$list = Construct::arrayList() ->add(4) ->add(2) ->remove(4) ->add(6);
LinkedList
用法
$list = Construct::linkedList() ->add(4) ->add(2) ->add(6);
复杂度
栈
可用方法
public static function make(): StackContract; public function isEmpty(): bool; public function push($item): StackContract; public function pop(): StackContract; public function top(); public function toArray(): array;
ArrayStack
用法
$stack = Construct::linkedStack() ->push(4) ->push(2) ->pop();
LinkedStack
用法
$stack = Construct::linkedStack() ->push(4) ->push(2) ->pop();
复杂度
队列
可用方法
public static function make(): QueueContract; public function isEmpty(): bool; public function enqueue($item): QueueContract; public function dequeue(); public function peek(); public function toArray(): array;
ArrayQueue
用法
$queue = Construct::linkedQueue() ->enqueue(4) ->enqueue(2) ->dequeue() ->enqueue(6);
复杂度
三元组
ArrayHeap
可用方法
public static function make(): ThreeContract; public function size(): int; public function add($item): ThreeContract; public function remove($item): ThreeContract; public function get(int $i): SimpleNode; public function toArray(): array;
用法
$heap = Construct::arrayHeap() ->add(4) ->add(2) ->remove(2) ->add(6);
复杂度
LinkedSearchThree
可用方法
public static function make(): ThreeContract; public function root(): Leaf; public function min(): Leaf; public function max(): Leaf; public function search($key): Leaf; public function insert($index, $item): ThreeContract; public function toArray(): array; public function keysArray(): array;
用法
$three = Construct::arrayHeap() ->insert(4, 'world') ->insert(2, 'hello'); $three->min(); $three->max();
算法复杂度
空间复杂度
辅助工具
toArray()
您可以使用toArray()
方法获取当前结构的数组表示。
$array = Construct::linkedList() ->add(4) ->toArray();
dump() 🚽 & dumpAndDie() ☠
Constructs使用了Symfony组件的var_dumper。您可以在您的结构上使用dump()
方法。
$list = Construct::linkedList() ->add(4) ->dump() ->remove(4) ->dump();
如果您更喜欢“导出并终止”的方法,dumpAndDie()
方法也是可用的。
$list = Construct::linkedList() ->add(4) ->add(2) ->remove(4) ->add(6) ->dumpAndDie();