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