zig update: sort

This commit is contained in:
Motiejus Jakštys 2023-06-06 18:43:35 +03:00
parent 6d957967ed
commit 617c256863
4 changed files with 8 additions and 8 deletions

View File

@ -33,7 +33,7 @@ Project goals
Dependencies Dependencies
------------ ------------
1. zig around `0.11.0-dev.3132+465272921`. 1. zig around `0.11.0-dev.3312+ab37ab33c`.
2. [cmph][cmph]: bundled with this repository. 2. [cmph][cmph]: bundled with this repository.
Building Building

View File

@ -89,7 +89,7 @@ pub fn init(
defer baseAllocator.free(name_idx); defer baseAllocator.free(name_idx);
for (usersConst, 0..) |user, i| name_idx[i] = for (usersConst, 0..) |user, i| name_idx[i] =
NameIdx{ .name = user.name, .idx = i }; NameIdx{ .name = user.name, .idx = i };
sort.sort(NameIdx, name_idx, {}, Compare.name); sort.pdq(NameIdx, name_idx, {}, Compare.name);
try users.ensureTotalCapacity(allocator, usersConst.len); try users.ensureTotalCapacity(allocator, usersConst.len);
for (name_idx) |entry| { for (name_idx) |entry| {
@ -104,7 +104,7 @@ pub fn init(
defer baseAllocator.free(gid_idx); defer baseAllocator.free(gid_idx);
for (groupsConst, 0..) |group, i| for (groupsConst, 0..) |group, i|
gid_idx[i] = GidIdx{ .gid = group.gid, .idx = i }; gid_idx[i] = GidIdx{ .gid = group.gid, .idx = i };
sort.sort(GidIdx, gid_idx, {}, Compare.gid); sort.pdq(GidIdx, gid_idx, {}, Compare.gid);
try groups.ensureTotalCapacity(allocator, groupsConst.len); try groups.ensureTotalCapacity(allocator, groupsConst.len);
for (gid_idx) |entry| { for (gid_idx) |entry| {
@ -192,12 +192,12 @@ pub fn init(
} }
for (group2users) |*groupusers| for (group2users) |*groupusers|
sort.sort(u32, groupusers.*, {}, comptime sort.asc(u32)); sort.pdq(u32, groupusers.*, {}, comptime sort.asc(u32));
var user2groups_final = try allocator.alloc([]const u32, users.len); var user2groups_final = try allocator.alloc([]const u32, users.len);
user2groups_final.len = users.len; user2groups_final.len = users.len;
for (user2groups, user2groups_final) |*usergroups, *user2groups_final_i| { for (user2groups, user2groups_final) |*usergroups, *user2groups_final_i| {
sort.sort(u32, usergroups.items, {}, comptime sort.asc(u32)); sort.pdq(u32, usergroups.items, {}, comptime sort.asc(u32));
user2groups_final_i.* = try usergroups.toOwnedSlice(allocator); user2groups_final_i.* = try usergroups.toOwnedSlice(allocator);
} }

View File

@ -905,7 +905,7 @@ test "DB pack gids" {
const k3 = bdz.search_u32(cmph_gid, 9999); const k3 = bdz.search_u32(cmph_gid, 9999);
const k4 = bdz.search_u32(cmph_gid, 100000); const k4 = bdz.search_u32(cmph_gid, 100000);
var hashes = [_]u32{ k1, k2, k3, k4 }; var hashes = [_]u32{ k1, k2, k3, k4 };
sort.sort(u32, &hashes, {}, comptime sort.asc(u32)); sort.heap(u32, &hashes, {}, comptime sort.asc(u32));
for (hashes, 0..) |hash, i| for (hashes, 0..) |hash, i|
try testing.expectEqual(i, hash); try testing.expectEqual(i, hash);
} }

View File

@ -128,7 +128,7 @@ test "cmph pack u32" {
var hashes: [keys.len]u32 = undefined; var hashes: [keys.len]u32 = undefined;
for (keys, &hashes) |key, *hash_i| for (keys, &hashes) |key, *hash_i|
hash_i.* = bdz.search_u32(packed_mphf, key); hash_i.* = bdz.search_u32(packed_mphf, key);
sort.sort(u32, hashes[0..], {}, comptime sort.asc(u32)); sort.heap(u32, hashes[0..], {}, comptime sort.asc(u32));
for (hashes, 0..) |hash, i| for (hashes, 0..) |hash, i|
try testing.expectEqual(i, hash); try testing.expectEqual(i, hash);
} }
@ -140,7 +140,7 @@ test "cmph pack str" {
var hashes: [keys.len]u32 = undefined; var hashes: [keys.len]u32 = undefined;
for (keys, &hashes) |key, *hash_i| for (keys, &hashes) |key, *hash_i|
hash_i.* = bdz.search(packed_mphf, key); hash_i.* = bdz.search(packed_mphf, key);
sort.sort(u32, hashes[0..], {}, comptime sort.asc(u32)); sort.heap(u32, hashes[0..], {}, comptime sort.asc(u32));
for (hashes, 0..) |hash, i| for (hashes, 0..) |hash, i|
try testing.expectEqual(i, hash); try testing.expectEqual(i, hash);
} }