Last active
August 4, 2023 17:01
-
-
Save likern/dbbe4be8e03010dc37e0a9668263dae2 to your computer and use it in GitHub Desktop.
pdq.zig
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn pdq( | |
comptime T: type, | |
items: []T, | |
context: anytype, | |
comptime lessThanFn: fn (context: @TypeOf(context), lhs: T, rhs: T) bool, | |
) void { | |
const Context = struct { | |
items: []T, | |
sub_ctx: @TypeOf(context), | |
pub fn lessThan(ctx: @This(), a: usize, b: usize) bool { | |
return lessThanFn(ctx.sub_ctx, ctx.items[a], ctx.items[b]); | |
} | |
pub fn swap(ctx: @This(), a: usize, b: usize) void { | |
return mem.swap(T, &ctx.items[a], &ctx.items[b]); | |
} | |
}; | |
pdqContext(0, items.len, Context{ .items = items, .sub_ctx = context }); | |
} | |
const Hint = enum { | |
increasing, | |
decreasing, | |
unknown, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment