Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
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. Public Function

orderedRemoveMany

Public Function
std.multi_array_list.MultiArrayList.orderedRemoveMany
pub fn orderedRemoveMany(self: *Self, sorted_indexes: []const usize) void

Remove the elements indexed by sorted_indexes. The indexes to be removed correspond to the array list before deletion.

Asserts:

  • Each index to be removed is in bounds.
  • The indexes to be removed are sorted ascending.

Duplicates in sorted_indexes are allowed.

This operation is O(N).

Invalidates element pointers beyond the first deleted index.

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;
        }