1
0
mirror of https://git.tukaani.org/xz.git synced 2026-10-31 03:14:56 +00:00

liblzma: index.c 3/4: Add index_tree_prev()

This commit is contained in:
Lasse Collin 2026-08-15 19:42:55 +03:00
parent 0543606d15
commit 869f0e85a8
No known key found for this signature in database
GPG Key ID: 38EE757D69184620

View File

@ -348,6 +348,25 @@ index_tree_next(const index_tree_node *node)
}
/// Get the previous node in the tree. Return NULL if there are no more nodes.
static void *
index_tree_prev(const index_tree_node *node)
{
if (node->left != NULL) {
node = node->left;
while (node->right != NULL)
node = node->right;
return (void *)(node);
}
while (node->parent != NULL && node->parent->left == node)
node = node->parent;
return (void *)(node->parent);
}
/// Locate a node that contains the given uncompressed offset. It is
/// caller's job to check that target is not bigger than the uncompressed
/// size of the tree (the last node would be returned in that case still).