shorten cmph pack by 4 bytes
This commit is contained in:
parent
3498167108
commit
c0afca00b0
@ -6,7 +6,7 @@ const c = @cImport({
|
||||
});
|
||||
|
||||
pub fn search_packed(packed_mphf: []const u8, key: []const u8) error{Overflow}!u32 {
|
||||
const bdz_start = @intToPtr(?*anyopaque, @ptrToInt(&packed_mphf[4]));
|
||||
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));
|
||||
}
|
||||
|
@ -6,8 +6,9 @@ const c = @cImport({
|
||||
@cInclude("cmph.h");
|
||||
});
|
||||
|
||||
// pack packs cmph hashes for the given input and returns a slice ("cmph
|
||||
// userdata") for further storage. The slice must be freed by the caller.
|
||||
// pack packs cmph hashes for the given input and returns a slice ("cmph pack
|
||||
// minus first 4 bytes") for further storage. The slice must be freed by the
|
||||
// caller.
|
||||
const packErr = Allocator.Error || error{Overflow};
|
||||
pub fn pack(allocator: Allocator, input: [][*:0]const u8) packErr![]const u8 {
|
||||
var cvector = @ptrCast([*c][*c]u8, input.ptr);
|
||||
@ -24,7 +25,7 @@ pub fn pack(allocator: Allocator, input: [][*:0]const u8) packErr![]const u8 {
|
||||
var buf = try allocator.alloc(u8, size);
|
||||
c.cmph_pack(hash, &buf[0]);
|
||||
c.cmph_destroy(hash);
|
||||
return buf;
|
||||
return buf[4..];
|
||||
}
|
||||
|
||||
const testing = std.testing;
|
||||
|
Loading…
Reference in New Issue
Block a user