{"id":21476146,"url":"https://github.com/amirhnajafiz/pyramid","last_synced_at":"2025-07-15T10:32:11.102Z","repository":{"id":65349731,"uuid":"552034733","full_name":"amirhnajafiz/pyramid","owner":"amirhnajafiz","description":"Fast generic Heap data structure in Golang","archived":false,"fork":false,"pushed_at":"2022-10-18T10:52:12.000Z","size":5348,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-08-10T09:38:18.373Z","etag":null,"topics":["go","golang","heap","heapsort-algorithm","max-heap","min-heap","priority-queue"],"latest_commit_sha":null,"homepage":"","language":"Go","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/amirhnajafiz.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":"2022-10-15T17:07:09.000Z","updated_at":"2023-07-28T22:38:21.000Z","dependencies_parsed_at":"2023-01-20T05:17:07.110Z","dependency_job_id":null,"html_url":"https://github.com/amirhnajafiz/pyramid","commit_stats":null,"previous_names":[],"tags_count":3,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amirhnajafiz%2Fpyramid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amirhnajafiz%2Fpyramid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amirhnajafiz%2Fpyramid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amirhnajafiz%2Fpyramid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amirhnajafiz","download_url":"https://codeload.github.com/amirhnajafiz/pyramid/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226033272,"owners_count":17563125,"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":["go","golang","heap","heapsort-algorithm","max-heap","min-heap","priority-queue"],"created_at":"2024-11-23T10:47:24.974Z","updated_at":"2024-11-23T10:47:25.635Z","avatar_url":"https://github.com/amirhnajafiz.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\u003cimg src=\"assets/logo.webp\" width=\"700\"  alt=\"logo\"/\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://img.shields.io/badge/Golang-1.19-66ADD8?style=for-the-badge\u0026logo=go\" alt=\"go version\" /\u003e\n\u003cimg src=\"https://img.shields.io/badge/Version-0.1.3-DD1199?style=for-the-badge\u0026logo=github\" alt=\"version\" /\u003e\n\u003cimg src=\"https://img.shields.io/badge/Load_Test-1M-442266?style=for-the-badge\u0026logo=k6\" alt=\"version\" /\u003e\n\u003cbr /\u003e\n\u003c/p\u003e\n\n\u003ch1 align=\"center\"\u003e\nPyramid\n\u003c/h1\u003e\n\nFast generic **Heap** in Golang. Create your Heap data structure with any data type. Set your\ncompression function to sort your data with any field that you want. Push, Pop and Update your\ndata in heap without any problems. Write your equality function to filter\nthe elements that you want to update.\n\n**Pyramid** is built with **Golang** internal libraries and does not include any external\nlibraries.\n\n## How to use?\n\nGet **pyramid** package.\n\n```shell\ngo get github.com/amirhnajafiz/pyramid\n```\n\nNow you can use pyramid to build any type of **Heap**.\n\n## Example\n\nCreating a _max-heap_ of type Integer.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/amirhnajafiz/pyramid\"\n)\n\nfunc main() {\n\t// initializing a heap with comparator function\n\th := pyramid.NewHeap[int](func(a int, b int) bool {\n\t\treturn a \u003e b\n\t})\n\n\t// Using push method\n\th.Push(2)\n\th.Push(12)\n\th.Push(4)\n\th.Push(90)\n\th.Push(20)\n\n\t// Using length method\n\tfor h.Length() \u003e 0 {\n\t\t// Using pop method\n\t\tfmt.Printf(\"%d \", h.Pop().(int))\n\t}\n}\n```\n\nCreating a _min-heap_ of type custom _Data_.\n\n```go\n// Creating a custom Data struct type.\ntype Data struct {\n\tPriority int\n\tData     string\n}\n\nfunc main() {\n\t// Creating a heap of Data type.\n\th := pyramid.NewHeap[Data](func(a Data, b Data) bool {\n\t\treturn a.Priority \u003c b.Priority\n\t})\n\n\t// Push data into heap.\n\tfor i := 0; i \u003c 10; i++ {\n\t\th.Push(Data{Priority: i, Data: fmt.Sprintf(\"data: %d\", i+1)})\n\t}\n\n\tfor h.Length() \u003e 0 {\n\t\tfmt.Printf(\"%s\\n\", h.Pop().(Data).Data)\n\t}\n}\n```\n\n### Updating a reference\n\nYou can update any item in the list, also you can define a \nequal function to check the equality of your objects.\n\n```go\nspecial := 675\n\nh.Push(special)\n\nfor i := 2; i \u003c 100; i++ {\n    h.Push(i)\n}\n\nh.Update(special, 0, func(a int, b int) bool {\n    return a == b\n})\n```\n\n## Load test\nIf we have 10000 items, and we want to update them 1 Million times, it would\nonly take 12 seconds:\n\n```shell\ngo run load-test/update/main.go -push 10000 -update 1000000\n```\n\n```shell\ntesting: 10000 numbers\nstart: Oct 16 14:42:34.752\ndone: Oct 16 14:42:52.064\nfinal size: 10000\nmin: 2\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famirhnajafiz%2Fpyramid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famirhnajafiz%2Fpyramid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famirhnajafiz%2Fpyramid/lists"}