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 said mtree_verify() right there in the RETURN VALUE section of a mtree_diff_subtree page. 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