@@ -1232,11 +1232,33 @@ pub fn ArrayHashMapUnmanaged(
1232
1232
pub inline fn sort (self : * Self , sort_ctx : anytype ) void {
1233
1233
if (@sizeOf (ByIndexContext ) != 0 )
1234
1234
@compileError ("Cannot infer context " ++ @typeName (Context ) ++ ", call sortContext instead." );
1235
- return self . sortContext ( sort_ctx , undefined );
1235
+ return sortContextInternal ( self , .stable , sort_ctx , undefined );
1236
1236
}
1237
1237
1238
- pub fn sortContext (self : * Self , sort_ctx : anytype , ctx : Context ) void {
1239
- self .entries .sort (sort_ctx );
1238
+ pub inline fn sortUnstable (self : * Self , sort_ctx : anytype ) void {
1239
+ if (@sizeOf (ByIndexContext ) != 0 )
1240
+ @compileError ("Cannot infer context " ++ @typeName (Context ) ++ ", call sortContext instead." );
1241
+ return self .sortContextInternal (.unstable , sort_ctx , undefined );
1242
+ }
1243
+
1244
+ pub inline fn sortContext (self : * Self , sort_ctx : anytype , ctx : Context ) void {
1245
+ return sortContextInternal (self , .stable , sort_ctx , ctx );
1246
+ }
1247
+
1248
+ pub inline fn sortUnstableContext (self : * Self , sort_ctx : anytype , ctx : Context ) void {
1249
+ return sortContextInternal (self , .unstable , sort_ctx , ctx );
1250
+ }
1251
+
1252
+ fn sortContextInternal (
1253
+ self : * Self ,
1254
+ comptime mode : std.sort.Mode ,
1255
+ sort_ctx : anytype ,
1256
+ ctx : Context ,
1257
+ ) void {
1258
+ switch (mode ) {
1259
+ .stable = > self .entries .sort (sort_ctx ),
1260
+ .unstable = > self .entries .sortUnstable (sort_ctx ),
1261
+ }
1240
1262
const header = self .index_header orelse return ;
1241
1263
header .reset ();
1242
1264
self .insertAllEntriesIntoNewHeader (if (store_hash ) {} else ctx , header );
0 commit comments