
Security News
Vite Releases Technical Preview of Rolldown-Vite, a Rust-Based Bundler
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
github.com/starwander/GoFIbonacciHeap
GoFibonacciHeap is a Golang implementation of Fibonacci Heap. This implementation is a bit different from the traditional Fibonacci Heap with an index map inside. Thanks to the index map, the internal struct 'node' no longer need to be exposed outsides the package. The index map also makes the random access to the values in the heap possible. But the union operation of this implementation is O(n) rather than O(1) of the traditional implementation.
Operations | Insert | Minimum | ExtractMin | Union | DecreaseKey | IncreaseKey | Delete | Get |
---|---|---|---|---|---|---|---|---|
Traditional Implementation | O(1) | O(1) | O(log n)ยน | O(1) | O(1)ยน | O(1)ยน | O(log n)ยน | N/A |
This Implementation | O(1) | O(1) | O(log n)ยน | O(n) | O(1)ยน | O(1)ยน | O(log n)ยน | O(1) |
ยน Amortized time. |
##Requirements #####Download this package
go get github.com/starwander/GoFibonacciHeap
#####Implements Value interface of this package for all values going to be inserted by value interfaces
// Value is the interface that all values push into or pop from the FibHeap by value interfaces must implement.
type Value interface {
// Tag returns the unique tag of the value.
// The tag is used in the index map.
Tag() interface{}
// Key returns the key as known as the priority of the value.
// The valid range of the key is (-inf, +inf].
Key() float64
}
package main
import (
"fmt"
"github.com/starwander/GoFibonacciHeap"
)
type student struct {
name string
age float64
}
func (s *student) Tag() interface{} {
return s.name
}
func (s *student) Key() float64 {
return s.age
}
func main() {
heap := fibHeap.NewFibHeap()
heap.InsertValue(&student{"John", 18.3})
heap.InsertValue(&student{"Tom", 21.0})
heap.InsertValue(&student{"Jessica", 19.4})
heap.InsertValue(&student{"Amy", 23.1})
fmt.Println(heap.Num()) // 4
fmt.Println(heap.Minimum()) // &{John 18.3}
fmt.Println(heap.Num()) // 4
john := heap.GetValue("John")
john.(*student).age = 20
heap.IncreaseKeyValue(john)
fmt.Println(heap.ExtractMin()) // &{Jessica 19.4}
fmt.Println(heap.ExtractMin()) // &{John 20}
fmt.Println(heap.Num()) // 2
amy := heap.GetValue("Amy")
amy.(*student).age = 16.5
heap.DecreaseKeyValue(amy)
fmt.Println(heap.ExtractMin()) // &{Amy 16.5}
fmt.Println(heap.Num()) // 1
fmt.Println(heap.ExtractValue("Tom")) // &{Tom 21}
fmt.Println(heap.Num()) // 0
}
GoFibonacciHeap source code is licensed under the Apache Licence, Version 2.0.
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.
Security News
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.