groupname2users -> group2users
This commit is contained in:
parent
9aa52e5a69
commit
c79741f4e2
@ -37,7 +37,7 @@ const Corpus = struct {
|
|||||||
|
|
||||||
name2user: StringHashMap(u32),
|
name2user: StringHashMap(u32),
|
||||||
name2group: StringHashMap(u32),
|
name2group: StringHashMap(u32),
|
||||||
groupname2users: StringHashMap([]u32),
|
group2users: []const []const u32,
|
||||||
username2groups: StringHashMap([]u32),
|
username2groups: StringHashMap([]u32),
|
||||||
|
|
||||||
pub fn init(
|
pub fn init(
|
||||||
@ -84,7 +84,7 @@ const Corpus = struct {
|
|||||||
res1.value_ptr.* = @intCast(u32, i);
|
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
|
// uses baseAllocator, because it will be freed before
|
||||||
// returning from this function. This keeps the arena clean.
|
// 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));
|
try groupsOfMember.value_ptr.*.append(allocator, @intCast(u32, i));
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = try groupname2users.getOrPut(group.name);
|
group2users[i] = members;
|
||||||
if (result.found_existing)
|
|
||||||
return error.Duplicate;
|
|
||||||
result.value_ptr.* = members;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var it1 = groupname2users.valueIterator();
|
for (group2users) |*groupUsers| {
|
||||||
while (it1.next()) |groupUsers| {
|
|
||||||
sort.sort(u32, groupUsers.*, {}, comptime sort.asc(u32));
|
sort.sort(u32, groupUsers.*, {}, comptime sort.asc(u32));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,7 +139,7 @@ const Corpus = struct {
|
|||||||
.groupsMulti = groupsMulti,
|
.groupsMulti = groupsMulti,
|
||||||
.name2user = name2user,
|
.name2user = name2user,
|
||||||
.name2group = name2group,
|
.name2group = name2group,
|
||||||
.groupname2users = groupname2users,
|
.group2users = group2users,
|
||||||
.username2groups = username2groups_final,
|
.username2groups = username2groups_final,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -311,8 +307,8 @@ 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) |group, i| {
|
for (corpus.groups) |_, i| {
|
||||||
const users = corpus.groupname2users.get(group.name).?;
|
const users = corpus.group2users[i];
|
||||||
if (users.len == 0) {
|
if (users.len == 0) {
|
||||||
idx2offset[i] = 0;
|
idx2offset[i] = 0;
|
||||||
continue;
|
continue;
|
||||||
@ -509,11 +505,10 @@ test "test corpus" {
|
|||||||
try testing.expectEqual(corpus.name2group.get("404"), null);
|
try testing.expectEqual(corpus.name2group.get("404"), null);
|
||||||
try testing.expectEqual(corpus.name2group.get("vidmantas").?, g_vidmantas);
|
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[0], name_name);
|
||||||
try testing.expectEqual(membersOfAll[1], svc_bar);
|
try testing.expectEqual(membersOfAll[1], svc_bar);
|
||||||
try testing.expectEqual(membersOfAll[2], vidmantas);
|
try testing.expectEqual(membersOfAll[2], vidmantas);
|
||||||
try testing.expectEqual(corpus.groupname2users.get("404"), null);
|
|
||||||
|
|
||||||
const groupsOfVidmantas = corpus.username2groups.get("vidmantas").?;
|
const groupsOfVidmantas = corpus.username2groups.get("vidmantas").?;
|
||||||
try testing.expectEqual(groupsOfVidmantas[0], g_service_account);
|
try testing.expectEqual(groupsOfVidmantas[0], g_service_account);
|
||||||
|
Loading…
Reference in New Issue
Block a user