#ifndef UCX_AVL_H
#define UCX_AVL_H
#include "ucx.h"
#include "allocator.h"
#include <inttypes.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct UcxAVLNode UcxAVLNode;
struct UcxAVLNode {
intptr_t key;
void *value;
size_t height;
UcxAVLNode *parent;
UcxAVLNode *left;
UcxAVLNode *right;
};
typedef struct {
UcxAllocator *allocator;
UcxAVLNode *root;
cmp_func cmpfunc;
void *userdata;
} UcxAVLTree;
UcxAVLTree *ucx_avl_new(cmp_func cmpfunc);
UcxAVLTree *ucx_avl_new_a(cmp_func cmpfunc, UcxAllocator *allocator);
void ucx_avl_free(UcxAVLTree *tree);
#define ucx_avl_default_new() ucx_avl_new_a(ucx_ptrcmp, ucx_default_allocator())
UcxAVLNode *ucx_avl_get_node(UcxAVLTree *tree,
intptr_t key);
void *ucx_avl_get(UcxAVLTree *tree,
intptr_t key);
int ucx_avl_put(UcxAVLTree *tree,
intptr_t key,
void *value);
int ucx_avl_put_s(UcxAVLTree *tree,
intptr_t key,
void *value,
void **oldvalue);
int ucx_avl_remove_node(UcxAVLTree *tree, UcxAVLNode *node);
int ucx_avl_remove(UcxAVLTree *tree,
intptr_t key);
int ucx_avl_remove_s(UcxAVLTree *tree,
intptr_t key,
intptr_t *oldkey,
void **oldvalue);
size_t ucx_avl_count(UcxAVLTree *tree);
#ifdef __cplusplus
}
#endif
#endif