start packed group

This commit is contained in:
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

@@ -5,7 +5,7 @@ const c = @cImport({
@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 len = try std.math.cast(c_uint, key.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;
inline for (items) |elem| {
const hashed = try bdz.search_packed(buf, elem);
const hashed = try bdz.search(buf, elem);
used[hashed] = true;
}

View File

@@ -1,7 +1,19 @@
const std = @import("std");
const PackedGroup = packed struct {
gid: u32,
members_offset: u27,
groupname_len: u5,
};
const Group = struct {
gid: u32,
name: []const u8,
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;
// asBytes/bytesAsValue use @sizeOf, which is larger. Now we are putting no
// 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 {