You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

github.com/menefotto/pqueue

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/menefotto/pqueue

v0.0.0-20180423212747-50ec0e99e956
Source
Go
Version published
Created
Source

pqueue

Package pqueue provides a simple priority queue implementation

GoDoc Build Status Coverage Status License: MIT

Queue can be either a max or min priority queue depending on the given Comparator function.

How do I use it?

In order to use it as max priority queue instantiate a pqueue with the New method like so:

    func less(i, j int, values []interface{}) bool {
        l, _ := values[i].(int)
        r, _ := values[j].(int)
        return l < r
    }

    pq := pqueue.New(less)

Otherwise if one wants to create min priority queue instantiate qa pqueue with the New method and a great Comparator function like so:

    func greater(i ,j int, values []interface{}) bool {
        l, _ := values[i].(int)
        r, _ := values[j].(int)
        return l > r
    }

    pq := pqueue.New(great)

Type casting inside the Comparator function is essential since comparison cannot be performed on interfaces. To extract the largest or smallest value ( depending on the queue ), call the Top method or to extract and remove it call PopTop, like so:

    v := pq.PopTop() // removes the values
    v := pq.Top() // gives a copy of the value not removing it from the queue

Important

  • Nothing to add

Philosophy

This software is developed following the "mantra" keep it simple, stupid or better known as KISS.

Thank You Notes

Implementation follows closely the implementation given in "Algorithms by Robert Sedgewick".

FAQs

Package last updated on 23 Apr 2018

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.