zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 1345f87f4efb7444516fceb76b1d60ec18ddebc1 (tree)
parent 69f0fc513a1926e6214733c678f785b724da0340
Author: Bhargav Srinivasan <bsvasan92@icloud.com>
Date:   Tue, 22 Sep 2020 01:50:22 -0700

items are not sorted, using linear search

Diffstat:
Mlib/std/priority_queue.zig | 13++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)

diff --git 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);