blister / php-linkedlist
一个快速的 DoubleLinkedList 数据结构实现。
0.1.0
2023-08-14 15:16 UTC
Requires
- php: >=7.0
Requires (Dev)
- phpunit/phpunit: ^9
README
PHP 中快速 LinkedList 和 DoubleLinkedList 数据结构的实现。
安装
composer require blister/linkedlist
使用
$list = new Blister\LinkedList(); // Add to the end of the LinkedList $list->push('Hello!'); $list->push('World!'); $list->push(array('key' => 'val')); $list->push(true); $list->push('Last!'); // Add to the front of the LinkedList $list->unshift('New First!'); // Get the length of the LinkedList $len = $list->length; // 6 // Searching inside the list $found_index = $list->index('World!'); // 2 $found = $list->find('World'); // true $found = $list->find('Missing'); // false // removing elements $last = $list->pop(); // 'Last!' $first = $list->shift(); // 'First!' $middle = $list->remove('World!'); // 'World!' $third = $list->removeAt(1); // array('key' => 'val')
测试
这个 LinkedList 实现附带了一套完整的 PHPUnit 测试。
composer run-script test
未来
-
toArray():array
-
findAll(mixed $needle):array
-
fill(int $count, mixed $value):bool
-
findFromTail(mixed $needle):mixed
-
indexFromTail(mixed $needle):int
-
print():void
作者
Eric Ryan Harrison, @blister