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.array_list.Aligned.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

array_list.zig:1070
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
        pub fn orderedRemoveMany(self: *Self, sorted_indexes: []const usize) void {
            self.pointer_stability.assertUnlocked();
            if (sorted_indexes.len == 0) return;
            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
                @memmove(self.items[start - shift ..][0..len], self.items[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.items.len;
            const len = end - start; // safety checks final `sorted_indexes` are in range
            @memmove(self.items[start - shift ..][0..len], self.items[start..][0..len]);
            self.items.len = end - shift;
        }