What is the complexity of Go's builtin append
function? What about string concatenation using +
?
I'd like to remove an element from a slice by appending two slices excluding that element, ex. http://play.golang.org/p/RIR5fXq-Sf
nums := []int{0, 1, 2, 3, 4, 5, 6, 7}
fmt.Println(append(nums[:4], nums[5:]...))
=> [0 1 2 3 5 6 7]
http://golang.org/pkg/builtin/#append says that if the destination has sufficient capacity, then that slice is resliced
. I'm hoping that "reslicing" is a constant time operation. I'm also hoping the same applies to string concatenation using +
.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…