Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/fsmiamoto/heap

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/fsmiamoto/heap

  • v0.0.6
  • Source
  • Go
  • Socket score

Version published
Created
Source

heap

go.dev reference Go Report Card GoCover Test

A generic binary heap data structure in Go.

It works with any type as long as you provide a comparison function.

The package defines two example functions for building a Max or Min Heap of integers.

Examples

  • Heapsort
func main() {
    values := []interface{}{40, 30, 50, 100, 15}

    // You can specify an initial capacity for the heap,
    // len(values) in this case, which helps to avoid reallocations.
    // Also, this heap uses the package defined MinInt comparison function,
    // that builds a MinHeap of integers
    h := heap.New(values, len(values), heap.MinInt)

    var sorted []int
    for !h.IsEmpty() {
        v, err := h.Extract()
        if err != nil {
            log.Fatal(err)
        }
        sorted = append(sorted, v.(int))
    }
    fmt.Println(sorted) // [15 30 40 50 100]
}

FAQs

Package last updated on 06 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc