aboutsummaryrefslogtreecommitdiff
path: root/std/array_list.zig
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-06-04 02:58:55 -0400
committerAndrew Kelley <superjoe30@gmail.com>2018-06-04 02:58:55 -0400
commit58ce79f9352a6139c873df6d99d1531101350e9f (patch)
tree227df3571b4ac48afc38777902251647870c5e1b /std/array_list.zig
parentcb042c8343eb94a8d149fe1f5d69aa2746aa85d0 (diff)
parent96164ce61377b36bcaf0c4087ca9b1ab822b9457 (diff)
downloadzig-58ce79f9352a6139c873df6d99d1531101350e9f.tar.gz
zig-58ce79f9352a6139c873df6d99d1531101350e9f.zip
Merge remote-tracking branch 'origin/master' into llvm7
Diffstat (limited to 'std/array_list.zig')
-rw-r--r--std/array_list.zig52
1 files changed, 26 insertions, 26 deletions
diff --git a/std/array_list.zig b/std/array_list.zig
index 679f7d73b8..07a1db6451 100644
--- a/std/array_list.zig
+++ b/std/array_list.zig
@@ -17,10 +17,10 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
/// you uninitialized memory.
items: []align(A) T,
len: usize,
- allocator: &Allocator,
+ allocator: *Allocator,
/// Deinitialize with `deinit` or use `toOwnedSlice`.
- pub fn init(allocator: &Allocator) Self {
+ pub fn init(allocator: *Allocator) Self {
return Self{
.items = []align(A) T{},
.len = 0,
@@ -28,30 +28,30 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
};
}
- pub fn deinit(l: &const Self) void {
+ pub fn deinit(l: *const Self) void {
l.allocator.free(l.items);
}
- pub fn toSlice(l: &const Self) []align(A) T {
+ pub fn toSlice(l: *const Self) []align(A) T {
return l.items[0..l.len];
}
- pub fn toSliceConst(l: &const Self) []align(A) const T {
+ pub fn toSliceConst(l: *const Self) []align(A) const T {
return l.items[0..l.len];
}
- pub fn at(l: &const Self, n: usize) T {
+ pub fn at(l: *const Self, n: usize) T {
return l.toSliceConst()[n];
}
- pub fn count(self: &const Self) usize {
+ pub fn count(self: *const Self) usize {
return self.len;
}
/// ArrayList takes ownership of the passed in slice. The slice must have been
/// allocated with `allocator`.
/// Deinitialize with `deinit` or use `toOwnedSlice`.
- pub fn fromOwnedSlice(allocator: &Allocator, slice: []align(A) T) Self {
+ pub fn fromOwnedSlice(allocator: *Allocator, slice: []align(A) T) Self {
return Self{
.items = slice,
.len = slice.len,
@@ -60,51 +60,51 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
}
/// The caller owns the returned memory. ArrayList becomes empty.
- pub fn toOwnedSlice(self: &Self) []align(A) T {
+ pub fn toOwnedSlice(self: *Self) []align(A) T {
const allocator = self.allocator;
const result = allocator.alignedShrink(T, A, self.items, self.len);
self.* = init(allocator);
return result;
}
- pub fn insert(l: &Self, n: usize, item: &const T) !void {
+ pub fn insert(l: *Self, n: usize, item: *const T) !void {
try l.ensureCapacity(l.len + 1);
l.len += 1;
- mem.copy(T, l.items[n + 1..l.len], l.items[n..l.len - 1]);
+ mem.copy(T, l.items[n + 1 .. l.len], l.items[n .. l.len - 1]);
l.items[n] = item.*;
}
- pub fn insertSlice(l: &Self, n: usize, items: []align(A) const T) !void {
+ pub fn insertSlice(l: *Self, n: usize, items: []align(A) const T) !void {
try l.ensureCapacity(l.len + items.len);
l.len += items.len;
- mem.copy(T, l.items[n + items.len..l.len], l.items[n..l.len - items.len]);
- mem.copy(T, l.items[n..n + items.len], items);
+ mem.copy(T, l.items[n + items.len .. l.len], l.items[n .. l.len - items.len]);
+ mem.copy(T, l.items[n .. n + items.len], items);
}
- pub fn append(l: &Self, item: &const T) !void {
+ pub fn append(l: *Self, item: *const T) !void {
const new_item_ptr = try l.addOne();
new_item_ptr.* = item.*;
}
- pub fn appendSlice(l: &Self, items: []align(A) const T) !void {
+ pub fn appendSlice(l: *Self, items: []align(A) const T) !void {
try l.ensureCapacity(l.len + items.len);
mem.copy(T, l.items[l.len..], items);
l.len += items.len;
}
- pub fn resize(l: &Self, new_len: usize) !void {
+ pub fn resize(l: *Self, new_len: usize) !void {
try l.ensureCapacity(new_len);
l.len = new_len;
}
- pub fn shrink(l: &Self, new_len: usize) void {
+ pub fn shrink(l: *Self, new_len: usize) void {
assert(new_len <= l.len);
l.len = new_len;
}
- pub fn ensureCapacity(l: &Self, new_capacity: usize) !void {
+ pub fn ensureCapacity(l: *Self, new_capacity: usize) !void {
var better_capacity = l.items.len;
if (better_capacity >= new_capacity) return;
while (true) {
@@ -114,7 +114,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
l.items = try l.allocator.alignedRealloc(T, A, l.items, better_capacity);
}
- pub fn addOne(l: &Self) !&T {
+ pub fn addOne(l: *Self) !*T {
const new_length = l.len + 1;
try l.ensureCapacity(new_length);
const result = &l.items[l.len];
@@ -122,34 +122,34 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type {
return result;
}
- pub fn pop(self: &Self) T {
+ pub fn pop(self: *Self) T {
self.len -= 1;
return self.items[self.len];
}
- pub fn popOrNull(self: &Self) ?T {
+ pub fn popOrNull(self: *Self) ?T {
if (self.len == 0) return null;
return self.pop();
}
pub const Iterator = struct {
- list: &const Self,
+ list: *const Self,
// how many items have we returned
count: usize,
- pub fn next(it: &Iterator) ?T {
+ pub fn next(it: *Iterator) ?T {
if (it.count >= it.list.len) return null;
const val = it.list.at(it.count);
it.count += 1;
return val;
}
- pub fn reset(it: &Iterator) void {
+ pub fn reset(it: *Iterator) void {
it.count = 0;
}
};
- pub fn iterator(self: &const Self) Iterator {
+ pub fn iterator(self: *const Self) Iterator {
return Iterator{
.list = self,
.count = 0,