2017 © Pedro Peláez
 

library container

Library for various data structure and its operations

image

gedex/container

Library for various data structure and its operations

  • Monday, August 3, 2015
  • by gedex
  • Repository
  • 0 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Container

Build Status Coverage Status, (*1)

Library for various data structure and its operations., (*2)

Examples

Doubly Linked List

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

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., (*3)

The Versions

03/08 2015

dev-master

9999999-dev

Library for various data structure and its operations

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires