MCPcopy
hub / github.com/mathaou/termdbms / insertItemIntoSlice

Function insertItemIntoSlice

list/list.go:1173–1187  ·  view source on GitHub ↗
(items []Item, item Item, index int)

Source from the content-addressed store, hash-verified

1171}
1172
1173func 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).
1190func removeItemFromSlice(i []Item, index int) []Item {

Callers 1

InsertItemMethod · 0.85

Calls 1

maxFunction · 0.70

Tested by

no test coverage detected