use Multi where appropriate

This commit is contained in:
Motiejus Jakštys 2022-03-09 06:02:55 +02:00 committed by Motiejus Jakštys
parent 15e018389a
commit 8fbd605b8d

View File

@ -70,15 +70,15 @@ const Corpus = struct {
var name2user = StringHashMap(u32).init(allocator); var name2user = StringHashMap(u32).init(allocator);
var name2group = StringHashMap(u32).init(allocator); var name2group = StringHashMap(u32).init(allocator);
for (users) |*user, i| { for (usersMulti.items(.name)) |name, i| {
var res1 = try name2user.getOrPut(user.name); var res1 = try name2user.getOrPut(name);
if (res1.found_existing) if (res1.found_existing)
return error.Duplicate; return error.Duplicate;
res1.value_ptr.* = @intCast(u32, i); res1.value_ptr.* = @intCast(u32, i);
} }
for (groups) |*group, i| { for (groupsMulti.items(.name)) |name, i| {
var res1 = try name2group.getOrPut(group.name); var res1 = try name2group.getOrPut(name);
if (res1.found_existing) if (res1.found_existing)
return error.Duplicate; return error.Duplicate;
res1.value_ptr.* = @intCast(u32, i); res1.value_ptr.* = @intCast(u32, i);
@ -92,11 +92,11 @@ const Corpus = struct {
defer baseAllocator.free(user2groups); defer baseAllocator.free(user2groups);
mem.set(ArrayListUnmanaged(u32), user2groups, ArrayListUnmanaged(u32){}); mem.set(ArrayListUnmanaged(u32), user2groups, ArrayListUnmanaged(u32){});
for (groups) |*group, i| { for (groupsMulti.items(.members)) |group_members, i| {
var members = try allocator.alloc(u32, group.members.count()); var members = try allocator.alloc(u32, group_members.count());
members.len = 0; members.len = 0;
var it = group.members.iterator(); var it = group_members.iterator();
while (it.next()) |memberName| { while (it.next()) |memberName| {
if (name2user.get(memberName.*)) |user_idx| { if (name2user.get(memberName.*)) |user_idx| {
members.len += 1; members.len += 1;
@ -206,8 +206,7 @@ pub fn userGids(
var scratch = try allocator.alloc(u32, 256); var scratch = try allocator.alloc(u32, 256);
defer allocator.free(scratch); defer allocator.free(scratch);
for (corpus.users) |_, user_idx| { for (corpus.user2groups) |usergroups, user_idx| {
const usergroups = corpus.user2groups[user_idx];
if (usergroups.len == 0) { if (usergroups.len == 0) {
idx2offset[user_idx] = 0; idx2offset[user_idx] = 0;
continue; continue;
@ -298,16 +297,15 @@ pub fn groupMembers(
errdefer blob.deinit(); errdefer blob.deinit();
// zero'th entry is empty, so empty groups can refer to it // zero'th entry is empty, so empty groups can refer to it
try compress.appendUvarint(&blob, 0); try compress.appendUvarint(&blob, 0);
for (corpus.groups) |_, i| { for (corpus.groupsMulti.items(.group)) |group_users, i| {
const users = corpus.group2users[i]; if (group_users.len == 0) {
if (users.len == 0) {
idx2offset[i] = 0; idx2offset[i] = 0;
continue; continue;
} }
idx2offset[i] = blob.len; idx2offset[i] = blob.len;
compress.appendUvarint(&blob, users.len); compress.appendUvarint(&blob, group_users.len);
for (users) |userIdx| for (group_users) |userIdx|
compress.appendUvarint(&blob, user2offset[userIdx]); compress.appendUvarint(&blob, user2offset[userIdx]);
} }
return GroupMembers{ return GroupMembers{