Permalink
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
bee/src/bee_tree.h
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
this fixes more issues that were not be fixed with 5fa8423 adds new flag BEE_TREE_FLAG_COMPARE_DATA_ON_EQUAL_KEY to bee_tree to insert sorted by data if different data generate same keys. if fixes wrong sorting of "d/0" and "a/0" ..
54 lines (37 sloc)
1.32 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef _BEE_BEE_TREE_H | |
#define _BEE_BEE_TREE_H 1 | |
struct bee_tree { | |
struct bee_subtree *root; | |
int flags; | |
void (*free_data)(void *data); | |
void * (*generate_key)(const void *data); | |
void (*free_key)(void *key); | |
int (*compare_key)(void *a, void *b); | |
int (*compare_data)(void *a, void *b); | |
void (*print_key)(void *key); | |
void (*print)(void *key, void *data); | |
}; | |
struct bee_subtree { | |
struct bee_subtree *parent; | |
struct bee_subtree *left; | |
struct bee_subtree *right; | |
unsigned char height; | |
char balance_factor; | |
void *key; | |
void *data; | |
}; | |
#define BEE_TREE_MAX(a,b) (((a) > (b)) ? (a) : (b)) | |
#define BEE_TREE_HEIGHT(t) ((t) ? ((t)->height) : 0) | |
#define BEE_TREE_FLAG_UNIQUE (1<<0) | |
#define BEE_TREE_FLAG_UNIQUE_DATA (1<<1) | |
#define BEE_TREE_FLAG_COMPARE_DATA_ON_EQUAL_KEY (1<<2) | |
struct bee_tree *bee_tree_allocate(void); | |
void bee_tree_free(struct bee_tree *tree); | |
struct bee_subtree *bee_tree_insert(struct bee_tree *tree, void *data); | |
void *bee_tree_search(struct bee_tree *tree, void *key); | |
void *bee_tree_delete(struct bee_tree *tree, void *key); | |
void bee_tree_print(struct bee_tree *tree); | |
void bee_tree_print_plain(struct bee_tree *tree); | |
int bee_tree_set_flags(struct bee_tree *tree, int flags); | |
int bee_tree_unset_flags(struct bee_tree *tree, int flags); | |
#endif |