{"id":43999175,"url":"https://github.com/sig-0/iq","last_synced_at":"2026-02-07T12:05:52.000Z","repository":{"id":154438870,"uuid":"628331103","full_name":"sig-0/iq","owner":"sig-0","description":"An indexable priority queue that utilizes insertion sort","archived":false,"fork":false,"pushed_at":"2025-11-21T11:29:49.000Z","size":48,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-14T18:28:21.944Z","etag":null,"topics":["insertion-sort","priority-queue","queue"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sig-0.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":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-04-15T16:03:00.000Z","updated_at":"2025-11-20T18:40:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"d4680c93-4835-42ab-bb77-1b80a3bb9813","html_url":"https://github.com/sig-0/iq","commit_stats":null,"previous_names":["sig-0/insertion-queue","sig-0/iq","madz-lab/insertion-queue"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/sig-0/iq","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sig-0%2Fiq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sig-0%2Fiq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sig-0%2Fiq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sig-0%2Fiq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sig-0","download_url":"https://codeload.github.com/sig-0/iq/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sig-0%2Fiq/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29194018,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-07T07:37:03.739Z","status":"ssl_error","status_checked_at":"2026-02-07T07:37:03.029Z","response_time":63,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["insertion-sort","priority-queue","queue"],"created_at":"2026-02-07T12:05:51.319Z","updated_at":"2026-02-07T12:05:51.993Z","avatar_url":"https://github.com/sig-0.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Overview\n\n[![codecov](https://codecov.io/gh/sig-0/iq/branch/main/graph/badge.svg?token=UJW1HMBFUM)](https://codecov.io/gh/sig-0/iq)\n\n`iq` is a small library that implements a priority queue in slice representation, where the order of items\nis sorted using insertion sort.\n\n## Usage\n\n### Installation\n\nTo start using it, fetch it using `go get`:\n\n```bash\ngo get github.com/sig-0/iq\n```\n\n### Basic operations\n\nIn order to use the priority queue with custom items, users need to define a special type that implements the methods in\nthe `Item` interface (`Less`):\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/sig-0/iq\"\n)\n\n// number is a wrapper for a queue number value\ntype number struct {\n\tvalue int\n}\n\n// Less is a required method implementation from iq.Item\nfunc (i number) Less(other iq.Item) bool {\n\treturn i.value \u003c other.(number).value\n}\n\nfunc main() {\n\t// Creating the queue\n\tq := iq.NewQueue[number]()\n\n\t// Adding an item to the queue\n\tq.Push(number{1}) // [1]\n\tq.Push(number{2}) // [1, 2]\n\n\t// Indexing an element\n\tfmt.Println(q[0])\n\n\t// Popping an item from the front\n\tfront := q.PopFront()\n\n\t// Popping an item from the back\n\tback := q.PopBack()\n\n\t// Fetching the size\n\tfmt.Println(len(q))\n}\n\n```\n\n## Why would anyone use this?\n\nThis is a fair question - users might be tempted to simply wrap a slice\nwithin their own structure, and define an insertion method that:\n\n- appends an item to the end of the queue\n- calls `sort.Sort` to sort the entire queue\n\nIt turns out this is not really efficient, especially if the use-case of the queue\nis that items will be added sequentially (one-by-one). Insertion sort provides the biggest performance\nbenefits in data sets that are _nearly_ sorted. Given that each element being added to the `iq` is\nautomatically sorted on insertion, the benefit is obvious - the overhead for placing the new element is minimal.\n\nAdditionally, this package is for users who want to have control over their input set (slice), by being able to directly\ninteract with it (index it and change values directly). When using a structure like `container/heap`, the order of items\nwithin the slice cannot be guaranteed after pushes and pops, and this can pose a problem if users plan to index the\nslice\nright away after modifying its internal data set.\n\nThis package outperforms the standard library implementation mentioned in the bullet points:\n\n```bash\n==================\n\nItems: 100\nIterations: 100\nName             Time [s]\niq  0.00052\nstdlib           0.00189\n\niq is faster by 0.00137s\n\n==================\n\nItems: 1000\nIterations: 100\nName             Time [s]\niq  0.03490\nstdlib           0.17314\n\niq is faster by 0.13824s\n```\n\nThe snippet for this performance test can be\nfound [here](https://gist.github.com/zivkovicmilos/ce12d68304e0aa7502f8f7173341821b).\n\n## Benchmarks\n\n```bash\ngoos: darwin\ngoarch: arm64\npkg: github.com/sig-0/iq\ncpu: Apple M3 Max\nBenchmarkHeap_Push10-14                  7005292               168.4 ns/op           248 B/op          5 allocs/op\nBenchmarkHeap_Push100-14                  201814              5934 ns/op            2168 B/op          8 allocs/op\nBenchmarkHeap_PopFront10-14              6614826               194.4 ns/op            24 B/op          1 allocs/op\nBenchmarkHeap_PopFront100-14             3770515               310.1 ns/op            24 B/op          1 allocs/op\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsig-0%2Fiq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsig-0%2Fiq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsig-0%2Fiq/lists"}