Skip to content

Commit

Permalink
naming: mid for index and mid_item for item
Browse files Browse the repository at this point in the history
  • Loading branch information
rofrol authored and truemedian committed Mar 30, 2023
1 parent 9bfb931 commit 1d46f92
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/std/sort.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn binarySearch(
key: anytype,
items: []const T,
context: anytype,
comptime compareFn: fn (context: @TypeOf(context), key: @TypeOf(key), mid: T) math.Order,
comptime compareFn: fn (context: @TypeOf(context), key: @TypeOf(key), mid_item: T) math.Order,
) ?usize {
var left: usize = 0;
var right: usize = items.len;
Expand Down Expand Up @@ -79,14 +79,14 @@ test "binarySearch" {
return @This(){ .b = b, .e = e };
}

fn order(context: void, key: i32, mid: @This()) math.Order {
fn order(context: void, key: i32, mid_item: @This()) math.Order {
_ = context;

if (key < mid.b) {
if (key < mid_item.b) {
return .lt;
}

if (key > mid.e) {
if (key > mid_item.e) {
return .gt;
}

Expand Down Expand Up @@ -1069,8 +1069,8 @@ fn binaryFirst(
const offset = size % 2;

size /= 2;
const mid = items[curr + size];
if (lessThan(context, mid, value)) {
const mid_item = items[curr + size];
if (lessThan(context, mid_item, value)) {
curr += size + offset;
}
}
Expand All @@ -1092,8 +1092,8 @@ fn binaryLast(
const offset = size % 2;

size /= 2;
const mid = items[curr + size];
if (!lessThan(context, value, mid)) {
const mid_item = items[curr + size];
if (!lessThan(context, value, mid_item)) {
curr += size + offset;
}
}
Expand Down

0 comments on commit 1d46f92

Please sign in to comment.