authorgravatar for kbutcher6200@gmail.comkprotty <kbutcher6200@gmail.com> 2022-04-15 17:01:01-05:00
committergravatar for kbutcher6200@gmail.comkprotty <kbutcher6200@gmail.com> 2022-04-15 17:01:01-05:00
log33952dad1259d9f4af09ebbad094c9b27d565525
treeca68091c1cf8a71c10d51edad69b2d42da31bd39
parent4d0303b99249adcc4acdd51fa9a10884f1e5ed61

treap: zig fmt


1 files changed, 9 insertions(+), 9 deletions(-)

lib/std/treap.zig+9-9
...@@ -8,7 +8,7 @@ pub fn Treap(comptime Key: type, comptime compareFn: anytype) type {...@@ -8,7 +8,7 @@ pub fn Treap(comptime Key: type, comptime compareFn: anytype) type {
8 const Self = @This();8 const Self = @This();
99
10 // Allow for compareFn to be fn(anytype, anytype) anytype10 // Allow for compareFn to be fn(anytype, anytype) anytype
11 // which allows the convenient use of std.math.order. 11 // which allows the convenient use of std.math.order.
12 fn compare(a: Key, b: Key) Order {12 fn compare(a: Key, b: Key) Order {
13 return compareFn(a, b);13 return compareFn(a, b);
14 }14 }
...@@ -30,9 +30,9 @@ pub fn Treap(comptime Key: type, comptime compareFn: anytype) type {...@@ -30,9 +30,9 @@ pub fn Treap(comptime Key: type, comptime compareFn: anytype) type {
3030
31 // Since we're using usize, decide the shifts by the integer's bit width.31 // Since we're using usize, decide the shifts by the integer's bit width.
32 const shifts = switch (@bitSizeOf(usize)) {32 const shifts = switch (@bitSizeOf(usize)) {
33 64 => .{13, 7, 17},33 64 => .{ 13, 7, 17 },
34 32 => .{13, 17, 5},34 32 => .{ 13, 17, 5 },
35 16 => .{7, 9, 8},35 16 => .{ 7, 9, 8 },
36 else => @compileError("platform not supported"),36 else => @compileError("platform not supported"),
37 };37 };
3838
...@@ -42,7 +42,7 @@ pub fn Treap(comptime Key: type, comptime compareFn: anytype) type {...@@ -42,7 +42,7 @@ pub fn Treap(comptime Key: type, comptime compareFn: anytype) type {
4242
43 assert(self.xorshift != 0);43 assert(self.xorshift != 0);
44 return self.xorshift;44 return self.xorshift;
45 } 45 }
46 };46 };
4747
48 /// A Node represents an item or point in the treap with a uniquely associated key.48 /// A Node represents an item or point in the treap with a uniquely associated key.
...@@ -164,7 +164,7 @@ pub fn Treap(comptime Key: type, comptime compareFn: anytype) type {...@@ -164,7 +164,7 @@ pub fn Treap(comptime Key: type, comptime compareFn: anytype) type {
164164
165 return node;165 return node;
166 }166 }
167 167
168 fn insert(self: *Self, key: Key, parent: ?*Node, node: *Node) void {168 fn insert(self: *Self, key: Key, parent: ?*Node, node: *Node) void {
169 // generate a random priority & prepare the node to be inserted into the tree169 // generate a random priority & prepare the node to be inserted into the tree
170 node.key = key;170 node.key = key;
...@@ -232,11 +232,11 @@ pub fn Treap(comptime Key: type, comptime compareFn: anytype) type {...@@ -232,11 +232,11 @@ pub fn Treap(comptime Key: type, comptime compareFn: anytype) type {
232 }232 }
233233
234 fn rotate(self: *Self, node: *Node, right: bool) void {234 fn rotate(self: *Self, node: *Node, right: bool) void {
235 // if right, converts the following: 235 // if right, converts the following:
236 // parent -> (node (target YY adjacent) XX)236 // parent -> (node (target YY adjacent) XX)
237 // parent -> (target YY (node adjacent XX))237 // parent -> (target YY (node adjacent XX))
238 //238 //
239 // if left (!right), converts the following: 239 // if left (!right), converts the following:
240 // parent -> (node (target YY adjacent) XX)240 // parent -> (node (target YY adjacent) XX)
241 // parent -> (target YY (node adjacent XX))241 // parent -> (target YY (node adjacent XX))
242 const parent = node.parent;242 const parent = node.parent;
...@@ -389,7 +389,7 @@ test "std.Treap: insert, find, replace, remove" {...@@ -389,7 +389,7 @@ test "std.Treap: insert, find, replace, remove" {
389 try testing.expectEqual(entry.node, node);389 try testing.expectEqual(entry.node, node);
390 try testing.expectEqual(entry.node, treap.getEntryFor(key).node);390 try testing.expectEqual(entry.node, treap.getEntryFor(key).node);
391 try testing.expectEqual(entry.node, treap.getEntryForExisting(node).node);391 try testing.expectEqual(entry.node, treap.getEntryForExisting(node).node);
392 392
393 // remove the node again and make sure it was cleared after the insert393 // remove the node again and make sure it was cleared after the insert
394 entry.set(null);394 entry.set(null);
395 try testing.expectEqual(entry.node, null);395 try testing.expectEqual(entry.node, null);