Skip to content

Commit

Permalink
slices.Delete: fix runtime complexity documentation
Browse files Browse the repository at this point in the history
O(len(s)-j) i.e. proportional to the number of elements shifted to the left.

Fixes golang/go#54699

Change-Id: Ifffeca54e0f53289015864aa301f20b9344befb9
Reviewed-on: https://go-review.googlesource.com/c/exp/+/425994
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
  • Loading branch information
Deleplace authored and randall77 committed Aug 26, 2022
1 parent 4cc3b17 commit bd9bcdd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion slices/slices.go
Expand Up @@ -151,7 +151,7 @@ func Insert[S ~[]E, E any](s S, i int, v ...E) S {
// Delete removes the elements s[i:j] from s, returning the modified slice.
// Delete panics if s[i:j] is not a valid slice of s.
// Delete modifies the contents of the slice s; it does not create a new slice.
// Delete is O(len(s)-(j-i)), so if many items must be deleted, it is better to
// Delete is O(len(s)-j), so if many items must be deleted, it is better to
// make a single call deleting them all together than to delete one at a time.
func Delete[S ~[]E, E any](s S, i, j int) S {
_ = s[i:j] // bounds check
Expand Down

0 comments on commit bd9bcdd

Please sign in to comment.