
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
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.
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
Unknown package
Did you know?
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.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.