diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-09-12 10:48:38 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-09-12 10:48:38 -0700 |
| commit | af4cc20ce275aeb0e59eee3d893b2f310c1f0239 (patch) | |
| tree | cc3ff8fa792c20ff0fc0f1e19e98998cc76c07c2 /lib/std/priority_queue.zig | |
| parent | 03a23418ff13e6ff64cdeed3ef4b54f99c533d88 (diff) | |
| parent | 9fe4c89230df2d78c8bf37b4b1d7a9bedb92677b (diff) | |
| download | zig-af4cc20ce275aeb0e59eee3d893b2f310c1f0239.tar.gz zig-af4cc20ce275aeb0e59eee3d893b2f310c1f0239.zip | |
Merge remote-tracking branch 'origin/master' into stage2-zig-cc
Master branch added in the concept of library versioning being optional
to main.cpp. It will need to be re-added into this branch before merging
back into master.
Diffstat (limited to 'lib/std/priority_queue.zig')
| -rw-r--r-- | lib/std/priority_queue.zig | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/std/priority_queue.zig b/lib/std/priority_queue.zig index 1c0d230d4d..b9be9b70bf 100644 --- a/lib/std/priority_queue.zig +++ b/lib/std/priority_queue.zig @@ -195,7 +195,7 @@ pub fn PriorityQueue(comptime T: type) type { count: usize, pub fn next(it: *Iterator) ?T { - if (it.count > it.queue.len - 1) return null; + if (it.count >= it.queue.len) return null; const out = it.count; it.count += 1; return it.queue.items[out]; @@ -428,3 +428,12 @@ test "std.PriorityQueue: remove at index" { expectEqual(queue.remove(), 3); expectEqual(queue.removeOrNull(), null); } + +test "std.PriorityQueue: iterator while empty" { + var queue = PQ.init(testing.allocator, lessThan); + defer queue.deinit(); + + var it = queue.iterator(); + + expectEqual(it.next(), null); +} |
