1
Fork 0

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
1 changed files with 12 additions and 14 deletions

View File

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