F2AZDZWZABPDWUH4TPLK4N5NMSRYKFDKP3GURGUVNYH4R6W2JSCAC
std.debug.print("time: {d}us\n", .{t.read() / 1_000});
test "Grid isize" {
var d = try Grid(isize, 100, 100).ParseGridFromCSV("grid-test.txt", ",");
const ret = try d.dijkstra(std.testing.allocator, .{ 0, 0 }, .{ 99, 99 });
try std.testing.expectEqual(@as(isize, 366), ret);
}
try std.testing.expectEqual(@as(usize, 366), ret);
test "Grid float" {
var d = try Grid(f64, 100, 100).ParseGridFromCSV("grid-test.txt", ",");
const ret = try d.dijkstra(std.testing.allocator, .{ 0, 0 }, .{ 99, 99 });
try std.testing.expectEqual(@as(f64, 366), ret);
// TODO: use proper parse function for each type
ret[row][col] = try std.fmt.parseUnsigned(T, item, 0);
switch (@typeInfo(T)) {
.Int => |item_type| {
if (item_type.signedness == .unsigned) {
ret[row][col] = try std.fmt.parseUnsigned(T, item, 0);
} else {
ret[row][col] = try std.fmt.parseInt(T, item, 0);
}
},
.Float => ret[row][col] = try std.fmt.parseFloat(T, item),
else => @compileError("unsupported type: " ++ @typeName(T)),
}
pub fn dijkstra(self: @This(), allocator: std.mem.Allocator, start: [2]usize, end: [2]usize) !usize {
var CostGrid = [_][GRID_COLS]usize{[_]usize{~@as(usize, 0)} ** GRID_COLS} ** GRID_ROWS;
pub fn dijkstra(self: @This(), allocator: std.mem.Allocator, start: [2]usize, end: [2]usize) !T {
var CostGrid = switch (@typeInfo(T)) {
.Int => [_][GRID_COLS]T{[_]T{std.math.maxInt(T)} ** GRID_COLS} ** GRID_ROWS,
.Float => [_][GRID_COLS]T{[_]T{std.math.floatMax(T)} ** GRID_COLS} ** GRID_ROWS,
else => @compileError("unsupported type: " ++ @typeName(T)),
};