sorting - Go: Is there a way to avoid the implementation of the full sort.Interface for slices of structs? -
if have array/slice of structs in go , want sort them using sort package seems me need implement whole sort interface contains 3 methods:
- len
- swap
- less
it seems len , swap should have same implementation no matter type of struct in array.
is there way avoid having implement len , swap every time or limitation lack of generics in go?
your own answer right. in case of array or slice implementations of len() , swap() simple. len() go provide native swap() here. interface used can used more complex data structures btrees. still allows sort() function work (like parallel quicksort, uses same sort interface).
Comments
Post a Comment