dnsjit.lib.trie(3)
π dnsjit.lib.trie(3) π
okay bestie, sit down, hydrate, because we're talking about dnsjit.lib.trie β it's a lib function, it lives in the Library Functions Manual, and it's genuinely one of the cutest little data structures out there. no cap.
β¨ NAME β¨
dnsjit.lib.trie β a prefix-tree data structure that addresses values by strings or byte arrays. it's giving "lookup but make it a tree" π³
πΈ SYNOPSIS πΈ
π Binary-key trie with integer values π
local trie = require("dnsjit.lib.trie").new("uint64_t", true, 4)
-- assume we have a bunch of dnsjit.core.object.ip packets to process
for _, pkt in pairs(pkts) do
local node = trie:get_ins(pkt.src)
local value = node:get() -- new nodes' values are initialized to 0
node:set(value + 1)
end
-- iterate over unique IPs and print number of packets received from each
local iter = trie:iter()
local node = iter:node()
local p = require("dnsjit.lib.ip")
while node ~= nil do
local ip_bytes = node:key()
local npkts = tonumber(node:get())
print(ip.tostring(ip_bytes).." sent "..npkts.." packets")
iter:next()
node = iter:node()
end
π¦ String-key trie with cdata values π¦
local trie = require("dnsjit.lib.trie").new("core_object_t*")
local obj1 -- assume this contains cdata of type core_object_t*
local node = trie:get_ins("obj1")
node:set(obj1)
node = trie:get_try("obj1")
assert(node:get() == obj1)
π DESCRIPTION π
so basically: this is a prefix-tree data structure that stores values indexed by strings or byte arrays, like IP addresses, for example. it's the main character of key-value storage, fr fr.
here's the tea tho β values of size up to sizeof(size_t) can be stored directly. anything bigger than that and you gotta use a pointer instead. no shortcuts, bestie. π
π Functions π
Trie.new(ctype, binary, keylen)β creates a shiny new Trie that storesctypevalues as data. by default, keys are handled as strings (yes queen, strings). want byte arrays instead? set binary totrue. optionally you can pass keylen as a default keylen for binary keys β but for string keys, their string length is used by default. iconic behavior honestly.Trie:log()β returns the Log object so you can control logging for this instance or module. lowkey essential for debugging your life.Trie:clear()β clears the trie instance, aka makes it empty. we love a clean slate β¨Trie:weight()β returns the number of keys in the trie. it's the trie's vibe check, its total count, its whole deal.Trie:get_try(key, keylen)β searches the trie and returnsnilon failure. no drama, justnil. πTrie:get_ins(key, keylen)β searches the trie and, if it fails, inserts an empty node (with value set to0). it's the "if it's not there, we're making it there" energy. π«ΆTrie:get_first()β returns the first node (minimum). smallest key first, always. βTrie:iter()β returns a trie iterator. heads up bestie: it is only valid as long as the key-set remains unchanged. touch the keys and that iterator is gone, periodt.
π SEE ALSO π
dnsjit.lib.trie.node(3), dnsjit.lib.trie.iter(3) β go read these next, they're the supporting cast and they ate π
πΈ AUTHORS and CONTRIBUTORS πΈ
the legends behind this:
- Jerry LundstrΓΆm (DNS-OARC)
- TomΓ‘Ε‘ KΕΓΕΎek (CZ.NIC)
- Petr Ε paΔek (ISC)
maintained by DNS-OARC π
π BUGS π
got issues? got feature requests? don't suffer in silence, bestie:
https://codeberg.org/DNS-OARC/dnsjit/issues
questions or need help? they're literally right there:
admin@dns-oarc.net
no gatekeeping, no being mean, just send the message. π
and that's the whole page, angel π this was dnsjit version 1.5.1, sitting pretty as dnsjit.lib.trie(3). now go forth and index your byte arrays, you absolute icon π§β¨
π¦ where this page comes from
- epel 10: dnsjit 1.5.1-2.el10_2 Β· GPL-3.0-or-later
- epel 9: dnsjit 1.5.1-2.el9 Β· GPL-3.0-or-later
- fedora 43: dnsjit 1.5.1-2.fc43 Β· GPL-3.0-or-later
- fedora 43: dnsjit 1.5.1-2.fc43 Β· GPL-3.0-or-later
- fedora 44: dnsjit 1.5.1-2.fc44 Β· GPL-3.0-or-later
- fedora 44: dnsjit 1.5.1-2.fc44 Β· GPL-3.0-or-later
- ubuntu resolute: dnsjit 1.5.1-2 Β· GPL-3.0-or-later
- ubuntu stonking: dnsjit-dev 1.5.1-6 Β· GPL-3.0-or-later
- Copyright (c) 2018-2026 OARC, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms