https://github.com/gedex/container
PHP library for various data structure and its operations.
https://github.com/gedex/container
Last synced: about 1 year ago
JSON representation
PHP library for various data structure and its operations.
- Host: GitHub
- URL: https://github.com/gedex/container
- Owner: gedex
- License: other
- Created: 2015-08-03T12:17:00.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-08-03T12:53:55.000Z (almost 11 years ago)
- Last Synced: 2025-02-15T08:25:15.575Z (over 1 year ago)
- Language: PHP
- Size: 117 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Container
=========
[](https://travis-ci.org/gedex/container)
[](https://coveralls.io/github/gedex/container?branch=master)
Library for various data structure and its operations.
## Examples
### Doubly Linked List
~~~php
use Gedex\Container;
$ll = new Container\DoublyLinkedList();
$e1 = $ll->pushFront(1);
$e2 = $ll->pushFront(2);
$e3 = $ll->pushBack('e3');
$e4 = $ll->insertBefore('el before e3', $e3);
$e5 = $ll->insertAfter('el after e3', $e3);
printList($ll); // --> (2) --> (1) --> (el before e3) --> (e3) --> (el after e4)
printf("Remove element (%s)\n", $e3->getValue());
$ll->remove($e3);
printList($ll); // --> (2) --> (1) --> (el before e3) --> (el after e4)
function printList($ll) {
$el = $ll->getFront();
while (!is_null($el)) {
printf('--> (%s) ', $el->getValue());
$el = $el->getNext();
}
printf("\n");
}
~~~
### Circular List
~~~php
use Gedex\Container;
$cl = new Container\CircularList(5);
for ($i = 1; $i <= $cl->len(); $i++) {
$el = $cl->cursor()->setValue($i);
$cl->next();
}
$sum = 0;
$cl->walk(function($value) use(&$sum) {
printf('--> (%s) ', $value);
$sum += $value;
});
printf("\n");
printf("%d\n", $sum); // 15
~~~
## License
MIT License - See [LICENSE file](LICENSE).