{"id":14966186,"url":"https://github.com/titsuki/raku-algorithm-minmaxheap","last_synced_at":"2025-10-25T16:30:40.139Z","repository":{"id":80481489,"uuid":"53797307","full_name":"titsuki/raku-Algorithm-MinMaxHeap","owner":"titsuki","description":"A Raku implementation of double ended priority queue","archived":false,"fork":false,"pushed_at":"2020-06-20T04:20:51.000Z","size":50,"stargazers_count":4,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-31T07:51:27.672Z","etag":null,"topics":["double-ended","minmaxheap","perl6","priority-queue","raku"],"latest_commit_sha":null,"homepage":"","language":"Raku","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"artistic-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/titsuki.png","metadata":{"files":{"readme":"README.md","changelog":"Changes","contributing":null,"funding":null,"license":"LICENSE","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":"2016-03-13T17:14:57.000Z","updated_at":"2022-07-28T16:30:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"d281bcbe-61f6-4bb0-83a8-8a0201bebf98","html_url":"https://github.com/titsuki/raku-Algorithm-MinMaxHeap","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/titsuki%2Fraku-Algorithm-MinMaxHeap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/titsuki%2Fraku-Algorithm-MinMaxHeap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/titsuki%2Fraku-Algorithm-MinMaxHeap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/titsuki%2Fraku-Algorithm-MinMaxHeap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/titsuki","download_url":"https://codeload.github.com/titsuki/raku-Algorithm-MinMaxHeap/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238174095,"owners_count":19428624,"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":["double-ended","minmaxheap","perl6","priority-queue","raku"],"created_at":"2024-09-24T13:35:58.561Z","updated_at":"2025-10-25T16:30:34.850Z","avatar_url":"https://github.com/titsuki.png","language":"Raku","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/titsuki/raku-Algorithm-MinMaxHeap.svg?branch=master)](https://travis-ci.org/titsuki/raku-Algorithm-MinMaxHeap)\n\nNAME\n====\n\nAlgorithm::MinMaxHeap - A Raku implementation of double ended priority queue\n\nSYNOPSIS\n========\n\nEXAMPLE1\n--------\n\n    use Algorithm::MinMaxHeap;\n\n    my $heap = Algorithm::MinMaxHeap[Int].new;\n    $heap.insert(0);\n    $heap.insert(1);\n    $heap.insert(2);\n    $heap.insert(3);\n    $heap.insert(4);\n    $heap.insert(5);\n    $heap.insert(6);\n    $heap.insert(7);\n    $heap.insert(8);\n\n    $heap.find-max.say # 8;\n    $heap.find-min.say # 0;\n\n    my @array;\n    @array.push($heap.pop-max) until $heap.is-empty;\n    @array.say # [8, 7, 6, 5, 4, 3, 2, 1, 0]\n\nEXAMPLE2\n--------\n\n    use Algorithm::MinMaxHeap;\n    use Algorithm::MinMaxHeap::Comparable;\n\n    # sets compare-to method using Algorithm::MinMaxHeap::Comparable role\n    my class State {\n       also does Algorithm::MinMaxHeap::Comparable[State];\n       has Int $.value;\n       has $.payload;\n       submethod BUILD(:$!value) { }\n       method compare-to(State $s) {\n              if $!value == $s.value {\n                 return Order::Same;\n              }\n              if $!value \u003e $s.value {\n                 return Order::More;\n              }\n              if $!value \u003c $s.value {\n                 return Order::Less;\n              }\n       }\n    }\n\n    # specify Algorithm::MinMaxHeap::Comparable role as an item type\n    my $class-heap = Algorithm::MinMaxHeap[Algorithm::MinMaxHeap::Comparable].new;\n    $class-heap.insert(State.new(value =\u003e 0));\n    $class-heap.insert(State.new(value =\u003e 1));\n    $class-heap.insert(State.new(value =\u003e 2));\n    $class-heap.insert(State.new(value =\u003e 3));\n    $class-heap.insert(State.new(value =\u003e 4));\n    $class-heap.insert(State.new(value =\u003e 5));\n    $class-heap.insert(State.new(value =\u003e 6));\n    $class-heap.insert(State.new(value =\u003e 7));\n    $class-heap.insert(State.new(value =\u003e 8));\n\n    $class-heap.find-max.value.say # 8;\n    $class-heap.find-min.value.say # 0;\n\n    my @array;\n    until $class-heap.is-empty {\n\t    my $state = $class-heap.pop-max;\n\t    @array.push($state.value);\n    }\n    @array.say # [8, 7, 6, 5, 4, 3, 2, 1, 0]\n\nDESCRIPTION\n===========\n\nAlgorithm::MinMaxHeap is a simple implementation of double ended priority queue.\n\nCONSTRUCTOR\n-----------\n\nDefined as:\n\n    role Algorithm::MinMaxHeap[::Type] {}\n\nUsage:\n\n    my $heap = Algorithm::MinMaxHeap[Int].new;\n    my $heap = Algorithm::MinMaxHeap[Rat].new;\n    my $heap = Algorithm::MinMaxHeap[Algorithm::MinMaxHeap::Comparable].new;\n\nSets `::Type` parameter, where `::Type` is a type of nodes in the queue.\n\nUse `subset` for creating complex type constraints:\n\n    my subset MyCool of Cool where Int|Num|Rat;\n    my $heap = Algorithm::MinMaxHeap[MyCool].new;\n\nMETHODS\n-------\n\n### insert($item)\n\n    $heap.insert($item);\n\nInserts an item to the queue.\n\n### pop-max()\n\n    my $max-value-item = $heap.pop-max();\n\nReturns a maximum value item in the queue and deletes this item in the queue.\n\n### pop-min()\n\n    my $min-value-item = $heap.pop-min();\n\nReturns a minimum value item in the queue and deletes this item in the queue.\n\n### find-max()\n\n    my $max-value-item = $heap.find-max();\n\nReturns a maximum value item in the queue.\n\n### find-min()\n\n    my $min-value-item = $heap.find-min();\n\nReturns a minimum value item in the queue.\n\n### is-empty() returns Bool:D\n\n    while (not $heap.is-empty()) {\n\t         // YOUR CODE\n    }\n\nReturns whether the queue is empty or not.\n\n### clear()\n\n    $heap.clear();\n\nDeletes all items in the queue.\n\nCAUTION\n=======\n\nDon't insert both numerical items and stringified items into the same queue.\n\nIt will cause mixing of lexicographical order and numerical order.\n\nAUTHOR\n======\n\ntitsuki \u003ctitsuki@cpan.org\u003e\n\nCOPYRIGHT AND LICENSE\n=====================\n\nCopyright 2016 titsuki\n\nThis library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.\n\nThis algorithm is from Atkinson, Michael D., et al. \"Min-max heaps and generalized priority queues.\" Communications of the ACM 29.10 (1986): 996-1000.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftitsuki%2Fraku-algorithm-minmaxheap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftitsuki%2Fraku-algorithm-minmaxheap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftitsuki%2Fraku-algorithm-minmaxheap/lists"}