Skip to content

Commit

Permalink
Update dijkstra.go
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzotinfena committed Mar 7, 2024
1 parent 991b78a commit e23b088
Showing 1 changed file with 7 additions and 26 deletions.
33 changes: 7 additions & 26 deletions collections/graph/dijkstra.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package graph

import (
"github.com/lorenzotinfena/goji/collections"
cl "github.com/lorenzotinfena/goji/collections"
"github.com/lorenzotinfena/goji/collections/heap"
"github.com/lorenzotinfena/goji/utils"
Expand Down Expand Up @@ -52,7 +51,7 @@ func UnitDijkstra[V comparable](start V, adjacents func(V) []V, addV func(V), co

type weightedDijkstraIterator[V comparable, W constr.Integer | constr.Float] struct {
toAnalyze *heap.FibonacciHeap[V]
adjacents func(V) []collections.Pair[V, W]
adjacents func(V) []cl.Pair[V, W]
dijkstraSet func(V, *DijkstraNode[V, W])
dijkstraGet func(V) *DijkstraNode[V, W]
dijkstraContains func(V) bool
Expand All @@ -78,39 +77,21 @@ func (it *weightedDijkstraIterator[V, W]) Next() DijkstraNode[V, W] {
return *it.dijkstraGet(curr)
}

type weightedDijkstraFibonacciHeapWrapper[V comparable] struct {
set func(V, *heap.FibonacciHeapNode[V])
get func(V) *heap.FibonacciHeapNode[V]
}

func (w weightedDijkstraFibonacciHeapWrapper[V]) Add(item V, node *heap.FibonacciHeapNode[V]) {
w.set(item, node)
}

func (w weightedDijkstraFibonacciHeapWrapper[V]) GetOne(item V) *heap.FibonacciHeapNode[V] {
return w.get(item)
}

func (w weightedDijkstraFibonacciHeapWrapper[V]) Contains(_ V) bool {
panic("this should not be called")
}

func (w weightedDijkstraFibonacciHeapWrapper[V]) Remove(_ V, _ *heap.FibonacciHeapNode[V]) {
}

func WeightedDijkstra[V comparable, W constr.Integer | constr.Float](
start V,
adjacents func(V) []collections.Pair[V, W],
adjacents func(V) []cl.Pair[V, W],

dijkstraSet func(V, *DijkstraNode[V, W]),
dijkstraGet func(V) *DijkstraNode[V, W],
dijkstraContains func(V) bool,
fibonacciSet func(V, *heap.FibonacciHeapNode[V]),
fibonacciGet func(V) *heap.FibonacciHeapNode[V],
fibonacciSet func(V, []*heap.FibonacciHeapNode[V]),
fibonacciGet func(V) []*heap.FibonacciHeapNode[V],
fibonacciContains func(V) bool,
fibonacciRemove func(V),
) utils.Iterator[DijkstraNode[V, W]] {
toAnalyze := heap.NewFibonacciHeap[V](
func(v1, v2 V) bool { return dijkstraGet(v1).Cost < dijkstraGet(v2).Cost },
weightedDijkstraFibonacciHeapWrapper[V]{fibonacciSet, fibonacciGet})
fibonacciSet, fibonacciGet, dijkstraContains, fibonacciRemove)
toAnalyze.Push(start)
dijkstraSet(start, &DijkstraNode[V, W]{start, nil, W(0)})

Expand Down

0 comments on commit e23b088

Please sign in to comment.