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-structure
use KaririCode\DataStructure\Collection\ArrayList; $list = new ArrayList(); $list->add("Item 1"); $list->add("Item 2"); echo $list->get(0); // Outputs: Item 1
use 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: value1
use KaririCode\DataStructure\Set\TreeSet; $set = new TreeSet(); $set->add("value1"); $set->add("value2"); echo $set->contains("value1"); // Outputs: true
use 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"
To run tests for the KaririCode DataStructure component, execute the following command:
make test
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