{
    "content": [
        {
            "type": "text",
            "text": "# Heap::Elem (perldoc)\n\n## NAME\n\nHeap::Elem - Base class for elements in a Heap\n\n## SYNOPSIS\n\nuse Heap::Elem::SomeInheritor;\nuse Heap::SomeHeapClass;\n$elem = Heap::Elem::SomeInheritor->new( $value );\n$heap = Heap::SomeHeapClass->new;\n$heap->add($elem);\n\n## DESCRIPTION\n\nThis is an inheritable class for Heap Elements. It provides the interface documentation and some\ninheritable methods. Only a child classes can be used - this class is not complete.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **METHODS**\n- **INHERITING**\n- **AUTHOR**\n- **COPYRIGHT**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "Heap::Elem",
        "section": "",
        "mode": "perldoc",
        "summary": "Heap::Elem - Base class for elements in a Heap",
        "synopsis": "use Heap::Elem::SomeInheritor;\nuse Heap::SomeHeapClass;\n$elem = Heap::Elem::SomeInheritor->new( $value );\n$heap = Heap::SomeHeapClass->new;\n$heap->add($elem);",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [
            {
                "name": "Heap",
                "section": "3",
                "url": "https://www.chedong.com/phpMan.php/man/Heap/3/json"
            },
            {
                "name": "Num",
                "section": "3",
                "url": "https://www.chedong.com/phpMan.php/man/Num/3/json"
            },
            {
                "name": "NumRev",
                "section": "3",
                "url": "https://www.chedong.com/phpMan.php/man/NumRev/3/json"
            },
            {
                "name": "Str",
                "section": "3",
                "url": "https://www.chedong.com/phpMan.php/man/Str/3/json"
            },
            {
                "name": "StrRev",
                "section": "3",
                "url": "https://www.chedong.com/phpMan.php/man/StrRev/3/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 9,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "METHODS",
                "lines": 33,
                "subsections": []
            },
            {
                "name": "INHERITING",
                "lines": 28,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "COPYRIGHT",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "Heap::Elem - Base class for elements in a Heap\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use Heap::Elem::SomeInheritor;\n\nuse Heap::SomeHeapClass;\n\n$elem = Heap::Elem::SomeInheritor->new( $value );\n$heap = Heap::SomeHeapClass->new;\n\n$heap->add($elem);\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "This is an inheritable class for Heap Elements. It provides the interface documentation and some\ninheritable methods. Only a child classes can be used - this class is not complete.\n",
                "subsections": []
            },
            "METHODS": {
                "content": "$elem = Heap::Elem::SomeInheritor->new( [args] );\nCreates a new Elem. If there is exactly one arg, the Elem's value will be set to that value.\nIf there is more than one arg provided, the Elem's value will be set to an anonymous hash\ninitialized to the provided args (which must have an even number, of course).\n\n$elem->heap( $val ); $elem->heap;\nProvides a method for use by the Heap processing routines. If a value argument is provided,\nit will be saved. The new saved value is always returned. If no value argument is provided,\nthe old saved value is returned.\n\nThe Heap processing routines use this method to map an element into its internal structure.\nThis is needed to support the Heap methods that affect elements that are not are the top of\nthe heap - *decreasekey* and *delete*.\n\nThe Heap processing routines will ensure that this value is undef when this elem is removed\nfrom a heap, and is not undef after it is inserted into a heap. This means that you can\ncheck whether an element is currently contained within a heap or not. (It cannot be used to\ndetermine which heap an element is contained in, if you have multiple heaps. Keeping that\ninformation accurate would make the operation of merging two heaps into a single one take\nlonger - it would have to traverse all of the elements in the merged heap to update them;\nfor Binomial and Fibonacci heaps that would turn an O(1) operation into an O(n) one.)\n\n$elem->val( $val ); $elem->val;\nProvides a method to get and/or set the value of the element.\n\n$elem1->cmp($elem2)\nA routine to compare two elements. It must return a negative value if this element should go\nhigher on the heap than *$elem2*, 0 if they are equal, or a positive value if this element\nshould go lower on the heap than *$elem2*. Just as with sort, the Perl operators <=> and cmp\ncause the smaller value to be returned first; similarly you can negate the meaning to\nreverse the order - causing the heap to always return the largest element instead of the\nsmallest.\n",
                "subsections": []
            },
            "INHERITING": {
                "content": "This class can be inherited to provide an object with the ability to be heaped. If the object is\nimplemented as a hash, and if it can deal with a key of *heap*, leaving it unchanged for use by\nthe heap routines, then the following implemetation will work.\n\npackage myObject;\n\nrequire Exporter;\n\n@ISA = qw(Heap::Elem);\n\nsub new {\nmy $self = shift;\nmy $class = ref($self) || $self;\n\nmy $self = SUPER::new($class);\n\n# set $self->{key} = $value;\n}\n\nsub cmp {\nmy $self = shift;\nmy $other = shift;\n\n$self->{key} cmp $other->{key};\n}\n\n# other methods for the rest of myObject's functionality\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(3), Heap::Elem::Num(3), Heap::Elem::NumRev(3), Heap::Elem::Str(3), Heap::Elem::StrRev(3).\n",
                "subsections": []
            }
        }
    }
}