Skip to content

Commit 529a092

Browse files
committed
fix delimiter inside trie.zig
1 parent 2bef04f commit 529a092

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

src/trie.zig

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,36 @@ pub const delimiter: u8 = nodeobj.delimiter;
88
const nodeobj = @import("node.zig");
99
const fmtcvt = @import("fmtcvt.zig");
1010

11+
const toml = @import("toml");
12+
13+
// const DottedIdentifier = std.TailQueue([]const u8);
14+
15+
const Address = struct {
16+
port: i64,
17+
host: []const u8,
18+
};
19+
20+
const Config = struct {
21+
master: bool,
22+
expires_at: toml.DateTime,
23+
description: []const u8,
24+
25+
local: *Address,
26+
peers: []const Address,
27+
};
28+
29+
fn loadTOML(allocator: Allocator, file: []const u8) !void {
30+
var parser = toml.Parser(Config).init(allocator);
31+
defer parser.deinit();
32+
33+
var result = try parser.parseFile(file);
34+
defer result.deinit();
35+
36+
const config = result.value;
37+
std.debug.print("{s}\nlocal address: {s}:{}\n", .{ config.description, config.local.host, config.local.port });
38+
std.debug.print("peer0: {s}:{}\n", .{ config.peers[0].host, config.peers[0].port });
39+
}
40+
1141
pub fn Trie(comptime T: type) type {
1242
return struct {
1343
prefix: []const u8,
@@ -19,7 +49,6 @@ pub fn Trie(comptime T: type) type {
1949
alloc: std.heap.ArenaAllocator,
2050
allocSave: std.mem.Allocator,
2151
const Self = @This();
22-
pub const delimiter: u8 = '.';
2352
pub fn init(alloc: std.mem.Allocator, prefix: []const u8) !Self {
2453
var v = Self{
2554
.alloc = std.heap.ArenaAllocator.init(alloc),
@@ -148,7 +177,7 @@ pub fn Trie(comptime T: type) type {
148177
pos += 1;
149178
}
150179
if (pos > 0) {
151-
buffer[pos] = delimiter;
180+
buffer[pos] = nodeobj.delimiter;
152181
pos += 1;
153182
}
154183
i = 0;
@@ -262,7 +291,7 @@ pub fn Trie(comptime T: type) type {
262291
if (!ret.partialMatched) {
263292
if (node.isBranch()) {
264293
// branch = true;
265-
if (!node.endsWith(delimiter)) {
294+
if (!node.endsWith(nodeobj.delimiter)) {
266295
return Error.PartialMatched;
267296
}
268297
return Error.BranchNodeFound;
@@ -298,7 +327,7 @@ pub fn Trie(comptime T: type) type {
298327
///
299328
/// fn walkOnTTree(key: []const u8, val: ?*NodeValue, props: anytype) bool {
300329
/// _ = props.level;
301-
/// const delim = props.trie.delimiter;
330+
/// const delim = delimiter;
302331
/// const alloc = props.trie.alloc.allocator();
303332
/// const node = props.node;
304333
/// if (node.endsWith(delim) and node.isBranch()) {
@@ -498,7 +527,7 @@ test "walker" {
498527

499528
fn walkOnTTree(key: []const u8, val: ?*NodeValue, props: anytype) bool {
500529
_ = props.level;
501-
const delim = delimiter;
530+
const delim = nodeobj.delimiter;
502531
const alloc = props.trie.alloc.allocator();
503532
const node = props.node;
504533
if (node.endsWith(delim) and node.isBranch()) {

0 commit comments

Comments
 (0)