1
Fork 0

start packed group

This commit is contained in:
Motiejus Jakštys 2022-02-24 05:51:04 +02:00 committed by Motiejus Jakštys
parent 3bf1b3fc01
commit b924e3a935
5 changed files with 21 additions and 9 deletions

View File

@ -180,10 +180,10 @@ referred by their byte offset in the `Users` and `Groups` section relative to
the beginning of the section. the beginning of the section.
``` ```
const PackedGroup = struct { const PackedGroup = packed struct {
gid: u32, gid: u32,
// index to a separate structure with a list of members. The memberlist is // index to a separate structure with a list of members. The memberlist is
// always 2^5-byte aligned (32b), this is an index there. // 2^5-byte aligned (32b), this is an index there.
members_offset: u27, members_offset: u27,
groupname_len: u5, groupname_len: u5,
// a groupname_len-sized string // a groupname_len-sized string
@ -347,10 +347,10 @@ Each section is padded to 64 bytes.
``` ```
STATUS SECTION SIZE DESCRIPTION STATUS SECTION SIZE DESCRIPTION
✅ Header 48 see "Turbonss header" section ✅ Header 48 see "Turbonss header" section
bdz_gid ? bdz(gid) bdz_gid ? bdz(gid)
bdz_groupname ? bdz(groupname) bdz_groupname ? bdz(groupname)
bdz_uid ? bdz(uid) bdz_uid ? bdz(uid)
bdz_name ? bdz(username) bdz_name ? bdz(username)
idx_gid2group len(group)*29/8 bdz->offset Groups idx_gid2group len(group)*29/8 bdz->offset Groups
idx_groupname2group len(group)*29/8 bdz->offset Groups idx_groupname2group len(group)*29/8 bdz->offset Groups
idx_uid2user len(user)*29/8 bdz->offset Users idx_uid2user len(user)*29/8 bdz->offset Users

View File

@ -5,7 +5,7 @@ const c = @cImport({
@cInclude("bdz.h"); @cInclude("bdz.h");
}); });
pub fn search_packed(packed_mphf: []const u8, key: []const u8) error{Overflow}!u32 { pub fn search(packed_mphf: []const u8, key: []const u8) error{Overflow}!u32 {
const bdz_start = @intToPtr(?*anyopaque, @ptrToInt(&packed_mphf[0])); const bdz_start = @intToPtr(?*anyopaque, @ptrToInt(&packed_mphf[0]));
const len = try std.math.cast(c_uint, key.len); const len = try std.math.cast(c_uint, key.len);
return @as(u32, c.bdz_search_packed(bdz_start, key.ptr, len)); return @as(u32, c.bdz_search_packed(bdz_start, key.ptr, len));

View File

@ -59,7 +59,7 @@ test "basic pack/unpack" {
var used: [items_len]bool = undefined; var used: [items_len]bool = undefined;
inline for (items) |elem| { inline for (items) |elem| {
const hashed = try bdz.search_packed(buf, elem); const hashed = try bdz.search(buf, elem);
used[hashed] = true; used[hashed] = true;
} }

View File

@ -1,7 +1,19 @@
const std = @import("std"); const std = @import("std");
const PackedGroup = packed struct {
gid: u32,
members_offset: u27,
groupname_len: u5,
};
const Group = struct { const Group = struct {
gid: u32, gid: u32,
name: []const u8, name: []const u8,
members: std.BufSet, members: std.BufSet,
}; };
const testing = std.testing;
test "PackedGroup alignment" {
try testing.expectEqual(@sizeOf(PackedGroup) * 8, @bitSizeOf(PackedGroup));
}

View File

@ -248,7 +248,7 @@ test "PackedUser internal and external alignment" {
// cannot be converted from/to [@bitSizeOf(PackedUser)/8]u8; // cannot be converted from/to [@bitSizeOf(PackedUser)/8]u8;
// asBytes/bytesAsValue use @sizeOf, which is larger. Now we are putting no // asBytes/bytesAsValue use @sizeOf, which is larger. Now we are putting no
// more than 1, but it probably could be higher. // more than 1, but it probably could be higher.
try testing.expect(@bitSizeOf(PackedUser) - @sizeOf(PackedUser) * 8 <= 8); try testing.expect(@sizeOf(PackedUser) * 8 - @bitSizeOf(PackedUser) <= 8);
} }
fn testShellIndex(shell: []const u8) ?u6 { fn testShellIndex(shell: []const u8) ?u6 {