pack differently

This commit is contained in:
2022-07-04 07:44:20 +03:00
parent 1fac779f5f
commit 752b0bac6f
3 changed files with 10 additions and 3 deletions

View File

@@ -4,13 +4,13 @@ extern fn bdz_search_packed(packed_mphf: [*]const u8, key: [*]const u8, len: c_u
pub fn search(packed_mphf: []const u8, key: []const u8) u32 {
const len = std.math.cast(c_uint, key.len).?;
return @as(u32, bdz_search_packed(packed_mphf.ptr, key.ptr, len));
return @as(u32, bdz_search_packed(packed_mphf[4..].ptr, key.ptr, len));
}
const u32len = 5;
pub fn search_u32(packed_mphf: []const u8, key: u32) u32 {
return @as(u32, bdz_search_packed(packed_mphf.ptr, &unzero(key), u32len));
return @as(u32, bdz_search_packed(packed_mphf[4..].ptr, &unzero(key), u32len));
}
// encode a u32 to 5 bytes so no bytes is a '\0'.

View File

@@ -39,7 +39,7 @@ pub fn pack(allocator: Allocator, input: [][*:0]const u8) error{OutOfMemory}![]c
errdefer allocator.free(buf);
cmph_pack(mph, buf.ptr);
cmph_destroy(mph);
return buf[4..];
return buf;
}
// perfect-hash a list of numbers and return the packed mphf