Actually load dictionary entries

This commit is contained in:
2026-06-10 02:12:44 -06:00
parent f041cec3bc
commit 3af3fb59dc

View File

@@ -33,6 +33,27 @@ fn loadDict() []const Wordle.Word {
// allocate all words // allocate all words
const dictionary = std.heap.smp_allocator.alloc(Wordle.Word, num) catch unreachable; const dictionary = std.heap.smp_allocator.alloc(Wordle.Word, num) catch unreachable;
// iterate over all lines
var lines = std.mem.splitSequence(u8, src, "\n");
var idx: usize = 0;
while (lines.next()) |line| {
// skip empty line at end
if (line.len == 0) {
continue;
}
// assert line is correct length
if (line.len != Wordle.WordLen) {
std.debug.panic("length of '{s}' mismatches {d} characters", .{ line, Wordle.WordLen });
}
// copy line bytes over
@memcpy(&dictionary[idx], line);
// increment dictionary entry
idx += 1;
}
// return complete dictionary // return complete dictionary
return dictionary; return dictionary;
} }
@@ -72,7 +93,7 @@ fn expectNotDictionary(word: Wordle.WordLiteral) !void {
} }
test "in dictionary" { test "in dictionary" {
try expectDictionary("alone"); try expectDictionary("abash");
} }
test "not in dictionary" { test "not in dictionary" {