{"id":26288909,"url":"https://github.com/clojure-finance/clojure-heap","last_synced_at":"2025-07-22T20:32:55.643Z","repository":{"id":41394919,"uuid":"448915991","full_name":"clojure-finance/clojure-heap","owner":"clojure-finance","description":"Pure Clojure implementation of a heap, i.e. priority queue","archived":false,"fork":false,"pushed_at":"2022-12-17T13:36:40.000Z","size":51,"stargazers_count":18,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-07T20:37:16.068Z","etag":null,"topics":["clojure","heap","priority-queue"],"latest_commit_sha":null,"homepage":"","language":"Clojure","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/clojure-finance.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-01-17T13:59:49.000Z","updated_at":"2024-05-07T21:53:50.000Z","dependencies_parsed_at":"2023-01-29T17:15:53.112Z","dependency_job_id":null,"html_url":"https://github.com/clojure-finance/clojure-heap","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/clojure-finance/clojure-heap","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clojure-finance%2Fclojure-heap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clojure-finance%2Fclojure-heap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clojure-finance%2Fclojure-heap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clojure-finance%2Fclojure-heap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clojure-finance","download_url":"https://codeload.github.com/clojure-finance/clojure-heap/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clojure-finance%2Fclojure-heap/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266567377,"owners_count":23949342,"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","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"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":["clojure","heap","priority-queue"],"created_at":"2025-03-14T22:15:33.033Z","updated_at":"2025-07-22T20:32:55.608Z","avatar_url":"https://github.com/clojure-finance.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Clojure Heap\n\nA pure Clojure implementation of mutable binary **heap** / **priority queue**. \n\n### Installation\nAvailable on [![Clojars Project](https://img.shields.io/clojars/v/com.github.clojure-finance/clojure-heap.svg)](https://clojars.org/com.github.clojure-finance/clojure-heap)\n\nImport it using\n```clojure\n(require '[clojure-heap.core :as heap])\n```\n\n***Or***\n\nCopy the source code in [`src/clojure/clojure_heap/core.clj`](src/clojure/heap/core.clj) to your project.\n\n### Speed\n\nEqual to the theoretical limit.\n\n**Single** **`add`**: O(logn)\n\n**Single** **`poll`**: O(logn)\n\n**Space**: n\n\n### APIs\n\n#### `heap`\n\nCreate a heap with a comparator[ and an entry]. O(1)\n\n| Argument     | Type     | Function                                         | Remarks                                                      |\n| ------------ | -------- | ------------------------------------------------ | ------------------------------------------------------------ |\n| `comparator` | Function | A comparator function, deciding a max / min heap | Two arguments. Return `true` on matching the condition, `false` otherwise |\n| [`value`]    | Any      | The first entry of the heap                      |                                                              |\n\n**Example**\n\n```clojure\n;; define a max heap containing maps\n(def x (heap (fn [a b] (\u003e (:id a) (:id b))) {:id 3}))\n;; without initial value\n(def x (heap (fn [a b] (\u003e (:id a) (:id b)))))\n```\n\n\n\n#### `get-size`\n\nGet the size (length) of heap. O(1)\n\n| Argument | Type           | Function      | Remarks |\n| -------- | -------------- | ------------- | ------- |\n| `heap`   | heap.core.Heap | A heap object |         |\n\n**Example**\n\n```clojure\n(def x (heap (fn [a b] (\u003e (:id a) (:id b))) {:id 3}))\n(get-size x)\n;; return 1\n```\n\n\n\n#### `peek`\n\nGet the top value of the heap. If it is a min heap, return the smallest value; otherwise return the largest value. Return nil if the heap is empty. O(1)\n\n| Argument | Type           | Function      | Remarks |\n| -------- | -------------- | ------------- | ------- |\n| `heap`   | heap.core.Heap | A heap object |         |\n\n**Example**\n\n```clojure\n(def x (heap (fn [a b] (\u003e (:id a) (:id b))) {:id 3}))\n(peek x)\n;; return {:id 3}\n```\n\n\n\n#### `add`\n\nInsert an entry to the heap. The heap will be reorganized to fit the new value. O(logn), n = size of the heap\n\n| Argument | Type           | Function                             | Remarks                                                |\n| -------- | -------------- | ------------------------------------ | ------------------------------------------------------ |\n| `heap`   | heap.core.Heap | A heap object                        |                                                        |\n| `value`  | Any            | The value to be inserted to the heap | Should be applicable as one argument of the comparator |\n\n**Example**\n\n```clojure\n(def x (heap (fn [a b] (\u003e (:id a) (:id b))) {:id 3}))\n(add x {:id 4})\n(get-size x)\n;; return 2\n```\n\n\n\n#### `poll`\n\nDelete and return the top value of the heap. If it is a min heap, return the smallest value; otherwise return the largest value. O(logn), n = size of the heap\n\n| Argument | Type           | Function      | Remarks |\n| -------- | -------------- | ------------- | ------- |\n| `heap`   | heap.core.Heap | A heap object |         |\n\n**Example**\n\n```clojure\n(def x (heap (fn [a b] (\u003e (:id a) (:id b))) {:id 3}))\n(poll x)\n;; return {:id 3}\n(poll x)\n;; return nil\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclojure-finance%2Fclojure-heap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclojure-finance%2Fclojure-heap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclojure-finance%2Fclojure-heap/lists"}