Luukdegram/ctradix
Comptime radix tree in Zig
{ "createdAt": "2020-10-06T19:18:27Z", "defaultBranch": "master", "description": "Comptime radix tree in Zig", "fullName": "Luukdegram/ctradix", "homepage": "", "language": "Zig", "name": "ctradix", "pushedAt": "2021-10-19T08:24:16Z", "stargazersCount": 22, "topics": [ "compiletime", "comptime", "radix", "radix-tree", "zig", "ziglang" ], "updatedAt": "2025-01-22T19:13:34Z", "url": "https://github.com/Luukdegram/ctradix"}ctradix
Section titled “ctradix”Comptime radix trie implemented in Zig. This library was experimental to see how feasible it is to implement a comptime radix trie where all data is known at compile time. The main use case for this library is to be used within apple_pie for routing support.
The implementation is based on Hashicorp’s implementation.
For a fast, adaptive radix tree implementation in Zig I’d recommend art.zig.
Example
Section titled “Example”comptime var radix = RadixTree(u32){};comptime _ = radix.insert("foo", 1);comptime _ = radix.insert("bar", 2);
const foo = radix.get("foo");const bar = radix.getLongestPrefix("barfoo");
std.log.info("{}", .{foo}); //1std.log.info("{}", .{bar}); //2Benchmarks
Section titled “Benchmarks”To run the benchmarks, run zig build bench. Note that the benchmark is always ran as ReleaseFast.
edit build.zig if you want to enable other build modes as well.
Searches for 300 words, 50.000 times for 3 instances
StringHashMap 0177ms 0175ms 0175msStringArrayHashMap 0228ms 0241ms 0241msRadixTree 0393ms 0389ms 0392ms