libclod
C library for interacting with NBTs, region files, LOD data and other things.
Loading...
Searching...
No Matches
tree.h File Reference
#include <clod/lib.h>
#include "clod/memory.h"

Go to the source code of this file.

Classes

struct  clod_tree
struct  clod_tree_location

Functions

bool clod_tree_create (struct clod_tree *tree)
void clod_tree_destroy (struct clod_tree *tree)
bool clod_tree_add (const struct clod_tree *tree, const void *key, const void *val, void *key_out, void *val_out)
bool clod_tree_get (const struct clod_tree *tree, const void *key, void *key_out, void *val_out)
bool clod_tree_del (const struct clod_tree *tree, const void *key, void *key_out, void *val_out)
bool clod_tree_find (struct clod_tree *tree, struct clod_tree_location *location, const void *key)
bool clod_tree_next (struct clod_tree *tree, struct clod_tree_location *location)
bool clod_tree_prev (struct clod_tree *tree, struct clod_tree_location *location)

Function Documentation

◆ clod_tree_create()

bool clod_tree_create ( struct clod_tree * tree)

Initialise a tree.

Parameters
[in]TreeTree to initialise.
Returns
True on success, false if parameters failed validation.

Definition at line 521 of file tree.c.

◆ clod_tree_destroy()

void clod_tree_destroy ( struct clod_tree * tree)

Destroy a tree. All nodes are freed.

Parameters
[in]TreeTree to destroy.

Definition at line 559 of file tree.c.

◆ clod_tree_add()

bool clod_tree_add ( const struct clod_tree * tree,
const void * key,
const void * val,
void * key_out,
void * val_out )

Add a key/value pair to the tree. If the key compares equal to an existing key, the operation fails, optionally returning the existing key and value.

Parameters
[in]TreeTree to add the key/value pair to.
[in]keyPointer to a key of the configured size.
[in]valPointer to a value of the configured size.
[out]key_out(nullable) Where the existing key is written to if the key already exists.
[out]val_out(nullable) Where the existing value is written to if the key already exists.
Returns
True on success. False otherwise.

Definition at line 586 of file tree.c.

◆ clod_tree_get()

bool clod_tree_get ( const struct clod_tree * tree,
const void * key,
void * key_out,
void * val_out )

Get a key/value pair from the tree.

Parameters
[in]TreeTree to get the key/value from.
[in]keyPointer to a key of the configured size.
[out]key_out(nullable) Where the existing key is written to if the key already exists.
[out]val_out(nullable) Where the existing value is written to if the key already exists.
Returns
True if the given key was found. False otherwise.

Definition at line 718 of file tree.c.

◆ clod_tree_del()

bool clod_tree_del ( const struct clod_tree * tree,
const void * key,
void * key_out,
void * val_out )

Remove a key/value pair from the tree.

Parameters
[in]TreeTree to remove the key/value pair from.
[in]keyPointer to a key of the configured size.
[out]key_out(nullable) Where the existing key is written to if the key already exists.
[out]val_out(nullable) Where the existing value is written to if the key already exists.
Returns
True if the given key was successfully found and removed. False otherwise.

Definition at line 734 of file tree.c.

◆ clod_tree_find()

bool clod_tree_find ( struct clod_tree * tree,
struct clod_tree_location * location,
const void * key )

Find the element equal to, or the next lower element from, the provided key. If an exact match is found, the method returns true.

Parameters
[in]TreeTree to search in.
[out]locationLocation of the search result.
[in]keyPointer to a key of the configured size.
Returns
True if an exact match was found. False otherwise.

◆ clod_tree_next()

bool clod_tree_next ( struct clod_tree * tree,
struct clod_tree_location * location )

Get the next element in the tree.

Parameters
[in]TreeTree to get next element in.
[in,out]locationLocation of the current element. If the location is not initialised (null node member), the first element in the tree is returned.
Returns
True if the next element existed. False otherwise.

◆ clod_tree_prev()

bool clod_tree_prev ( struct clod_tree * tree,
struct clod_tree_location * location )

Get the previous element in the tree.

Parameters
[in]TreeTree to get the previous element from.
[in,out]locationLocation of the current element. If the location is not initialised (null node member), the last element in the tree is returned.
Returns
True if the next element existed. False otherwise.