MTBL_ITER(3)
π MTBL_ITER π
okay bestie, welcome to the mtbl_iter(3) page β this is the whole entire manual for iterating over a sequence of key-value pairs, and yes it's short, but it's iconic, so let's get into it π¦
β¨ NAME β¨
mtbl_iter β iterate over a sequence of key-value pairs
lowkey that's the whole vibe. you got a bunch of key-value pairs, you wanna walk through them one by one, mtbl_iter is the girl for the job π
β¨ SYNOPSIS β¨
first things first, you gotta pull in the header:
#include <mtbl.h>
then here's your three function signatures, no cap:
mtbl_res
mtbl_iter_next(struct mtbl_iter *it,
const uint8_t **key, size_t *len_key,
const uint8_t **val, size_t *len_val);
void
mtbl_iter_destroy(struct mtbl_iter **it);
mtbl_res
mtbl_iter_seek(struct mtbl_iter *it,
const uint8_t *key, size_t len_key);
β¨ DESCRIPTION β¨
so the mtbl_iter interface is literally just here to hand you back a sequence of one or more key-value pairs. that's the assignment. that's the job. π
once you've got yourself an mtbl_iter object, the way that you use it is: you call mtbl_iter_next() over and over and over again, bestie, until there are absolutely no more key-value entries left to retrieve. and the moment you hit that point β when it's all done, when the well is dry β you must free the iterator object by calling mtbl_iter_destroy(). not optional. free your girl, she's done her service π«Ά
and here's the cute part: mtbl_iter_seek() can be called on the iterator to seek to a different location in the index, and you can do this without having to destroy the iterator and build a whole new one from scratch. no wasteful breakups and makeups. you just seek. slay π
β¨
β¨ RETURN VALUE β¨
okay so mtbl_iter_next() returns mtbl_res_success when a key-value entry was successfully retrieved β and when that happens, key and val will point to buffers of length len_key and len_val respectively. so good. so clean. πΈ
and then the value mtbl_res_failure gets returned in two situations, and you need to know both of them:
- there are no more entries to read π
- the
itargument isNULLπ
that's it. that's the whole return contract. iykyk.
β¨ SEE ALSO β¨
go read that one too, bestie, it's giving related π
and that's the page!! written under the MTBL_ITER(3) name, dated 03/29/2019 β mwah, a classic, a time capsule, we love her πβ¨ bye pookie, go iterate responsibly π¦
π¦ where this page comes from
- debian bookworm: libmtbl-dev 1.3.0-1 Β· Apache-2.0
- debian trixie: libmtbl-dev 1.6.1-1+b1 Β· Apache-2.0
- ubuntu jammy: libmtbl-dev 1.3.0-1 Β· Apache-2.0
- ubuntu noble: libmtbl-dev 1.3.0-1 Β· Apache-2.0
- ubuntu questing: libmtbl-dev 1.6.1-1
- ubuntu resolute: libmtbl-dev 1.6.1-1build1 Β· Apache-2.0
- ubuntu stonking: libmtbl-dev 1.6.1-1build1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms