40 lines
1 KiB
C
40 lines
1 KiB
C
#ifndef UTILITIEC_BINARYTREE_H
|
|
#define UTILITIEC_BINARYTREE_H
|
|
|
|
#include "../allocator-interface/allocator-interface.h"
|
|
#include "../dynamicarray/dynamicarray.h"
|
|
|
|
typedef struct BinaryTreeNode_s {
|
|
struct BinaryTreeNode_s* left;
|
|
struct BinaryTreeNode_s* right;
|
|
|
|
size_t depth;
|
|
|
|
char value[];
|
|
} BinaryTreeNode;
|
|
|
|
typedef int (*BinaryTreeComparator) (void* this, void* other, void* xdata);
|
|
|
|
typedef struct BinaryTree_s {
|
|
BinaryTreeNode* root;
|
|
|
|
DynamicArray walker_stack;
|
|
|
|
size_t value_size;
|
|
BinaryTreeComparator compare;
|
|
void* xdata;
|
|
|
|
allocator_t* allocator;
|
|
} BinaryTree;
|
|
|
|
int BinaryTree_Create(BinaryTree* target, BinaryTreeComparator compare, void* xdata, size_t value_size, allocator_t* allocator);
|
|
void BinaryTree_Destroy(BinaryTree* tree);
|
|
|
|
int BinaryTree_Insert(BinaryTree* tree, void* value);
|
|
int BinaryTree_Remove(BinaryTree* tree, void* value);
|
|
|
|
typedef int (*BinaryTreeNodeFunction) (void* context, BinaryTreeNode* node);
|
|
|
|
int BinaryTree_ForEachPostOrder(BinaryTree* tree, BinaryTreeNodeFunction action, void* context);
|
|
|
|
#endif
|