Skip to content

container/heap: Fix is not correct #12304

@jonathantcummings

Description

@jonathantcummings

Documentation( http://golang.org/pkg/container/heap/#Fix ) states:
"Fix re-establishes the heap ordering after the element at index i has changed its value."

A simple test proves that this functionality is broken. Add 10 numbers 0->9 and the heap will look like this:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Change heap[9] to 0 making the heap look like this:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 0]
Call heap.Fix(9) and the heap looks like this:
[0, 0, 2, 3, 1, 5, 6, 7, 8, 4]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions