Hi Guys, is it possible to implement generic, efficient binary search using generics or interfaces. So i'll have some index, and data inside single struct and then could just define a comparison function between 2 variables of same type index which will return bool.
Will have 20-30 million datapoints
type abc struct {
index uint32
data1 []byte
data2 []string
}
type bcd struct {
index [4]byte
data1 []byte
data2 []string
}
a = []abc{...}
b = []bcd{...}
find(a, 217621)
find(b, [4]byte{1,2,54,11})
Currently i have this, which is probably incorrect:
type comparable[TC any] interface {
compare(TC, TC) bool
}
func bin[T comparable](data []T, find T) int {
}
Is that even possible to do efficiently or i should just go with writing separated code for each struct type ?