ugurcsen / gods-generic

GoDS-Generic (Go Generic Data Structures) - Sets, Lists, Stacks, Maps, Trees, Queues, and much more
https://pkg.go.dev/github.com/ugurcsen/gods-generic
Other
65 stars 6 forks source link

Type constraint on V in treemap is unnecessary #7

Closed YoungerLee closed 10 months ago

YoungerLee commented 1 year ago

The type constraint on parameter V in treemap is not necessary, otherwise the any value is not allowed. What I need is

var t treemap.Map[string, any] = treemap.NewWithStringComparator[any]()

but the type parameter V is limited by comparable.

// Map holds the elements in a red-black tree
type Map[K, T comparable] struct {
    tree *rbt.Tree[K, T]
}

Consider the following code?

type Map[K comparable, T any] struct {
    tree *rbt.Tree[K, T]
}
Zyl9393 commented 1 year ago

There already was a pull request which did this for other types: https://github.com/ugurcsen/gods-generic/pull/2
linkedhashmap.Map has the same issue.

ugurcsen commented 1 year ago

I have to decrease code duplication first after that I will fix this.

ugurcsen commented 1 year ago

Can you create a pr for this issue?

sz-po commented 10 months ago

I'm experiencing the same problem. This restricts the library's usefulness to comparable types only, even as a map value. It's quite strange.

Would you be willing to add a comparable interface that users can use to compare their types?

Anyway, great job! Keep up the good work!

YoungerLee commented 10 months ago

Can you create a pr for this issue?

ok