{"id":18411438,"url":"https://github.com/sirodiaz/datastructures","last_synced_at":"2025-04-07T11:31:42.879Z","repository":{"id":57051939,"uuid":"92519709","full_name":"SiroDiaz/DataStructures","owner":"SiroDiaz","description":"Collection of lot high performance data structures for PHP","archived":false,"fork":false,"pushed_at":"2017-09-30T18:45:06.000Z","size":234,"stargazers_count":8,"open_issues_count":3,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-06T04:32:42.076Z","etag":null,"topics":["algorithm","algorithms","avl-tree","bst","data-structures","datastructures","disjoint-sets","hashmap","hashset","list","oop","php","php7","radix-tree","stack","tree","trie"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SiroDiaz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-26T14:39:25.000Z","updated_at":"2022-02-12T08:06:05.000Z","dependencies_parsed_at":"2022-08-24T05:10:14.545Z","dependency_job_id":null,"html_url":"https://github.com/SiroDiaz/DataStructures","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SiroDiaz%2FDataStructures","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SiroDiaz%2FDataStructures/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SiroDiaz%2FDataStructures/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SiroDiaz%2FDataStructures/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SiroDiaz","download_url":"https://codeload.github.com/SiroDiaz/DataStructures/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247644155,"owners_count":20972229,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithm","algorithms","avl-tree","bst","data-structures","datastructures","disjoint-sets","hashmap","hashset","list","oop","php","php7","radix-tree","stack","tree","trie"],"created_at":"2024-11-06T03:37:02.263Z","updated_at":"2025-04-07T11:31:42.527Z","avatar_url":"https://github.com/SiroDiaz.png","language":"PHP","readme":"# DataStructures [![Build Status](https://travis-ci.org/SiroDiaz/DataStructures.svg?branch=master)](https://travis-ci.org/SiroDiaz/DataStructures) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/SiroDiaz/DataStructures/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/SiroDiaz/DataStructures/?branch=master) \nData structures for PHP \u003e= 7.0. Use data structures in your project using this library.\n\n## Index\n\n[Install](https://github.com/SiroDiaz/DataStructures#install)\u003cbr\u003e\n**[API](https://github.com/SiroDiaz/DataStructures#api)**\u003cbr\u003e\n\n*[List implementations](https://github.com/SiroDiaz/DataStructures#lists)*\u003cbr\u003e\n - [Singly linked list](https://github.com/SiroDiaz/DataStructures#singly-linked-list)\u003cbr\u003e\n - [Singly circular linked list](https://github.com/SiroDiaz/DataStructures#circular-linked-list)\u003cbr\u003e\n - [Doubly circular linked list](https://github.com/SiroDiaz/DataStructures#doubly-circular-linked-list)\u003cbr\u003e\n - [Array list](https://github.com/SiroDiaz/DataStructures#array-list)\u003cbr\u003e\n - [Stack](https://github.com/SiroDiaz/DataStructures#stack)\u003cbr\u003e\n - [Queue](https://github.com/SiroDiaz/DataStructures#queue)\u003cbr\u003e\n*[Tree implementations](https://github.com/SiroDiaz/DataStructures#trees)*\u003cbr\u003e\n - [Trie tree](https://github.com/SiroDiaz/DataStructures#trie-tree)\u003cbr\u003e\n - [Binary search tree](https://github.com/SiroDiaz/DataStructures#binary-search-tree)\u003cbr\u003e\n - [AVL Tree](https://github.com/SiroDiaz/DataStructures#avl-tree)\u003cbr\u003e\n## Install\n\nVia Composer just copy and paste:\n```sh\ncomposer require siro-diaz/data-structures:\"dev-master\"\n```\n## API\n### Lists\n\nThe list data structures supported are the following:\n\n*list type*: **class**\n\n - *Singly linked list*: **SinglyLinkedList**\n - *Circular singly linked list*: **CircularLinkedList**\n - *Circular doubly linked list*: **DoublyLinkedList**\n - *Array list*: **ArrayList**\n - *Stack*: **Stack**\n - *Queue*: **Queue**\n\n\n#### Singly linked list\n##### Introduction\nSingly linked list is the simplest linked list that can be created. It has a pointer\nto the next node in the list and the last node points to null.\nAll lists except stacks and queues have the same methods because they implements the same\ninterface.\n##### Methods\n - size()\n - empty()\n - get($index)\n - getAll()\n - getLast()\n - delete($index)\n - clear()\n - pop()\n - insert($index, $data)\n - push($data)\n - unshift($data)\n - shift()\n - toArray()\n##### Example\n```php\nuse DataStructures\\Lists\\SinglyLinkedList;\n\n$myList = new SinglyLinkedList();\n$myList-\u003epush(20);\necho \"Size of : \". $myList-\u003esize();\n$myList-\u003eunshift(100);\necho \"Item at the beginnig: \". $myList-\u003eget(0);\n```\n\n\n#### Circular linked list\n\n##### Introduction\nCircular linked list is a singly linked list that has a pointer to the last and first node. \nAll lists except stacks and queues have the same methods because they implements the same\ninterface.\n\n##### Methods\n - size()\n - empty()\n - get($index)\n - getAll()\n - getLast()\n - delete($index)\n - clear()\n - pop()\n - insert($index, $data)\n - push($data)\n - unshift($data)\n - shift()\n - toArray()\n##### Example\n```php\nuse DataStructures\\Lists\\CircularLinkedList;\n\n$myList = new CircularLinkedList();\n$myList-\u003epush(20);\n$myList-\u003epush(10);\necho \"Size of : \". $myList-\u003esize();\n$myList-\u003eunshift(100);\necho \"Item at the beginnig: \". $myList-\u003eget(0);\necho \"Last item: \". $myList-\u003egetLast();\n```\n\n\n#### Doubly circular linked list\n\n##### Introduction\nDoubly circular linked list is a doubly linked list that each node contained in the list\ncontains a pointer to the next and previous node. In the of the first node it is going to point \nto the last node. It uses some performance tricks for insert, get, and delete operations.\n\n##### Methods\n - size()\n - empty()\n - get($index)\n - getAll()\n - getLast()\n - delete($index)\n - clear()\n - pop()\n - insert($index, $data)\n - push($data)\n - unshift($data)\n - shift()\n - toArray()\n\n##### Example\n```php\nuse DataStructures\\Lists\\DoublyLinkedList;\n\n$myList = new DoublyLinkedList();\n$myList-\u003epush(20);\n$myList-\u003epush(10);\necho \"Size of : \". $myList-\u003esize();\n$myList-\u003eunshift(100);\necho \"Item at position 1: \". $myList-\u003eget(1);\necho \"Last item: \". $myList-\u003egetLast();\n```\n\n#### Array list\n\n##### Introduction\nArray list uses the built in arrays as lists. In PHP all uses hash tables and it give\narray lists some performance advantages in operations like get that will be O(1). \nArray list auto increments their size internally, without the necessity of increment it\nmanually. It is translates in a very easy way to implement this type of list.\n\n##### Methods\n - size()\n - empty()\n - get($index)\n - getAll()\n - getLast()\n - delete($index)\n - clear()\n - pop()\n - insert($index, $data)\n - push($data)\n - unshift($data)\n - shift()\n - toArray()\n\n##### Example\n```php\nuse DataStructures\\Lists\\ArrayList;\n\n$myList = new ArrayList();\n$myList-\u003epush(20);\n$myList-\u003epush(10);\necho \"Size of : \". $myList-\u003esize();\n$myList-\u003eunshift(100);\necho \"Item at position 1: \". $myList-\u003eget(1);\necho \"Last item: \". $myList-\u003egetLast();\n```\n\n\n#### Stack\n\n##### Introduction\nStack is a LIFO (Last In First Out) data structure that works like a stack (as its name\nsaid). Last element that is inserted will be the first in going out. \nThe implementation used in this library allow to especify a maximum size, in other words,\nit can be a limited stack. When limited stack is been used is important check if it is full\nbefore insert a new element.\n\n##### Methods\n - size()\n - empty()\n - isFull()\n - peek()\n - pop()\n - push($data)\n\n##### Example\n```php\nuse DataStructures\\Lists\\Stack;\n\n$myStack = new Stack(); // unlimited stack.\n// new Stack(5) will contain a maximum of 5 elements.\n$myStack-\u003epush(20);\n$myStack-\u003epush(10);\necho \"Size of : \". $myStack-\u003esize();\necho \"Front element: \". $myStack-\u003epeek(1);\necho \"Last element inserted and being removed: \". $myStack-\u003epop();\n```\n\n### Trees\n\nThe tree data structures supported are the following:\n\n*tree type*: **class**\n\n - *Trie tree*: **TrieTree**\n - *Binary search tree*: **BinarySearchTree**\n - *AVL tree*: **AVLTree**\n\n#### Trie tree\n##### Introduction\nSingly linked list is the simplest linked list that can be created. It has a pointer\nto the next node in the list and the last node points to null.\nAll lists except stacks and queues have the same methods because they implements the same\ninterface.\n##### Methods\n - size()\n - empty()\n - wordCount()\n - withPrefix($prefix)\n - startsWith($prefix)\n - getWords()\n - clear()\n - delete($word)\n - contains($word)\n - add($word)\n##### Example\n```php\nuse DataStructures\\Trees\\TrieTree;\n\n$trie = new TrieTree();\n$trie-\u003eadd('hello');\n$trie-\u003eadd('hell');\n$trie-\u003eadd('world');\necho \"Size of : \". $trie-\u003ewordCount();  // 3\n$trie-\u003econtains('hell');    // true\n\necho \"There are words that start with 'he': \". $trie-\u003estartsWith('he');   // true\n```\n\n#### Binary Search Tree\n##### Introduction\nBinary search tree (BST) is a data structure which has a root node that may have up to 2 siblings.\nEach sibling also can have a maximum of 2 siblings. If the node have not siblings it is called leaf node.\nThe left sibling is lower than the parent node and right sibling is grater than it parent.\n##### Methods\n - size()\n - empty()\n - delete($key)\n - put($key, $data, $update = false)\n - putOrUpdate($key, $data)\n - get($key)\n - getRoot()\n - exists($key)\n - min()\n - max()\n - deleteMin(BinaryNodeInterface $node = null)\n - deleteMax(BinaryNodeInterface $node = null)\n - search($key)\n - isLeaf($node)\n - isRoot($node)\n - preorder(Callable $callback = null)\n - inorder(Callable $callback = null)\n - postorder(Callable $callback = null)\n##### Example\n```php\nuse DataStructures\\Trees\\BinarySearchTree;\n\n$bst = new BinarySearchTree();\n$bst-\u003eput(4, 10);\n$bst-\u003eput(2, 100);\n$bst-\u003eput(10, 1000);\necho \"Size of : \". $bst-\u003esize();\n$bst-\u003eexists(100);  // false\necho \"Is leaf?: \". $bst-\u003eisLeaf($bst-\u003emin());   // true\n```\n\n#### AVL Tree\n##### Introduction\nAVL Tree is a binary search tree that has a balance condition. The condition consists in each\nsubnode can have a maximum height of one respect the oposite side subtree (it means that right subtree of a node can't be higher than one, compared with the left subtree). If it has a height of two or more then is rebalanced the tree using a single left rotation, single right rotation, double left rotation or a double right rotation.\n##### Methods\nSame method that binary search tree.\n##### Example\n```php\nuse DataStructures\\Trees\\AVLTree;\n\n$avl = new BinarySearchTree();\n$avl-\u003eput(4, 10);\n$avl-\u003eput(2, 100);\n$avl-\u003eput(10, 1000);\necho \"Size of : \". $avl-\u003esize();\n$avl-\u003eexists(100);  // false\necho \"Is leaf?: \". $avl-\u003eisLeaf($avl-\u003emin());   // true\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsirodiaz%2Fdatastructures","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsirodiaz%2Fdatastructures","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsirodiaz%2Fdatastructures/lists"}