Skip to content

Commit

Permalink
Initial PriorityQueue implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
destel committed Dec 3, 2024
1 parent 2779dbb commit 96a903c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions buffer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package rill

import (
"github.com/destel/rill/internal/core"
"github.com/destel/rill/internal/heapbuffer"
)

func PriorityQueue[A any](in <-chan Try[A], capacity int, less func(A, A) bool) <-chan Try[A] {
buf := heapbuffer.New(capacity, func(item1, item2 Try[A]) bool {
// Always prioritize errors
if item1.Error != nil {
return true
}
if item2.Error != nil {
return false
}

// invert the comparison to get max-heap behavior
return !less(item1.Value, item2.Value)
})

return core.CustomBuffer(in, buf)

Check failure on line 22 in buffer.go

View workflow job for this annotation

GitHub Actions / coverage

in call to core.CustomBuffer, type *heapbuffer.Buffer[Try[A]] of buf does not match inferred type core.iBuffer[Try[A]] for core.iBuffer[A]

Check failure on line 22 in buffer.go

View workflow job for this annotation

GitHub Actions / gotest (1.21.x)

type *heapbuffer.Buffer[Try[A]] of buf does not match inferred type core.iBuffer[Try[A]] for core.iBuffer[A]

Check failure on line 22 in buffer.go

View workflow job for this annotation

GitHub Actions / gotest (1.23.x)

in call to core.CustomBuffer, type *heapbuffer.Buffer[Try[A]] of buf does not match inferred type core.iBuffer[Try[A]] for core.iBuffer[A]
}

0 comments on commit 96a903c

Please sign in to comment.