authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-30 20:43:56-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-30 20:43:56-04:00
logd7f15aa2cbead42516fe1339cd5395c3221216f4
tree88e93c80a993867c6f3ec70952037299219f5fa5
parentc52ee6efcabbe02e238e61da48fb12da8e1c927d
parent1f0bcefe4a1b00882f59982bd641f9adb927234f
signaturelock-open Commit is signed but in an unrecognized format.

Merge remote-tracking branch 'origin/master' into std.net


2 files changed, 21 insertions(+), 21 deletions(-)

lib/std/fs/path.zig+1-21
......@@ -253,27 +253,7 @@ pub fn windowsParsePath(path: []const u8) WindowsPath {
253253 return relative_path;
254254 }
255255
256 // TODO when I combined these together with `inline for` the compiler crashed
257 {
258 const this_sep = '/';
259 const two_sep = [_]u8{ this_sep, this_sep };
260 if (mem.startsWith(u8, path, two_sep)) {
261 if (path[2] == this_sep) {
262 return relative_path;
263 }
264
265 var it = mem.tokenize(path, [_]u8{this_sep});
266 _ = (it.next() orelse return relative_path);
267 _ = (it.next() orelse return relative_path);
268 return WindowsPath{
269 .is_abs = isAbsoluteWindows(path),
270 .kind = WindowsPath.Kind.NetworkShare,
271 .disk_designator = path[0..it.index],
272 };
273 }
274 }
275 {
276 const this_sep = '\\';
256 inline for ("/\\") |this_sep| {
277257 const two_sep = [_]u8{ this_sep, this_sep };
278258 if (mem.startsWith(u8, path, two_sep)) {
279259 if (path[2] == this_sep) {
lib/std/priority_queue.zig+20
......@@ -4,6 +4,7 @@ const debug = std.debug;
44const expect = std.testing.expect;
55const expectEqual = std.testing.expectEqual;
66
7/// Priority queue for storing generic data. Initialize with `init`.
78pub fn PriorityQueue(comptime T: type) type {
89 return struct {
910 const Self = @This();
......@@ -13,6 +14,12 @@ pub fn PriorityQueue(comptime T: type) type {
1314 allocator: *Allocator,
1415 compareFn: fn (a: T, b: T) bool,
1516
17 /// Initialize and return a priority queue. Provide
18 /// `compareFn` that returns `true` when its first argument
19 /// should get popped before its second argument. For example,
20 /// to make `pop` return the minimum value, provide
21 ///
22 /// `fn lessThan(a: T, b: T) bool { return a < b; }`
1623 pub fn init(allocator: *Allocator, compareFn: fn (a: T, b: T) bool) Self {
1724 return Self{
1825 .items = [_]T{},
......@@ -22,10 +29,12 @@ pub fn PriorityQueue(comptime T: type) type {
2229 };
2330 }
2431
32 /// Free memory used by the queue.
2533 pub fn deinit(self: Self) void {
2634 self.allocator.free(self.items);
2735 }
2836
37 /// Insert a new element, maintaining priority.
2938 pub fn add(self: *Self, elem: T) !void {
3039 try ensureCapacity(self, self.len + 1);
3140 addUnchecked(self, elem);
......@@ -48,6 +57,7 @@ pub fn PriorityQueue(comptime T: type) type {
4857 self.len += 1;
4958 }
5059
60 /// Add each element in `items` to the queue.
5161 pub fn addSlice(self: *Self, items: []const T) !void {
5262 try self.ensureCapacity(self.len + items.len);
5363 for (items) |e| {
......@@ -55,10 +65,14 @@ pub fn PriorityQueue(comptime T: type) type {
5565 }
5666 }
5767
68 /// Look at the highest priority element in the queue. Returns
69 /// `null` if empty.
5870 pub fn peek(self: *Self) ?T {
5971 return if (self.len > 0) self.items[0] else null;
6072 }
6173
74 /// Pop the highest priority element from the queue. Returns
75 /// `null` if empty.
6276 pub fn removeOrNull(self: *Self) ?T {
6377 return if (self.len > 0) self.remove() else null;
6478 }
......@@ -72,10 +86,14 @@ pub fn PriorityQueue(comptime T: type) type {
7286 return first;
7387 }
7488
89 /// Return the number of elements remaining in the priority
90 /// queue.
7591 pub fn count(self: Self) usize {
7692 return self.len;
7793 }
7894
95 /// Return the number of elements that can be added to the
96 /// queue before more memory is allocated.
7997 pub fn capacity(self: Self) usize {
8098 return self.items.len;
8199 }
......@@ -171,6 +189,8 @@ pub fn PriorityQueue(comptime T: type) type {
171189 }
172190 };
173191
192 /// Return an iterator that walks the queue without consuming
193 /// it. Invalidated if the heap is modified.
174194 pub fn iterator(self: *Self) Iterator {
175195 return Iterator{
176196 .queue = self,