This commit is contained in:
Pontus Rosqvist 2025-11-23 22:57:18 +00:00 committed by GitHub
commit 19d3870b5c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 558 additions and 714 deletions

View file

@ -629,10 +629,13 @@ pub fn sortUnstable(
std.sort.pdq(T, items, context, lessThanFn);
}
/// TODO: currently this just calls `insertionSortContext`. The block sort implementation
/// in this file needs to be adapted to use the sort context.
/// Sorts a range [a, b) using a stable algorithm (maintains relative order of equal elements) with custom context.
/// This is a lower-level interface for sorting that works with indices instead of slices.
///
/// The context must provide lessThan(a_idx, b_idx) and swap(a_idx, b_idx) methods and optionally
/// a rotate(start_idx, end_idx, amount) method (see `mem.rotate`).
pub fn sortContext(a: usize, b: usize, context: anytype) void {
std.sort.insertionContext(a, b, context);
std.sort.blockContext(a, b, context);
}
/// Sorts a range [a, b) using an unstable algorithm with custom context.

View file

@ -191,7 +191,7 @@ pub fn MultiArrayList(comptime T: type) type {
return lhs.alignment > rhs.alignment;
}
};
@setEvalBranchQuota(3 * fields.len * std.math.log2(fields.len));
@setEvalBranchQuota(10 * fields.len * std.math.log2(fields.len));
mem.sort(Data, &data, {}, Sort.lessThan);
var sizes_bytes: [fields.len]usize = undefined;
var field_indexes: [fields.len]usize = undefined;

View file

@ -7,6 +7,7 @@ const math = std.math;
pub const Mode = enum { stable, unstable };
pub const block = @import("sort/block.zig").block;
pub const blockContext = @import("sort/block.zig").blockContext;
pub const pdq = @import("sort/pdq.zig").pdq;
pub const pdqContext = @import("sort/pdq.zig").pdqContext;
@ -159,7 +160,7 @@ const sort_funcs = &[_]fn (comptime type, anytype, anytype, comptime anytype) vo
};
const context_sort_funcs = &[_]fn (usize, usize, anytype) void{
// blockContext,
blockContext,
pdqContext,
insertionContext,
heapContext,

File diff suppressed because it is too large Load diff