less error handling
This commit is contained in:
parent
88d2a0f470
commit
1e084cc3fb
31
src/main.zig
31
src/main.zig
|
@ -14,10 +14,8 @@ pub fn main() !void {}
|
||||||
test "simple cmph usage" {
|
test "simple cmph usage" {
|
||||||
var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
||||||
const arena = arena_instance.allocator();
|
const arena = arena_instance.allocator();
|
||||||
const stdout = std.io.getStdOut().writer();
|
|
||||||
const stderr = std.io.getStdErr().writer();
|
const stderr = std.io.getStdErr().writer();
|
||||||
|
|
||||||
_ = stdout;
|
|
||||||
var vector = std.ArrayList([*:0]const u8).init(arena);
|
var vector = std.ArrayList([*:0]const u8).init(arena);
|
||||||
try vector.appendSlice(&.{
|
try vector.appendSlice(&.{
|
||||||
"aaaaaaaaaa",
|
"aaaaaaaaaa",
|
||||||
|
@ -31,11 +29,10 @@ test "simple cmph usage" {
|
||||||
"iiiiiiiiii",
|
"iiiiiiiiii",
|
||||||
"jjjjjjjjjj",
|
"jjjjjjjjjj",
|
||||||
});
|
});
|
||||||
var vector2 = try vector.clone();
|
|
||||||
var nkeys = @truncate(c_uint, vector.items.len);
|
var nkeys = @truncate(c_uint, vector.items.len);
|
||||||
|
|
||||||
var mphf_fd = c.fopen(tempMph, "w");
|
var mphf_fd = c.fopen(tempMph, "w");
|
||||||
var cvector = @ptrCast([*c][*c]u8, vector.toOwnedSlice().ptr);
|
var cvector = @ptrCast([*c][*c]u8, vector.items.ptr);
|
||||||
var source = c.cmph_io_vector_adapter(cvector, nkeys);
|
var source = c.cmph_io_vector_adapter(cvector, nkeys);
|
||||||
defer c.cmph_io_vector_adapter_destroy(source);
|
defer c.cmph_io_vector_adapter_destroy(source);
|
||||||
var config: *c.cmph_config_t = c.cmph_config_new(source) orelse return error.OutOfMemory;
|
var config: *c.cmph_config_t = c.cmph_config_new(source) orelse return error.OutOfMemory;
|
||||||
|
@ -50,16 +47,11 @@ test "simple cmph usage" {
|
||||||
mphf_fd = c.fopen(tempMph, "r");
|
mphf_fd = c.fopen(tempMph, "r");
|
||||||
defer _ = c.fclose(mphf_fd);
|
defer _ = c.fclose(mphf_fd);
|
||||||
|
|
||||||
var got_hash: ?*c.cmph_t = c.cmph_load(mphf_fd);
|
hash = c.cmph_load(mphf_fd) orelse unreachable;
|
||||||
if (got_hash) |real_hash| {
|
|
||||||
hash = real_hash;
|
|
||||||
} else {
|
|
||||||
try stderr.print("failed to unwrap hash\n", .{});
|
|
||||||
}
|
|
||||||
defer c.cmph_destroy(hash);
|
defer c.cmph_destroy(hash);
|
||||||
|
|
||||||
try stderr.print("\n", .{});
|
try stderr.print("\n", .{});
|
||||||
for (vector2.items) |key| {
|
for (vector.items) |key| {
|
||||||
var id = c.cmph_search(hash, key, @truncate(c_uint, c.strlen(key)));
|
var id = c.cmph_search(hash, key, @truncate(c_uint, c.strlen(key)));
|
||||||
try stderr.print("key: {s}, id: {d}\n", .{ key, id });
|
try stderr.print("key: {s}, id: {d}\n", .{ key, id });
|
||||||
}
|
}
|
||||||
|
@ -71,20 +63,3 @@ fn closeCFile(f: *c.FILE) !void {
|
||||||
return std.os.unexpectedErrno(std.os.errno(close_code));
|
return std.os.unexpectedErrno(std.os.errno(close_code));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const expectEqual = std.testing.expectEqual;
|
|
||||||
|
|
||||||
test "char**" {
|
|
||||||
var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
|
||||||
const arena = arena_instance.allocator();
|
|
||||||
|
|
||||||
var arrl = std.ArrayList([*:0]const u8).init(arena);
|
|
||||||
try arrl.append("foo");
|
|
||||||
try arrl.append("bar");
|
|
||||||
|
|
||||||
var arr: [*][*:0]const u8 = arrl.toOwnedSlice().ptr;
|
|
||||||
|
|
||||||
try expectEqual(@TypeOf(arr[0]), [*:0]const u8);
|
|
||||||
try expectEqual(arr[0][2], 'o');
|
|
||||||
try expectEqual(arr[0][3], 0);
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue