Socket
Book a DemoInstallSign in
Socket

github.com/szabba/heap

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/szabba/heap

Source
Go
Version
v0.0.0-20140825182600-44a74e20602a
Version published
Created
Source

github.com/szabba/heap

The code has been extracted from github.com/daviddengcn/go-villa. The package provides a type-safe alternative to container/heap from the standard library.

The package only requires that the type being used implements sort.Interface. The pop and push operations are provided by the package. The trick is that they do not return/take the deleted/inserted element but assume the last position in the underlying sort.Interface is where to put/find it.

Example

The example below leverages the implementation of sort.Interface provided by the standard sort package and creates short wrappers with a more elegant interface.

type IntHeap []int

func (h *IntHeap) Pop() int {
	heap.PopToLast(sort.IntSlice(*h))
	res := (*h)[len(*h) - 1]
	*h = (*h)[:len(*h) - 1]

	return res
}

func (h *IntHeap) Push(x int) {
	*h = append(*h, x)
	heap.PushLast(sort.IntSlice(*h))
}

The library is provided under the 2-clause BSD license (see LICENSE).

Copyright for github.com/szabba/heap (c) 2014, Karol Marcjan All rights reserved.

Copyright for github.com/daviddengcn/go-villa (c) 2013, Yi DENG All right reserved.

FAQs

Package last updated on 25 Aug 2014

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.