3 ms·
It's because it's the wrong data-structure for the job. A slice is not sparse. If you need to delete from the middle of an ordered collection of items then it'
by zimbatm 10y ago
It's because it's the wrong data-structure for the job. A slice is not sparse.
If you need to delete from the middle of an ordered collection of items then it's better to use a linked or doubly-linked list (unless it's small then it doesn't matter).
- masklinn 10y ago> It's because it's the wrong data-structure for the job. A slice is not sparse. So? > If you need to delete from the middle of an ordered collection of items then it's better to use a linked or doubly-linked list (unless it's small then it doesn't matter). Meh. Deleting from the middle of an array is one memmove, you don't get 1~2 pointers memory overhead, caches blown and having to deref' n pointers getting to the item to remove in the first place. If your language provides arrays, there are almost no cases where you should reach for linked lists without having seriously benched both cases. And that's before the consideration that a Go linked list means loss of type safety or a hand-rolled hand-specialized implementation.
- junke 10y agoYou don't want to memmove an array which content is shared by another array, which is what slices are about.