aboutsummaryrefslogtreecommitdiff
path: root/lib/std/priority_queue.zig
diff options
context:
space:
mode:
authorBhargav Srinivasan <bsvasan92@icloud.com>2020-09-22 01:50:22 -0700
committerBhargav Srinivasan <bsvasan92@icloud.com>2020-09-22 01:50:22 -0700
commit1345f87f4efb7444516fceb76b1d60ec18ddebc1 (patch)
tree33b00ef6e623ca4e2e46c9b82f584183d0c134bf /lib/std/priority_queue.zig
parent69f0fc513a1926e6214733c678f785b724da0340 (diff)
downloadzig-1345f87f4efb7444516fceb76b1d60ec18ddebc1.tar.gz
zig-1345f87f4efb7444516fceb76b1d60ec18ddebc1.zip
items are not sorted, using linear search
Diffstat (limited to 'lib/std/priority_queue.zig')
-rw-r--r--lib/std/priority_queue.zig13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/std/priority_queue.zig b/lib/std/priority_queue.zig
index 345d5db584..6e0e47dd05 100644
--- a/lib/std/priority_queue.zig
+++ b/lib/std/priority_queue.zig
@@ -190,12 +190,19 @@ pub fn PriorityQueue(comptime T: type) type {
self.len = new_len;
}
- fn orderFn(lhs: T, rhs: T) std.math.Order {
- return std.math.order(lhs, rhs);
+ fn linearSearch(elem: T, items: []const T) usize {
+ var found: usize = 0;
+ for (items) |item, i| {
+ if (item == elem) {
+ found = i;
+ break;
+ }
+ }
+ return found;
}
pub fn update(self: *Self, elem: T, new_elem: T) !void {
- var update_index: usize = std.sort.binarySearch(T, elem, self.items, {}, orderFn) orelse 0;
+ var update_index: usize = linearSearch(elem, self.items);
assert (update_index >= 0 and update_index < self.items.len);
_ = self.removeIndex(update_index);
try self.add(new_elem);