ugurcsen/gods-generic

Type constraint on V in treemap is unnecessary

YoungerLee opened this issue · 5 comments

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]
}

There already was a pull request which did this for other types: #2
linkedhashmap.Map has the same issue.

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

Can you create a pr for this issue?

sz-po commented

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!

Can you create a pr for this issue?

ok