#Removing Elements from Lists ?
1 messages · Page 1 of 1 (latest)
var read_index: usize = 0;
var write_index: usize = 0;
while (read_index < list.items.len) : (read_index += 1) {
if (pred(list.items[read_index])) {
list.items[write_index] = list.items[read_index];
write_index += 1;
}
}
list.shrinkRetainingCapacity(write_index);
depending on how big the array is, it might be more efficient to re-create the arraylist and fill it with matching elements (can be done trivially with a for loop)
otherwise, youd want to use a while loop with list.orderedRemove or similar
oh thats smart, havent thought of that
i was also thinking about that.. but that would require an allocator right ?
it would
👍 ... this seems to do the trick...
technically you could borrow the arraylist's backing allocator but that's pretty bad UX
hmm.... got it... i did not even think that you could use the allocator from the list itself