You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But when I import "github.com/emirpasic/gods/queues/priorityqueue" and build the code on https://go.dev/play, I meet the error:
go: finding module for package github.com/emirpasic/gods/queues/priorityqueue
go: downloading github.com/emirpasic/gods v1.18.1
go: found github.com/emirpasic/gods/queues/priorityqueue in github.com/emirpasic/gods v1.18.1
./prog.go:11:31: invalid operation: cannot index priorityqueue.NewWith (value of type func(comparator utils.Comparator) *priorityqueue.Queue)
Here are some source codes:
// NewWith instantiates a new empty queue with the custom comparator.funcNewWith[Tcomparable](comparator utils.Comparator[T]) *Queue[T] {
return&Queue[T]{heap: binaryheap.NewWith(comparator), Comparator: comparator}
}
// comparable is an interface that is implemented by all comparable types// (booleans, numbers, strings, pointers, channels, arrays of comparable types,// structs whose fields are all comparable types).// The comparable interface may only be used as a type parameter constraint,// not as the type of a variable.typecomparableinterface{ comparable }
But, I have added generics and implemented comparators, why are there still errors?
Meanwhile, while compiling the code locally, I encountered this error again:
D:\space\algorithm\leetcode-top-interview-questions\src> go build .\problem_0023_merge_k_sorted_lists.go
# github.com/emirpasic/gods/queues/priorityqueue
D:\opt\go1.22\gopath\pkg\mod\github.com\emirpasic\[email protected]\queues\priorityqueue\iterator.go:13:7: type instantiation requires go1.18 or later (-lang was set to go1.2; check go.mod)
D:\opt\go1.22\gopath\pkg\mod\github.com\emirpasic\[email protected]\queues\priorityqueue\iterator.go:16:15: type parameter requires go1.18 or later (-lang was set to go1.2; check go.mod)
D:\opt\go1.22\gopath\pkg\mod\github.com\emirpasic\[email protected]\queues\priorityqueue\iterator.go:16:17: predeclared comparable requires go1.18 or later (-lang was set to go1.2; check go.mod)
D:\opt\go1.22\gopath\pkg\mod\github.com\emirpasic\[email protected]\queues\priorityqueue\iterator.go:17:12: type instantiation requires go1.18 or later (-lang was set to go1.2; check go.mod)
D:\opt\go1.22\gopath\pkg\mod\github.com\emirpasic\[email protected]\queues\priorityqueue\priorityqueue.go:32:12: type parameter requires go1.18 or later (-lang was set to go1.2; check go.mod)
D:\opt\go1.22\gopath\pkg\mod\github.com\emirpasic\[email protected]\queues\priorityqueue\priorityqueue.go:32:14: predeclared comparable requires go1.18 or later (-lang was set to go1.2; check go.mod)
D:\opt\go1.22\gopath\pkg\mod\github.com\emirpasic\[email protected]\queues\priorityqueue\priorityqueue.go:33:14: type instantiation requires go1.18 or later (-lang was set to go1.2; check go.mod)
D:\opt\go1.22\gopath\pkg\mod\github.com\emirpasic\[email protected]\queues\priorityqueue\priorityqueue.go:34:13: type instantiation requires go1.18 or later (-lang was set to go1.2; check go.mod)
D:\opt\go1.22\gopath\pkg\mod\github.com\emirpasic\[email protected]\queues\priorityqueue\priorityqueue.go:37:10: type parameter requires go1.18 or later (-lang was set to go1.2; check go.mod)
D:\opt\go1.22\gopath\pkg\mod\github.com\emirpasic\[email protected]\queues\priorityqueue\priorityqueue.go:42:14: type parameter requires go1.18 or later (-lang was set to go1.2; check go.mod)
D:\opt\go1.22\gopath\pkg\mod\github.com\emirpasic\[email protected]\queues\priorityqueue\iterator.go:13:7: too many errors
My Go version is go version go1.22.0 windows/amd64. And this is my go.mod
This is a leetcode problem:merge k sorted lists, I want to use a heap to solve it, and the following code can be AC.
But type assertion is required, and I want to add generics to solve this problem. I noticed that the following libraries have already introduced generics: https://github.com/emirpasic/gods/blob/master/queues/priorityqueue/priorityqueue.go
So I adjusted my code and added generics:
But when I import "github.com/emirpasic/gods/queues/priorityqueue" and build the code on https://go.dev/play, I meet the error:
Here are some source codes:
But, I have added generics and implemented comparators, why are there still errors?
Meanwhile, while compiling the code locally, I encountered this error again:
My Go version is go version go1.22.0 windows/amd64. And this is my go.mod
How can I solve the above two problems? Thank you!
The text was updated successfully, but these errors were encountered: