mirror of
https://github.com/versity/scoutfs.git
synced 2026-02-13 05:51:07 +00:00
Use little helpers to insert items into new single block btrees for mkfs. We're about to insert a whole bunch more items. Signed-off-by: Zach Brown <zab@versity.com>
49 lines
1015 B
C
49 lines
1015 B
C
#include "sparse.h"
|
|
#include "util.h"
|
|
#include "format.h"
|
|
#include "avl.h"
|
|
|
|
static struct scoutfs_avl_node *node_ptr(struct scoutfs_avl_root *root,
|
|
|
|
__le16 off)
|
|
{
|
|
return off ? (void *)root + le16_to_cpu(off) : NULL;
|
|
}
|
|
|
|
__le16 avl_node_off(struct scoutfs_avl_root *root,
|
|
struct scoutfs_avl_node *node)
|
|
{
|
|
if (!node)
|
|
return 0;
|
|
return cpu_to_le16((void *)node - (void *)root);
|
|
}
|
|
|
|
struct scoutfs_avl_node *avl_first(struct scoutfs_avl_root *root)
|
|
{
|
|
struct scoutfs_avl_node *node = node_ptr(root, root->node);
|
|
|
|
while (node && node->left)
|
|
node = node_ptr(root, node->left);
|
|
|
|
return node;
|
|
}
|
|
|
|
struct scoutfs_avl_node *avl_next(struct scoutfs_avl_root *root,
|
|
struct scoutfs_avl_node *node)
|
|
{
|
|
struct scoutfs_avl_node *parent;
|
|
|
|
if (node->right) {
|
|
node = node_ptr(root, node->right);
|
|
while (node->left)
|
|
node = node_ptr(root, node->left);
|
|
return node;
|
|
}
|
|
|
|
while ((parent = node_ptr(root, node->parent)) &&
|
|
node == node_ptr(root, parent->right))
|
|
node = parent;
|
|
|
|
return parent;
|
|
}
|