From d2ace3e12527cf54099ed5187e3fd91073393ab0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Mon, 7 Mar 2022 21:14:19 +0200 Subject: [PATCH] remove redundant fields --- src/sections.zig | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/src/sections.zig b/src/sections.zig index 020b6bb..59ff7c1 100644 --- a/src/sections.zig +++ b/src/sections.zig @@ -31,15 +31,12 @@ const Corpus = struct { // sorted by gid groups: []Group, - // convenience users and groups by column + // columnar users and groups of the above usersMulti: MultiArrayList(User), groupsMulti: MultiArrayList(Group), - // pointing to `users` and `groups` slices above. name2user: StringHashMap(usize), - uid2user: AutoHashMap(u32, usize), name2group: StringHashMap(usize), - gid2group: AutoHashMap(u32, usize), groupname2users: StringHashMap([]usize), username2groups: StringHashMap([]usize), @@ -72,20 +69,12 @@ const Corpus = struct { groupsMulti.appendAssumeCapacity(group); var name2user = StringHashMap(usize).init(allocator); - var uid2user = AutoHashMap(u32, usize).init(allocator); var name2group = StringHashMap(usize).init(allocator); - var gid2group = AutoHashMap(u32, usize).init(allocator); for (users) |*user, i| { var res1 = try name2user.getOrPut(user.name); if (res1.found_existing) return error.Duplicate; res1.value_ptr.* = i; - - var res2 = try uid2user.getOrPut(user.uid); - if (res2.found_existing) - return error.Duplicate; - - res2.value_ptr.* = i; } for (groups) |*group, i| { @@ -93,10 +82,6 @@ const Corpus = struct { if (res1.found_existing) return error.Duplicate; res1.value_ptr.* = i; - var res2 = try gid2group.getOrPut(group.gid); - if (res2.found_existing) - return error.Duplicate; - res2.value_ptr.* = i; } var groupname2users = StringHashMap([]usize).init(allocator); @@ -157,9 +142,7 @@ const Corpus = struct { .usersMulti = usersMulti, .groupsMulti = groupsMulti, .name2user = name2user, - .uid2user = uid2user, .name2group = name2group, - .gid2group = gid2group, .groupname2users = groupname2users, .username2groups = username2groups_final, }; @@ -525,12 +508,8 @@ test "test corpus" { try testing.expectEqual(corpus.name2user.get("404"), null); try testing.expectEqual(corpus.name2user.get("vidmantas").?, vidmantas); - try testing.expectEqual(corpus.uid2user.get(42), null); - try testing.expectEqual(corpus.uid2user.get(128).?, vidmantas); try testing.expectEqual(corpus.name2group.get("404"), null); try testing.expectEqual(corpus.name2group.get("vidmantas").?, g_vidmantas); - try testing.expectEqual(corpus.gid2group.get(42), null); - try testing.expectEqual(corpus.gid2group.get(128).?, g_vidmantas); const membersOfAll = corpus.groupname2users.get("all").?; try testing.expectEqual(membersOfAll[0], name_name);