offsets are u64, indices are u32
This commit is contained in:
parent
fc469acbf9
commit
9aa52e5a69
@ -369,7 +369,7 @@ shellBlob <= 4032 shell data blob (max 63*64 bytes)
|
|||||||
groups ? packed Group entries (8b padding)
|
groups ? packed Group entries (8b padding)
|
||||||
users ? packed User entries (8b padding)
|
users ? packed User entries (8b padding)
|
||||||
groupMembers ? per-group varint memberlist (no padding)
|
groupMembers ? per-group varint memberlist (no padding)
|
||||||
userGids ? per-user varint gidlist (8b padding)
|
userGids ? per-user varint gidlist (no padding)
|
||||||
```
|
```
|
||||||
|
|
||||||
Section creation order:
|
Section creation order:
|
||||||
|
@ -35,10 +35,10 @@ const Corpus = struct {
|
|||||||
usersMulti: MultiArrayList(User),
|
usersMulti: MultiArrayList(User),
|
||||||
groupsMulti: MultiArrayList(Group),
|
groupsMulti: MultiArrayList(Group),
|
||||||
|
|
||||||
name2user: StringHashMap(u64),
|
name2user: StringHashMap(u32),
|
||||||
name2group: StringHashMap(u64),
|
name2group: StringHashMap(u32),
|
||||||
groupname2users: StringHashMap([]u64),
|
groupname2users: StringHashMap([]u32),
|
||||||
username2groups: StringHashMap([]u64),
|
username2groups: StringHashMap([]u32),
|
||||||
|
|
||||||
pub fn init(
|
pub fn init(
|
||||||
baseAllocator: Allocator,
|
baseAllocator: Allocator,
|
||||||
@ -68,33 +68,33 @@ const Corpus = struct {
|
|||||||
for (groups) |group|
|
for (groups) |group|
|
||||||
groupsMulti.appendAssumeCapacity(group);
|
groupsMulti.appendAssumeCapacity(group);
|
||||||
|
|
||||||
var name2user = StringHashMap(u64).init(allocator);
|
var name2user = StringHashMap(u32).init(allocator);
|
||||||
var name2group = StringHashMap(u64).init(allocator);
|
var name2group = StringHashMap(u32).init(allocator);
|
||||||
for (users) |*user, i| {
|
for (users) |*user, i| {
|
||||||
var res1 = try name2user.getOrPut(user.name);
|
var res1 = try name2user.getOrPut(user.name);
|
||||||
if (res1.found_existing)
|
if (res1.found_existing)
|
||||||
return error.Duplicate;
|
return error.Duplicate;
|
||||||
res1.value_ptr.* = i;
|
res1.value_ptr.* = @intCast(u32, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (groups) |*group, i| {
|
for (groups) |*group, i| {
|
||||||
var res1 = try name2group.getOrPut(group.name);
|
var res1 = try name2group.getOrPut(group.name);
|
||||||
if (res1.found_existing)
|
if (res1.found_existing)
|
||||||
return error.Duplicate;
|
return error.Duplicate;
|
||||||
res1.value_ptr.* = i;
|
res1.value_ptr.* = @intCast(u32, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
var groupname2users = StringHashMap([]u64).init(allocator);
|
var groupname2users = StringHashMap([]u32).init(allocator);
|
||||||
|
|
||||||
// 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.
|
||||||
var username2groups = StringHashMap(
|
var username2groups = StringHashMap(
|
||||||
ArrayListUnmanaged(u64),
|
ArrayListUnmanaged(u32),
|
||||||
).init(baseAllocator);
|
).init(baseAllocator);
|
||||||
defer username2groups.deinit();
|
defer username2groups.deinit();
|
||||||
|
|
||||||
for (groups) |*group, i| {
|
for (groups) |*group, i| {
|
||||||
var members = try allocator.alloc(u64, 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();
|
||||||
@ -108,8 +108,8 @@ const Corpus = struct {
|
|||||||
|
|
||||||
var groupsOfMember = try username2groups.getOrPut(memberName.*);
|
var groupsOfMember = try username2groups.getOrPut(memberName.*);
|
||||||
if (!groupsOfMember.found_existing)
|
if (!groupsOfMember.found_existing)
|
||||||
groupsOfMember.value_ptr.* = ArrayListUnmanaged(u64){};
|
groupsOfMember.value_ptr.* = ArrayListUnmanaged(u32){};
|
||||||
try groupsOfMember.value_ptr.*.append(allocator, i);
|
try groupsOfMember.value_ptr.*.append(allocator, @intCast(u32, i));
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = try groupname2users.getOrPut(group.name);
|
var result = try groupname2users.getOrPut(group.name);
|
||||||
@ -120,14 +120,14 @@ const Corpus = struct {
|
|||||||
|
|
||||||
var it1 = groupname2users.valueIterator();
|
var it1 = groupname2users.valueIterator();
|
||||||
while (it1.next()) |groupUsers| {
|
while (it1.next()) |groupUsers| {
|
||||||
sort.sort(u64, groupUsers.*, {}, comptime sort.asc(u64));
|
sort.sort(u32, groupUsers.*, {}, comptime sort.asc(u32));
|
||||||
}
|
}
|
||||||
|
|
||||||
var it2 = username2groups.valueIterator();
|
var it2 = username2groups.valueIterator();
|
||||||
while (it2.next()) |userGroups|
|
while (it2.next()) |userGroups|
|
||||||
sort.sort(u64, userGroups.items, {}, comptime sort.asc(u64));
|
sort.sort(u32, userGroups.items, {}, comptime sort.asc(u32));
|
||||||
|
|
||||||
var username2groups_final = StringHashMap([]u64).init(allocator);
|
var username2groups_final = StringHashMap([]u32).init(allocator);
|
||||||
var it = username2groups.iterator();
|
var it = username2groups.iterator();
|
||||||
while (it.next()) |elem| {
|
while (it.next()) |elem| {
|
||||||
const username = elem.key_ptr.*;
|
const username = elem.key_ptr.*;
|
||||||
|
Loading…
Reference in New Issue
Block a user