From c79741f4e22f4c10ea69aa5e8d1a1201d7116f3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Wed, 9 Mar 2022 05:42:59 +0200 Subject: [PATCH] groupname2users -> group2users --- src/sections.zig | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/sections.zig b/src/sections.zig index e315698..56acbed 100644 --- a/src/sections.zig +++ b/src/sections.zig @@ -37,7 +37,7 @@ const Corpus = struct { name2user: StringHashMap(u32), name2group: StringHashMap(u32), - groupname2users: StringHashMap([]u32), + group2users: []const []const u32, username2groups: StringHashMap([]u32), pub fn init( @@ -84,7 +84,7 @@ const Corpus = struct { res1.value_ptr.* = @intCast(u32, i); } - var groupname2users = StringHashMap([]u32).init(allocator); + var group2users = try allocator.alloc([]u32, groups.len); // uses baseAllocator, because it will be freed before // returning from this function. This keeps the arena clean. @@ -112,14 +112,10 @@ const Corpus = struct { try groupsOfMember.value_ptr.*.append(allocator, @intCast(u32, i)); } - var result = try groupname2users.getOrPut(group.name); - if (result.found_existing) - return error.Duplicate; - result.value_ptr.* = members; + group2users[i] = members; } - var it1 = groupname2users.valueIterator(); - while (it1.next()) |groupUsers| { + for (group2users) |*groupUsers| { sort.sort(u32, groupUsers.*, {}, comptime sort.asc(u32)); } @@ -143,7 +139,7 @@ const Corpus = struct { .groupsMulti = groupsMulti, .name2user = name2user, .name2group = name2group, - .groupname2users = groupname2users, + .group2users = group2users, .username2groups = username2groups_final, }; } @@ -311,8 +307,8 @@ pub fn groupMembers( errdefer blob.deinit(); // zero'th entry is empty, so empty groups can refer to it try compress.appendUvarint(&blob, 0); - for (corpus.groups) |group, i| { - const users = corpus.groupname2users.get(group.name).?; + for (corpus.groups) |_, i| { + const users = corpus.group2users[i]; if (users.len == 0) { idx2offset[i] = 0; continue; @@ -509,11 +505,10 @@ test "test corpus" { try testing.expectEqual(corpus.name2group.get("404"), null); try testing.expectEqual(corpus.name2group.get("vidmantas").?, g_vidmantas); - const membersOfAll = corpus.groupname2users.get("all").?; + const membersOfAll = corpus.group2users[g_all]; try testing.expectEqual(membersOfAll[0], name_name); try testing.expectEqual(membersOfAll[1], svc_bar); try testing.expectEqual(membersOfAll[2], vidmantas); - try testing.expectEqual(corpus.groupname2users.get("404"), null); const groupsOfVidmantas = corpus.username2groups.get("vidmantas").?; try testing.expectEqual(groupsOfVidmantas[0], g_service_account);