mirror of
https://codeberg.org/kaasboteram/zig-iterating.git
synced 2026-02-19 05:27:03 +01:00
Renamed many variables/paramaters called gpa to allocator
This commit is contained in:
parent
a440d40797
commit
075b246858
1 changed files with 9 additions and 9 deletions
18
src/root.zig
18
src/root.zig
|
|
@ -37,7 +37,7 @@ pub fn Iter(comptime T: type) type {
|
||||||
test Iter {
|
test Iter {
|
||||||
const testing = @import("std").testing;
|
const testing = @import("std").testing;
|
||||||
|
|
||||||
const gpa = testing.allocator;
|
const allocator = testing.allocator;
|
||||||
|
|
||||||
const arith = struct {
|
const arith = struct {
|
||||||
fn is_square(x: i32) bool {
|
fn is_square(x: i32) bool {
|
||||||
|
|
@ -55,9 +55,9 @@ test Iter {
|
||||||
.chain(Iter(i32)
|
.chain(Iter(i32)
|
||||||
.range(0, 10)),
|
.range(0, 10)),
|
||||||
)
|
)
|
||||||
.toOwnedSlice(gpa);
|
.toOwnedSlice(allocator);
|
||||||
|
|
||||||
defer gpa.free(items);
|
defer allocator.free(items);
|
||||||
|
|
||||||
try testing.expectEqualSlices(
|
try testing.expectEqualSlices(
|
||||||
i32,
|
i32,
|
||||||
|
|
@ -173,19 +173,19 @@ pub fn Iterator(comptime Inner: type) type {
|
||||||
try testing.expectEqualDeep(struct { i32, i32 }{ 10, 20 }, it.next().?);
|
try testing.expectEqualDeep(struct { i32, i32 }{ 10, 20 }, it.next().?);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toOwnedSlice(self: Self, gpa: std.mem.Allocator) ![]const Item {
|
pub fn toOwnedSlice(self: Self, allocator: std.mem.Allocator) ![]const Item {
|
||||||
var list: std.ArrayList(Item) = .empty;
|
var list: std.ArrayList(Item) = .empty;
|
||||||
errdefer list.deinit(gpa);
|
errdefer list.deinit(allocator);
|
||||||
|
|
||||||
try self.collectInto(&list, gpa);
|
try self.collectInto(&list, allocator);
|
||||||
|
|
||||||
return try list.toOwnedSlice(gpa);
|
return try list.toOwnedSlice(allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn collectInto(self: Self, list: *std.ArrayList(Item), gpa: std.mem.Allocator) !void {
|
pub fn collectInto(self: Self, list: *std.ArrayList(Item), allocator: std.mem.Allocator) !void {
|
||||||
var mutSelf = self;
|
var mutSelf = self;
|
||||||
while (mutSelf.next()) |val| {
|
while (mutSelf.next()) |val| {
|
||||||
try list.append(gpa, val);
|
try list.append(allocator, val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue