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.
- 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.
To install the KaririCode DataStructure component, use the following command:
composer require kariricode/data-structureuse KaririCode\DataStructure\Collection\ArrayList;
$list = new ArrayList();
$list->add("Item 1");
$list->add("Item 2");
echo $list->get(0); // Outputs: Item 1use KaririCode\DataStructure\Collection\LinkedList;
$linkedList = new LinkedList();
$linkedList->add("First");
$linkedList->add("Second");
$linkedList->remove("First");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)use KaririCode\DataStructure\Map\HashMap;
$map = new HashMap();
$map->put("key1", "value1");
echo $map->get("key1"); // Outputs: value1use KaririCode\DataStructure\Set\TreeSet;
$set = new TreeSet();
$set->add("value1");
$set->add("value2");
echo $set->contains("value1"); // Outputs: trueuse KaririCode\DataStructure\Stack\ArrayStack;
$stack = new ArrayStack();
$stack->push("First");
$stack->push("Second");
echo $stack->peek(); // Outputs: Second
$stack->pop(); // Removes "Second"use KaririCode\DataStructure\Queue\ArrayDeque;
$deque = new ArrayDeque();
$deque->addFirst("First");
$deque->addLast("Last");
echo $deque->peekLast(); // Outputs: Last
$deque->removeLast(); // Removes "Last"This package keeps no QA tools in require-dev. KaririCode Devkit (kcode) installs PHPUnit, PHPStan, Psalm, PHP-CS-Fixer and Rector into .kcode/ (git-ignored) the first time a command needs them.
Install kcode once (PHP 8.4+):
wget https://github.com/KaririCode-PHP/devkit/releases/latest/download/kcode.phar
chmod +x kcode.phar
sudo mv kcode.phar /usr/local/bin/kcodeFrom the repository root:
composer install # runtime dependencies only
kcode init # generate .kcode/ and install the toolchain (first run)
kcode test # PHPUnit (--coverage, --suite=Unit, any PHPUnit option)
kcode analyse # PHPStan, then Psalm
kcode cs:fix # apply the code style (--check reports only)
kcode quality # the CI gate: cs-fixer, PHPStan, Psalm, PHPUnit
kcode quality --docker # the same gate inside the kcode PHP containerProject overrides go in devkit.php (kcode init --config writes a template); run kcode init after editing it. kcode clean --all removes .kcode/.
This project is licensed under the MIT License. See the LICENSE file for details.
- Documentation: https://kariricode.org
- Issue Tracker: GitHub Issues
- Community: KaririCode Club Community
- Professional Support: For enterprise-level support, contact us at support@kariricode.org
Built with ❤️ by the KaririCode team. Maintained by Walmir Silva - walmir.silva@kariricode.org