Slice
Add/Remove from Middle
i := 1
s := append(s[:i], s[i+1:]...)Performance Consideration
Sort
type Edge struct {
Nodes [2]*Node
Weight int
}
// ByWeight implements Golang sort interface.
type ByWeight []*Edge
func (s ByWeight) Len() int {
return len(s)
}
func (s ByWeight) Less(i, j int) bool {
return s[i].Weight < s[j].Weight
}
func (s ByWeight) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}Last updated