remove redundant fields
This commit is contained in:
parent
9bf0a35689
commit
d2ace3e125
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue