{
    "content": [
        {
            "type": "text",
            "text": "# Heap (perldoc)\n\n## NAME\n\nHeap - Perl extensions for keeping data partially sorted\n\n## SYNOPSIS\n\nuse Heap;\nmy $heap = Heap->new;\nmy $elem;\nuse Heap::Elem::Num(NumElem);\nforeach $i ( 1..100 ) {\n$elem = NumElem( $i );\n$heap->add( $elem );\n}\nwhile( defined( $elem = $heap->extracttop ) ) {\nprint \"Smallest is \", $elem->val, \"\\n\";\n}\n\n## DESCRIPTION\n\nThe Heap collection of modules provide routines that manage a heap of elements. A heap is a\npartially sorted structure that is always able to easily extract the smallest of the elements in\nthe structure (or the largest if a reversed compare routine is provided).\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **METHODS**\n- **AUTHOR**\n- **COPYRIGHT**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "Heap",
        "section": "",
        "mode": "perldoc",
        "summary": "Heap - Perl extensions for keeping data partially sorted",
        "synopsis": "use Heap;\nmy $heap = Heap->new;\nmy $elem;\nuse Heap::Elem::Num(NumElem);\nforeach $i ( 1..100 ) {\n$elem = NumElem( $i );\n$heap->add( $elem );\n}\nwhile( defined( $elem = $heap->extracttop ) ) {\nprint \"Smallest is \", $elem->val, \"\\n\";\n}",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [
            {
                "name": "Elem",
                "section": "3",
                "url": "https://www.chedong.com/phpMan.php/man/Elem/3/json"
            },
            {
                "name": "Binary",
                "section": "3",
                "url": "https://www.chedong.com/phpMan.php/man/Binary/3/json"
            },
            {
                "name": "Binomial",
                "section": "3",
                "url": "https://www.chedong.com/phpMan.php/man/Binomial/3/json"
            },
            {
                "name": "Fibonacci",
                "section": "3",
                "url": "https://www.chedong.com/phpMan.php/man/Fibonacci/3/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 16,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 11,
                "subsections": []
            },
            {
                "name": "METHODS",
                "lines": 44,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "COPYRIGHT",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "Heap - Perl extensions for keeping data partially sorted\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use Heap;\n\nmy $heap = Heap->new;\nmy $elem;\n\nuse Heap::Elem::Num(NumElem);\n\nforeach $i ( 1..100 ) {\n$elem = NumElem( $i );\n$heap->add( $elem );\n}\n\nwhile( defined( $elem = $heap->extracttop ) ) {\nprint \"Smallest is \", $elem->val, \"\\n\";\n}\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "The Heap collection of modules provide routines that manage a heap of elements. A heap is a\npartially sorted structure that is always able to easily extract the smallest of the elements in\nthe structure (or the largest if a reversed compare routine is provided).\n\nIf the collection of elements is changing dynamically, the heap has less overhead than keeping\nthe collection fully sorted.\n\nThe elements must be objects as described in \"Heap::Elem\" and all elements inserted into one\nheap must be mutually compatible - either the same class exactly or else classes that differ\nonly in ways unrelated to the Heap::Elem interface.\n",
                "subsections": []
            },
            "METHODS": {
                "content": "$heap = HeapClass::new(); $heap2 = $heap1->new();\nReturns a new heap object of the specified (sub-)class. This is often used as a subroutine\ninstead of a method, of course.\n\n$heap->DESTROY\nEnsures that no internal circular data references remain. Some variants of Heap ignore this\n(they have no such references). Heap users normally need not worry about it, DESTROY is\nautomatically invoked when the heap reference goes out of scope.\n\n$heap->add($elem)\nAdd an element to the heap.\n\n$elem = $heap->top\nReturn the top element on the heap. It is not removed from the heap but will remain at the\ntop. It will be the smallest element on the heap (unless a reversed cmp function is being\nused, in which case it will be the largest). Returns *undef* if the heap is empty.\n\nThis method used to be called \"minimum\" instead of \"top\". The old name is still supported\nbut is deprecated. (It was confusing to use the method \"minimum\" to get the maximum value on\nthe heap when a reversed cmp function was used for ordering elements.)\n\n$elem = $heap->extracttop\nDelete the top element from the heap and return it. Returns *undef* if the heap was empty.\n\nThis method used to be called \"extractminimum\" instead of \"extracttop\". The old name is\nstill supported but is deprecated. (It was confusing to use the method \"extractminimum\" to\nget the maximum value on the heap when a reversed cmp function was used for ordering\nelements.)\n\n$heap1->absorb($heap2)\nMerge all of the elements from *$heap2* into *$heap1*. This will leave *$heap2* empty.\n\n$heap1->decreasekey($elem)\nThe element will be moved closed to the top of the heap if it is now smaller than any higher\nparent elements. The user must have changed the value of *$elem* before *decreasekey* is\ncalled. Only a decrease is permitted. (This is a decrease according to the *cmp* function -\nif it is a reversed order comparison, then you are only permitted to increase the value of\nthe element. To be pedantic, you may only use *decreasekey* if *$elem-*cmp($elemoriginal)\n<= 0> if *$elemoriginal* were an elem with the value that *$elem* had before it was\n*decreased*.)\n\n$elem = $heap->delete($elem)\nThe element is removed from the heap (whether it is at the top or not).\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "John Macdonald, john@perlwolf.com\n",
                "subsections": []
            },
            "COPYRIGHT": {
                "content": "Copyright 1998-2007, O'Reilly & Associates.\n\nThis code is distributed under the same copyright terms as perl itself.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "Heap::Elem(3), Heap::Binary(3), Heap::Binomial(3), Heap::Fibonacci(3).\n",
                "subsections": []
            }
        }
    }
}