From 9aa52e5a691520a448065cc09a3bea0e00cd5f7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Tue, 8 Mar 2022 20:48:33 +0200 Subject: [PATCH] offsets are u64, indices are u32 --- README.md | 2 +- src/sections.zig | 32 ++++++++++++++++---------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index e3cbb6f..5f9dd5c 100644 --- a/README.md +++ b/README.md @@ -369,7 +369,7 @@ shellBlob <= 4032 shell data blob (max 63*64 bytes) groups ? packed Group entries (8b padding) users ? packed User entries (8b 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: diff --git a/src/sections.zig b/src/sections.zig index 7c62d1f..e315698 100644 --- a/src/sections.zig +++ b/src/sections.zig @@ -35,10 +35,10 @@ const Corpus = struct { usersMulti: MultiArrayList(User), groupsMulti: MultiArrayList(Group), - name2user: StringHashMap(u64), - name2group: StringHashMap(u64), - groupname2users: StringHashMap([]u64), - username2groups: StringHashMap([]u64), + name2user: StringHashMap(u32), + name2group: StringHashMap(u32), + groupname2users: StringHashMap([]u32), + username2groups: StringHashMap([]u32), pub fn init( baseAllocator: Allocator, @@ -68,33 +68,33 @@ const Corpus = struct { for (groups) |group| groupsMulti.appendAssumeCapacity(group); - var name2user = StringHashMap(u64).init(allocator); - var name2group = StringHashMap(u64).init(allocator); + var name2user = StringHashMap(u32).init(allocator); + var name2group = StringHashMap(u32).init(allocator); for (users) |*user, i| { var res1 = try name2user.getOrPut(user.name); if (res1.found_existing) return error.Duplicate; - res1.value_ptr.* = i; + res1.value_ptr.* = @intCast(u32, i); } for (groups) |*group, i| { var res1 = try name2group.getOrPut(group.name); if (res1.found_existing) 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 // returning from this function. This keeps the arena clean. var username2groups = StringHashMap( - ArrayListUnmanaged(u64), + ArrayListUnmanaged(u32), ).init(baseAllocator); defer username2groups.deinit(); 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; var it = group.members.iterator(); @@ -108,8 +108,8 @@ const Corpus = struct { var groupsOfMember = try username2groups.getOrPut(memberName.*); if (!groupsOfMember.found_existing) - groupsOfMember.value_ptr.* = ArrayListUnmanaged(u64){}; - try groupsOfMember.value_ptr.*.append(allocator, i); + groupsOfMember.value_ptr.* = ArrayListUnmanaged(u32){}; + try groupsOfMember.value_ptr.*.append(allocator, @intCast(u32, i)); } var result = try groupname2users.getOrPut(group.name); @@ -120,14 +120,14 @@ const Corpus = struct { var it1 = groupname2users.valueIterator(); while (it1.next()) |groupUsers| { - sort.sort(u64, groupUsers.*, {}, comptime sort.asc(u64)); + sort.sort(u32, groupUsers.*, {}, comptime sort.asc(u32)); } var it2 = username2groups.valueIterator(); 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(); while (it.next()) |elem| { const username = elem.key_ptr.*;