{"id":19356880,"url":"https://github.com/alexfigliolia/data-structures","last_synced_at":"2025-04-23T10:33:03.728Z","repository":{"id":249862673,"uuid":"832772759","full_name":"alexfigliolia/data-structures","owner":"alexfigliolia","description":"Efficient data structures for every day programming","archived":false,"fork":false,"pushed_at":"2025-01-13T19:07:42.000Z","size":113,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-29T02:18:23.432Z","etag":null,"topics":["algorithms","data-structures","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexfigliolia.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-23T17:38:21.000Z","updated_at":"2025-01-13T19:07:46.000Z","dependencies_parsed_at":"2024-09-15T22:15:12.548Z","dependency_job_id":null,"html_url":"https://github.com/alexfigliolia/data-structures","commit_stats":null,"previous_names":["alexfigliolia/data-structures"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexfigliolia%2Fdata-structures","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexfigliolia%2Fdata-structures/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexfigliolia%2Fdata-structures/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexfigliolia%2Fdata-structures/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexfigliolia","download_url":"https://codeload.github.com/alexfigliolia/data-structures/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250416900,"owners_count":21427085,"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":["algorithms","data-structures","typescript"],"created_at":"2024-11-10T07:05:44.883Z","updated_at":"2025-04-23T10:32:58.721Z","avatar_url":"https://github.com/alexfigliolia.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Data Structures\nType-safe and efficient data-structures for everyday programming. \n\nIn this library you'll find a few of the common data-structures I find myself creating over and over again across my projects. When using this library you'll have access to:\n\n1. [Stacks](#stack)\n2. [Queues](#queue)\n3. [Min Stacks](#min-stack)\n4. [Max Stacks](#max-stack)\n5. [Min Heaps](#min-heap)\n6. [Max Heaps](#max-heap)\n7. [Graphs](#graph)\n8. [Doubly Linked Lists](#linked-list)\n9. [Priority Queues](#priority-queue)\n10. [Tries](#trie)\n11. [Quick Stack](#quick-stack)\n11. [Quick Queue](#quick-queue)\n12. [Binary Search](#binary-search)\n\nAll of which are documented and type-safe.\n\n\n## Installation\n```bash\nnpm i @figliolia/data-structures\n# or \nyarn add @figliolia/data-structures\n```\n\n## Utilities\n\n### Graph\n A generic graph construct for string and number values\n\n ```typescript\nimport { Graph, NodeCache } from \"@figliolia/data-structures\";\n\nconst cache = new NodeCache();\n\nconst root = cache.create(1);\nconst node2 = cache.create(2);\n\nroot.addEdge(node2);\nroot.addEdge(cache.create(4));\nnode2.addEdge(cache.create(3));\n\nroot.DFS(node =\u003e console.log(node.value)); // 1, 2, 3, 4\nroot.BFS(node =\u003e console.log(node.value)); // 1, 2, 4, 3\n```\n\n### Linked List\n\nA doubly linked list mimicking the interface of JavaScript arrays\n\n```typescript\nimport { LinkedList } from \"@figliolia/data-structures\";\n\nconst list = new LinkedList\u003cnumber\u003e();\nlist.push(1);\nlist.push(2);\nlist.push(3);\nfor(const item of list) {\n  console.log(item); // 1, 2, 3\n}\nlist.pop(); // 3 -\u003e O(1)\nlist.shift() // 1 -\u003e O(1)\nlist.push(3) // O(1)\nlist.unshift(1) // O(1)\n```\n\n### Max Heap\nA heap that remains sorted descendingly\n\n```typescript\nimport { MaxHeap } from \"@figliolia/data-structures\";\n \nconst heap = new MaxHeap\u003cnumber\u003e(value =\u003e value);\nheap.push(3);\nheap.push(2);\nheap.push(1);\nheap.pop() // 3\n \nconst complexDataHeap = new MaxHeap\u003c{ id: number, name: string }\u003e(value =\u003e value.id);\ncomplexDataHeap.push({ id: 3, name: \"Jeff\" });\ncomplexDataHeap.push({ id: 2, name: \"Steve\" });\ncomplexDataHeap.push({ id: 1, name: \"Dave\" });\ncomplexDataHeap.pop() // { id: 3, name: \"Jeff\" }\n```\n\n### Min Heap\nA heap that remains sorted ascendingly\n \n```typescript\nimport { MinHeap } from \"@figliolia/data-structures\";\n \nconst heap = new MinHeap\u003cnumber\u003e(value =\u003e value);\nheap.push(1);\nheap.push(2);\nheap.push(3);\nheap.pop() // 1\n \nconst complexHeap = new MinHeap\u003c{ id: number, name: string }\u003e(\n  value =\u003e value.id // numeric value extractor\n);\ncomplexHeap.push({ id: 1, name: \"Jeff\" });\ncomplexHeap.push({ id: 2, name: \"Steve\" });\ncomplexHeap.push({ id: 3, name: \"Dave\" });\ncomplexHeap.pop() // { id: 1, name: \"Jeff\" }\n```\n\n### Max Stack\nA stack maintaining a reference to it's highest weighted item\n \n```typescript\nimport { MaxStack } from \"@figliolia/data-structures\";\n \nconst stack = new MaxStack\u003cnumber\u003e(value =\u003e value);\nstack.push(1); // max = 1\nstack.push(2); // max = 2\nstack.push(3); // max = 3\nstack.max // 3\nstack.pop() // max = 2\n```\n\n### Min Stack\nA stack maintaining a reference to it's lowest weighted item\n \n```typescript\nimport { MinStack } from \"@figliolia/data-structures\";\n \nconst stack = new MinStack\u003cnumber\u003e(value =\u003e value);\nstack.push(3); // min = 3\nstack.push(2); // min = 2\nstack.push(1); // min = 1\nstack.min // 1\nstack.pop() // min = 2\n```\n\n### Priority Queue\n\nA bucket queue that sorts elements based on the priority level specified\n \n```typescript\nimport { PriorityQueue } from \"@figliolia/data-structures\";\n \nconst queue = new PriorityQueue\u003cnumber\u003e();\nqueue.push(1 /* priority */, 3 /* value */);\nqueue.push(2, 2);\nqueue.push(3, 1);\nqueue.length // 3\n// queue = [[3], [2], [1]]\nwhile(!queue.isEmpty) {\n  queue.pop() // 1, 2, 3\n}\n```\n\n### Queue\nA basic queue with enqueue, dequeue and peek methods\n\n```typescript\nimport { Queue } from \"@figliolia/data-structures\";\n \nconst queue = new Queue\u003cnumber\u003e();\nqueue.enqueue(1);\nqueue.enqueue(2);\nqueue.enqueue(3);\nqueue.peek(); // 1\nqueue.dequeue(); // 1\n```\n\n### Stack\nA basic stack with push, pop and peek methods\n \n```typescript\nimport { Stack } from \"@figliolia/data-structures\";\n \nconst stack = new Stack\u003cnumber\u003e();\nstack.push(1);\nstack.push(2);\nstack.push(3);\nstack.peek(); // 3\nstack.pop(); // 3\n```\n\n### Trie\nA graph-like data structure for optimized search over multiple\nstrings\n \n```typescript\nimport { Trie } from \"@figliolia/data-structures\";\n \nconst dictionary = new Trie();\ndictionary.add(\"hello\");\ndictionary.add(\"goodbye\");\ndictionary.add(\"helpful\");\ndictionary.search(\"hello\"); // true\ndictionary.search(\"help\", false); // true\n```\n\n### Quick Stack\nA wrapper around the native JavaScript Map that assigns an auto-incrementing ID to each value added. It provides a stack-like interface with the ability to access and remove items in 0(1) time\n\n```typescript\nimport { QuickStack } from \"@figliolia/data-structures\";\n\nconst stack = new QuickStack\u003c() =\u003e void\u003e();\nconst ID1 = stack.push(function one() {});\nconst ID2 = stack.push(function two() {});\nstack.pop() // function two() {}\nstack.pop() // function one() {}\nstack.get(/* ID */) // retrieves an item by ID 0(1)\nstack.delete(/* ID */) // deletes an item by ID 0(1)\n```\n\n### Quick Queue\nA wrapper around the native JavaScript Map that assigns an auto-incrementing ID to each value added. It provides a queue-like interface with the ability to access and remove items in 0(1) time\n\n```typescript\nimport { QuickQueue } from \"@figliolia/data-structures\";\n\nconst queue = new QuickQueue\u003c() =\u003e void\u003e();\nconst ID1 = queue.enqueue(function one() {});\nconst ID2 = queue.enqueue(function two() {});\nqueue.dequeue() // function one() {}\nqueue.dequeue() // function two() {}\nqueue.get(/* ID */) // retrieves an item by ID 0(1)\nqueue.delete(/* ID */) // deletes an item by ID 0(1)\n```\n\n### Binary Search\nLogarithmic searching for sorted lists\n\n```typescript\nimport { binarySearch } from \"@figliolia/data-structures\";\n\nbinarySearch([1, 2, 3, 4], 3) // true\nbinarySearch([1, 2, 3, 4], 5) // false\n\nbinarySearch(\n   [\n     { id: 1, name: \"Jeff\" },\n     { id: 2, name: \"Steve\" },\n     { id: 3, name: \"Dave\" },\n     { id: 4, name: \"Alex\" },\n   ],\n   { id: 3, name: \"Dave\" },\n   item =\u003e item.id\n) // true\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexfigliolia%2Fdata-structures","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexfigliolia%2Fdata-structures","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexfigliolia%2Fdata-structures/lists"}