Skip to content

Commit

Permalink
Merge pull request #649 from sanpeqf/docs-skiplist
Browse files Browse the repository at this point in the history
docs skiplist: added api comments
  • Loading branch information
sanpeqf authored Jan 12, 2025
2 parents 8cfc423 + e08933b commit ea4919c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 21 deletions.
51 changes: 40 additions & 11 deletions include/bfdev/skiplist.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,55 @@ struct bfdev_skip_head {
bfdev_list_head_t nodes[0];
};

/**
* bfdev_skiplist_find - find a node in the skiplist.
* @head: the skiplist head to find in.
* @find: the find function for this skiplist.
* @pdata: the private data for @find.
*/
extern bfdev_skip_node_t *
bfdev_skiplist_find(bfdev_skip_head_t *head, bfdev_find_t find, void *pdata);

/**
* bfdev_skiplist_insert - insert a node into the skiplist.
* @head: the skiplist head to insert into.
* @key: the key for this skiplist.
* @cmp: the compare function for this skiplist.
* @pdata: the private data for @cmp.
*/
extern int
bfdev_skiplist_insert(bfdev_skip_head_t *head, void *key, bfdev_cmp_t cmp,
void *pdata);
bfdev_skiplist_insert(bfdev_skip_head_t *head, void *key,
bfdev_cmp_t cmp, void *pdata);

extern void
/**
* bfdev_skiplist_delete - delete a node from the skiplist.
* @head: the skiplist head to delete from.
* @find: the find function for this skiplist.
* @pdata: the private data for @find.
*/
extern int
bfdev_skiplist_delete(bfdev_skip_head_t *head, bfdev_find_t find, void *pdata);

extern bfdev_skip_node_t *
bfdev_skiplist_find(bfdev_skip_head_t *head, bfdev_find_t find, void *pdata);

/**
* bfdev_skiplist_reset - reset all nodes in a skiplist.
* @head: the skiplist head to reset.
* @release: the function to release each node.
* @pdata: the private data for @release.
*/
extern void
bfdev_skiplist_reset(bfdev_skip_head_t *head, bfdev_release_t release,
void *pdata);

bfdev_skiplist_reset(bfdev_skip_head_t *head,
bfdev_release_t release, void *pdata);
/**
* bfdev_skiplist_create - create a skiplist header.
* @alloc: the allocator for this skiplist.
* @levels: the levels for this skiplist.
*/
extern bfdev_skip_head_t *
bfdev_skiplist_create(const bfdev_alloc_t *alloc, unsigned int levels);

extern void
bfdev_skiplist_destroy(bfdev_skip_head_t *head, bfdev_release_t release,
void *pdata);
bfdev_skiplist_destroy(bfdev_skip_head_t *head,
bfdev_release_t release, void *pdata);

/**
* bfdev_skiplist_for_each - iterate over list of given type.
Expand Down
23 changes: 13 additions & 10 deletions src/skiplist.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ skipnode_find(bfdev_skip_head_t *head, bfdev_find_t find,
return NULL;
}

export bfdev_skip_node_t *
bfdev_skiplist_find(bfdev_skip_head_t *head, bfdev_find_t find, void *pdata)
{
bfdev_skip_node_t *node;

node = skipnode_find(head, find, pdata, NULL);

return node;
}

export int
bfdev_skiplist_insert(bfdev_skip_head_t *head, void *key, bfdev_cmp_t cmp,
void *pdata)
Expand Down Expand Up @@ -100,7 +110,7 @@ bfdev_skiplist_insert(bfdev_skip_head_t *head, void *key, bfdev_cmp_t cmp,
return 0;
}

export void
export int
bfdev_skiplist_delete(bfdev_skip_head_t *head, bfdev_find_t find, void *pdata)
{
const bfdev_alloc_t *alloc;
Expand All @@ -110,7 +120,7 @@ bfdev_skiplist_delete(bfdev_skip_head_t *head, bfdev_find_t find, void *pdata)
alloc = head->alloc;
node = skipnode_find(head, find, pdata, &level);
if (bfdev_unlikely(!node))
return;
return -BFDEV_ENOENT;

while (level--) {
bfdev_list_del(&node->list[level]);
Expand All @@ -119,15 +129,8 @@ bfdev_skiplist_delete(bfdev_skip_head_t *head, bfdev_find_t find, void *pdata)
}

bfdev_free(alloc, node);
}

export bfdev_skip_node_t *
bfdev_skiplist_find(bfdev_skip_head_t *head,
bfdev_find_t find, void *pdata)
{
bfdev_skip_node_t *node;
node = skipnode_find(head, find, pdata, NULL);
return node;
return -BFDEV_ENOERR;
}

static void
Expand Down

0 comments on commit ea4919c

Please sign in to comment.