Zig 0.17.0-dev (Split by item) This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig standard library.
std › multi_array_list › MultiArrayList › orderedRemoveMany Public Function orderedRemoveMany Doc Source Public Function std.multi_array_list.MultiArrayList.orderedRemoveMany
pub fn orderedRemoveMany (self : *Self , sorted_indexes : []const usize ) void Params self : *Self sorted_indexes : []const usize File multi_array_list.zig: 424
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446 pub fn orderedRemoveMany (self : *Self , sorted_indexes : []const usize ) void {
if (sorted_indexes .len == 0 ) return ;
const slices = self .slice ();
var shift : usize = 1 ;
for (sorted_indexes [0 .. sorted_indexes .len - 1 ], sorted_indexes [1 ..]) |removed , end | {
if (removed == end ) continue ; // allows duplicates in `sorted_indexes`
const start = removed + 1 ;
const len = end - start ; // safety checks `sorted_indexes` are sorted
inline for (field_names , 0 ..) |_ , field_index | {
const field_slice = slices .items (@fromBackingInt (@intCast (field_index )));
@memmove (field_slice [start - shift ..][0 ..len ], field_slice [start ..][0 ..len ]); // safety checks initial `sorted_indexes` are in range
}
shift += 1 ;
}
const start = sorted_indexes [sorted_indexes .len - 1 ] + 1 ;
const end = self .len ;
const len = end - start ; // safety checks final `sorted_indexes` are in range
inline for (field_names , 0 ..) |_ , field_index | {
const field_slice = slices .items (@fromBackingInt (@intCast (field_index )));
@memmove (field_slice [start - shift ..][0 ..len ], field_slice [start ..][0 ..len ]);
}
self .len = end - shift ;
}
Remove the elements indexed by
sorted_indexes. The indexes to be removed correspond to the array list before deletion.Asserts:
Duplicates in
sorted_indexesare allowed.This operation is O(N).
Invalidates element pointers beyond the first deleted index.