Skip to content

std.ArrayHashMap: add unstable sorting capability #17426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
andrewrk opened this issue Oct 7, 2023 · 0 comments
Closed

std.ArrayHashMap: add unstable sorting capability #17426

andrewrk opened this issue Oct 7, 2023 · 0 comments
Labels
contributor friendly This issue is limited in scope and/or knowledge of Zig internals. enhancement Solving this issue will likely involve adding new logic or components to the codebase. optimization standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@andrewrk
Copy link
Member

andrewrk commented Oct 7, 2023

These functions are available:

zig/lib/std/array_hash_map.zig

Lines 1229 to 1243 in d68f39b

/// Sorts the entries and then rebuilds the index.
/// `sort_ctx` must have this method:
/// `fn lessThan(ctx: @TypeOf(ctx), a_index: usize, b_index: usize) bool`
pub inline fn sort(self: *Self, sort_ctx: anytype) void {
if (@sizeOf(ByIndexContext) != 0)
@compileError("Cannot infer context " ++ @typeName(Context) ++ ", call sortContext instead.");
return self.sortContext(sort_ctx, undefined);
}
pub fn sortContext(self: *Self, sort_ctx: anytype, ctx: Context) void {
self.entries.sort(sort_ctx);
const header = self.index_header orelse return;
header.reset();
self.insertAllEntriesIntoNewHeader(if (store_hash) {} else ctx, header);
}

However, unstable sort is preferred when possible. This API should offer unstable sorting as well.

@andrewrk andrewrk added enhancement Solving this issue will likely involve adding new logic or components to the codebase. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. optimization standard library This issue involves writing Zig code for the standard library. labels Oct 7, 2023
@andrewrk andrewrk added this to the 0.14.0 milestone Oct 7, 2023
andrewrk added a commit that referenced this issue Oct 7, 2023
andrewrk added a commit that referenced this issue Oct 7, 2023
@andrewrk andrewrk mentioned this issue Oct 8, 2023
11 tasks
@andrewrk andrewrk modified the milestones: 0.14.0, 0.12.0 Oct 9, 2023
@mlugg mlugg moved this to Uncategorized in Performance Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor friendly This issue is limited in scope and/or knowledge of Zig internals. enhancement Solving this issue will likely involve adding new logic or components to the codebase. optimization standard library This issue involves writing Zig code for the standard library.
Projects
Archived in project
Development

No branches or pull requests

1 participant