Actually load dictionary entries
This commit is contained in:
23
src/dict.zig
23
src/dict.zig
@@ -33,6 +33,27 @@ fn loadDict() []const Wordle.Word {
|
||||
// allocate all words
|
||||
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 dictionary;
|
||||
}
|
||||
@@ -72,7 +93,7 @@ fn expectNotDictionary(word: Wordle.WordLiteral) !void {
|
||||
}
|
||||
|
||||
test "in dictionary" {
|
||||
try expectDictionary("alone");
|
||||
try expectDictionary("abash");
|
||||
}
|
||||
|
||||
test "not in dictionary" {
|
||||
|
||||
Reference in New Issue
Block a user