MTREE_DIFF_SUBTREE(3)
π MTREE_DIFF_SUBTREE π
okay bestie, sit down, hydrate, and let me tell you about mtree_diff_subtree from the Librecast Programmer's Manual. this is the diff-your-trees function and it's honestly so useful it's giving main character energy π¦
β¨ NAME β¨
mtree_diff_subtree β compare two subtrees and return bitmap π
π LIBRARY π
Librecast library (liblibrecast, -llibrecast) π
πΈ SYNOPSIS πΈ
#include <librecast/mtree.h>
unsigned char *mtree_diff_subtree(mtree_t *t1, mtree_t *t2, size_t root, unsigned bits);
unsigned char *mtree_diff_map(mtree_t *t1, mtree_t *t2);
Compile and link with -llibrecast. periodt π
π« DESCRIPTION π«
so mtree_diff_subtree does a bredth-first comparison of the merkle trees t1 and t2, and hands you back a pointer to a bitmap, setting bits bits for any chunks that differ. no cap, that's the whole vibe.
bits should be set to the number of packets required to transport each chunk. and when bits > 1, bestie, the chunks get fragmented into multiple packets, and the bitmap will represent the packets required instead. it's giving packet-level detail π₯
if you wanna know how many packets it takes to patch the differences, just check the popcount (Hamming Weight) of the returned bitmap. that's literally the number. iconic.
π«Ά the returned bitmap must be freed by the caller when no longer needed, by passing it to free(3). do NOT ghost your memory, bestie, that's how leaks happen π
mtree_diff_map() is a convenience wrapper β it's the same as calling mtree_diff_subtree() with root set to zero (whole tree) and bits set to one. so it returns a bitmap of the entire tree with a single bit per chunk. one bit per chunk, whole tree, chef's kiss π
π RETURN VALUE π
mtree_verify() returns zero if the tree is valid, or NULL on error, with errno set to indicate the error.
π yes, we saidmtree_verify()right there in the RETURN VALUE section of amtree_diff_subtreepage. that's what the manpage says, so that's what you get. iykyk.
π ERRORS π
ENOMEMβ Not enough space/cannot allocate memory (POSIX.1-2001).
π SEE ALSO π
and that's the whole page, bestie!! π§β¨ brought to you by LIBRECAST, dated 2023-06-20, and yes the manual name is still MTREE_DIFF_SUBTREE(3) in case you forgot π go free your bitmaps, slay, bye π¦πΈ
π¦ where this page comes from
- debian trixie: liblibrecast-dev 0.9.1-1 Β· GPL-2.0-only OR GPL-3.0-only
- nixos 26.05: librecast 0.11.2
- nixpkgs unstable: librecast 0.11.2
- ubuntu noble: liblibrecast-dev 0.8.0-1.1build1 Β· GPL-2.0-only OR GPL-3.0-only
- ubuntu questing: liblibrecast-dev 0.9.1-1
- ubuntu resolute: liblibrecast-dev 0.11.2-2 Β· GPL-2.0-only OR GPL-3.0-only
- ubuntu stonking: liblibrecast-dev 0.11.2-2build1 Β· GPL-2.0-only OR GPL-3.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms