(items []Item, item Item, index int)
| 1171 | } |
| 1172 | |
| 1173 | func insertItemIntoSlice(items []Item, item Item, index int) []Item { |
| 1174 | if items == nil { |
| 1175 | return []Item{item} |
| 1176 | } |
| 1177 | if index >= len(items) { |
| 1178 | return append(items, item) |
| 1179 | } |
| 1180 | |
| 1181 | index = max(0, index) |
| 1182 | |
| 1183 | items = append(items, nil) |
| 1184 | copy(items[index+1:], items[index:]) |
| 1185 | items[index] = item |
| 1186 | return items |
| 1187 | } |
| 1188 | |
| 1189 | // Remove an item from a slice of items at the given index. This runs in O(n). |
| 1190 | func removeItemFromSlice(i []Item, index int) []Item { |