Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kc596/ugcpriorityqueue
Unbuffered Generic Concurrent Priority Queue in GoLang.
https://github.com/kc596/ugcpriorityqueue
go golang priority-queue priorityqueue priorityqueues
Last synced: 16 days ago
JSON representation
Unbuffered Generic Concurrent Priority Queue in GoLang.
- Host: GitHub
- URL: https://github.com/kc596/ugcpriorityqueue
- Owner: kc596
- License: bsd-2-clause
- Created: 2020-10-31T16:00:47.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2020-11-03T13:50:14.000Z (about 4 years ago)
- Last Synced: 2024-10-11T11:17:37.098Z (about 1 month ago)
- Topics: go, golang, priority-queue, priorityqueue, priorityqueues
- Language: Go
- Homepage:
- Size: 22.5 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## UGC Priority Queue
[![Build Status](https://travis-ci.org/kc596/UGCPriorityQueue.svg?branch=master)](https://travis-ci.org/kc596/UGCPriorityQueue)
[![codecov](https://codecov.io/gh/kc596/UGCPriorityQueue/branch/master/graph/badge.svg?token=80KG51HA2Z)](https://codecov.io/gh/kc596/UGCPriorityQueue/branch/master/)
[![Go Report Card](https://goreportcard.com/badge/github.com/kc596/UGCPriorityQueue)](https://goreportcard.com/report/github.com/kc596/UGCPriorityQueue)**U**nbuffered **G**eneric **C**oncurrent Priority Queue in GoLang.
### Installation
> go get github.com/kc596/UGCPriorityQueue
### Quickstart
```go
import (
"github.com/kc596/UGCPriorityQueue/maxpq"
"fmt"
)func ExamplePQ() {
// create new max priority queue
pq := maxpq.New()
// creating new pq node with priority 1
node1 := maxpq.NewNode("Value1", 1)
// value of node could be of any type, int here
node2 := maxpq.NewNode(101, 10)
// add the nodes to pq
pq.Insert(node1)
pq.Insert(node2)
// get the node with highest priority
highestPriorityNode, _ := pq.Max()
fmt.Printf("%+v\n", highestPriorityNode)
// pop the nodes with highest priority
highestPriorityNode, _ = pq.Pop()
nextHighest, _ := pq.Pop()
fmt.Printf("%+v\n", highestPriorityNode) // value:101, priority:10
fmt.Printf("%+v\n", nextHighest) // value:Value1, priority:1
}
```### APIs
#### maxpq.PQ
Method | Return Type | Description
---|---|---
`IsEmpty()`|`bool` | Returns true if there are no nodes in priority queue
`Size()` | `int` | Returns the number of nodes in priority queue
`Insert(*Node)` | `void` | Adds a new node to the priority queue
`Max()` | `*Node,error` | Returns highest priority node of the priority queue
`Pop()` | `*Node,error` | Returns highest priority node and deletes it from priority queue
`Clear()` | `void` | Clears the priority queue#### maxpq.Node
Method | Return Type
---|---
`GetPriority()`|`float64`
`GetStringValue()` | `string`
`GetFloat64Value()` | `float64`
`GetFloat32Value()`| `float32`
`GetIntValue()`| `int`
`GetInt64Value()`| `int64`
`GetInt32Value()`| `int32`
`GetUIntValue()`| `uint`
`GetUInt64Value()`| `uint64`
`GetUInt32Value()`| `uint32`
`GetFuncValue()`| `func()`
`GetValue(target interface{})` | `void`