1
Fork 0

groupname2users -> group2users

main
Motiejus Jakštys 2022-03-09 05:42:59 +02:00 committed by Motiejus Jakštys
parent 9aa52e5a69
commit c79741f4e2
1 changed files with 8 additions and 13 deletions

View File

@ -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);