| ... | @@ -113,11 +113,20 @@ pub fn Queue(comptime T: type) type { | ... | @@ -113,11 +113,20 @@ pub fn Queue(comptime T: type) type { |
| 113 | | 113 | |
| 114 | pub fn dumpToStream(self: *Self, comptime Error: type, stream: *std.io.OutStream(Error)) Error!void { | 114 | pub fn dumpToStream(self: *Self, comptime Error: type, stream: *std.io.OutStream(Error)) Error!void { |
| 115 | const S = struct { | 115 | const S = struct { |
| 116 | fn dumpRecursive(s: *std.io.OutStream(Error), optional_node: ?*Node, indent: usize) Error!void { | 116 | fn dumpRecursive( |
| | 117 | s: *std.io.OutStream(Error), |
| | 118 | optional_node: ?*Node, |
| | 119 | indent: usize, |
| | 120 | comptime depth: comptime_int, |
| | 121 | ) Error!void { |
| 117 | try s.writeByteNTimes(' ', indent); | 122 | try s.writeByteNTimes(' ', indent); |
| 118 | if (optional_node) |node| { | 123 | if (optional_node) |node| { |
| 119 | try s.print("0x{x}={}\n", .{ @ptrToInt(node), node.data }); | 124 | try s.print("0x{x}={}\n", .{ @ptrToInt(node), node.data }); |
| 120 | try dumpRecursive(s, node.next, indent + 1); | 125 | if (depth == 0) { |
| | 126 | try s.print("(max depth)\n", .{}); |
| | 127 | return; |
| | 128 | } |
| | 129 | try dumpRecursive(s, node.next, indent + 1, depth - 1); |
| 121 | } else { | 130 | } else { |
| 122 | try s.print("(null)\n", .{}); | 131 | try s.print("(null)\n", .{}); |
| 123 | } | 132 | } |
| ... | @@ -127,9 +136,9 @@ pub fn Queue(comptime T: type) type { | ... | @@ -127,9 +136,9 @@ pub fn Queue(comptime T: type) type { |
| 127 | defer held.release(); | 136 | defer held.release(); |
| 128 | | 137 | |
| 129 | try stream.print("head: ", .{}); | 138 | try stream.print("head: ", .{}); |
| 130 | try S.dumpRecursive(stream, self.head, 0); | 139 | try S.dumpRecursive(stream, self.head, 0, 4); |
| 131 | try stream.print("tail: ", .{}); | 140 | try stream.print("tail: ", .{}); |
| 132 | try S.dumpRecursive(stream, self.tail, 0); | 141 | try S.dumpRecursive(stream, self.tail, 0, 4); |
| 133 | } | 142 | } |
| 134 | }; | 143 | }; |
| 135 | } | 144 | } |