tiny.simd.AlignedVector
Defined in aligned.
Source
Source: lib/simd/src/aligned.zig:112
zig
pub fn Vector(comptime T: type) type { return struct { storage: ?Allocation(T) = null, len_value: usize = 0, const Self = @This(); pub fn init( allocator: std.mem.Allocator, initial: []const T, ) Error!Self { var self = try initCapacity(allocator, initial.len); if (initial.len != 0) { @memcpy(self.storage.?.values[0..initial.len], initial); self.len_value = initial.len; } return self; } pub fn initCapacity( allocator: std.mem.Allocator, capacity_value: usize, ) Error!Self { if (capacity_value == 0) return .{}; return .{ .storage = try Allocation(T).init(allocator, capacity_value) }; } pub fn deinit(self: *Self, allocator: std.mem.Allocator) void { if (self.storage) |*storage| storage.deinit(allocator); self.* = .{}; } pub fn len(self: *const Self) usize { return self.len_value; } pub fn capacity(self: *const Self) usize { return if (self.storage) |storage| storage.values.len else 0; } pub fn items(self: *Self) []T { if (self.storage) |*storage| return storage.values[0..self.len_value]; return @constCast((&[_]T{})[0..]); } pub fn constItems(self: *const Self) []const T { if (self.storage) |*storage| return storage.values[0..self.len_value]; return &.{}; } pub fn append( self: *Self, allocator: std.mem.Allocator, value: T, ) Error!void { const required = std.math.add(usize, self.len_value, 1) catch return error.AllocationSizeOverflow; try self.ensureTotalCapacity(allocator, required); self.storage.?.values[self.len_value] = value; self.len_value += 1; } pub fn appendSlice( self: *Self, allocator: std.mem.Allocator, values: []const T, ) Error!void { if (values.len == 0) return; const required = std.math.add(usize, self.len_value, values.len) catch return error.AllocationSizeOverflow; try self.ensureTotalCapacity(allocator, required); @memcpy(self.storage.?.values[self.len_value..required], values); self.len_value = required; } pub fn pop(self: *Self) ?T { if (self.len_value == 0) return null; self.len_value -= 1; return self.storage.?.values[self.len_value]; } pub fn clearRetainingCapacity(self: *Self) void { self.len_value = 0; } pub fn ensureTotalCapacity( self: *Self, allocator: std.mem.Allocator, required: usize, ) Error!void { const current_capacity = self.capacity(); if (required <= current_capacity) return; const grown = std.math.mul(usize, current_capacity, 2) catch required; const new_capacity = @max(required, @max(@as(usize, 8), grown)); var replacement = try Allocation(T).init(allocator, new_capacity); if (self.storage) |*storage| { @memcpy(replacement.values[0..self.len_value], storage.values[0..self.len_value]); storage.deinit(allocator); } self.storage = replacement; } };}Source: lib/simd/src/root.zig:250
zig
pub const AlignedVector = aligned.Vector;Audit
| Definitions | 1 |
|---|---|
| Public names | 2 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |