Skip to content

Commit dcfc851

Browse files
committed
ArrayHashMapWithAllocator: add sortUnstable fn alongside sort
1 parent cbe3dd1 commit dcfc851

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lib/std/array_hash_map.zig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,19 @@ pub fn ArrayHashMapWithAllocator(
460460
/// Sorts the entries and then rebuilds the index.
461461
/// `sort_ctx` must have this method:
462462
/// `fn lessThan(ctx: @TypeOf(ctx), a_index: usize, b_index: usize) bool`
463+
/// Uses a stable sorting algorithm.
463464
pub fn sort(self: *Self, sort_ctx: anytype) void {
464465
return self.unmanaged.sortContext(sort_ctx, self.ctx);
465466
}
466467

468+
/// Sorts the entries and then rebuilds the index.
469+
/// `sort_ctx` must have this method:
470+
/// `fn lessThan(ctx: @TypeOf(ctx), a_index: usize, b_index: usize) bool`
471+
/// Uses an unstable sorting algorithm.
472+
pub fn sortUnstable(self: *Self, sort_ctx: anytype) void {
473+
return self.unmanaged.sortUnstableContext(sort_ctx, self.ctx);
474+
}
475+
467476
/// Shrinks the underlying `Entry` array to `new_len` elements and
468477
/// discards any associated index entries. Keeps capacity the same.
469478
///

0 commit comments

Comments
 (0)