diff options
Diffstat (limited to 'include/lib')
-rw-r--r-- | include/lib/algo/avl_tree.h | 40 | ||||
-rw-r--r-- | include/lib/monad.h | 9 | ||||
-rw-r--r-- | include/lib/seg/mask_data.h | 46 |
3 files changed, 95 insertions, 0 deletions
diff --git a/include/lib/algo/avl_tree.h b/include/lib/algo/avl_tree.h new file mode 100644 index 0000000..80f0c44 --- /dev/null +++ b/include/lib/algo/avl_tree.h @@ -0,0 +1,40 @@ +#ifndef INC_LIB_ALGO_AVL_TREE_H +#define INC_LIB_ALGO_AVL_TREE_H + +#include <lib/bool.h> +#include <stdint.h> +#include <stdlib.h> + +struct AVLNode { + void* data; + bool_t (*compare)(void*, void*); + struct AVLNode* left; + struct AVLNode* right; + uint8_t height; +}; + +// Get the height of an AVL node +uint8_t get_height(struct AVLNode* node); + +// Get the Maximum Height between two +uint8_t max_height(uint8_t a, uint8_t b); + +// Get the balance factor of a node +ssize_t get_balance_factor(struct AVLNode* node); + +// Rotate an AVL node right +struct AVLNode* right_rotate(struct AVLNode* parent); + +// Rotate an AVL node left +struct AVLNode* left_rotate(struct AVLNode* parent); + +// In-order traversal print pointer +void print_in_order(struct AVLNode* root); + +// Free avl tree nodes starting at root +void free_avl_tree(struct AVLNode* root); + +// Free avl tree and their data starting at root +void free_avl_tree_nodes(struct AVLNode* root); + +#endif diff --git a/include/lib/monad.h b/include/lib/monad.h new file mode 100644 index 0000000..4a68e0a --- /dev/null +++ b/include/lib/monad.h @@ -0,0 +1,9 @@ +#ifndef INC_LIB_MONAD_H +#define INC_LIB_MONAD_H + +struct Result { + void* data; + bool_t success; +}; + +#endif diff --git a/include/lib/seg/mask_data.h b/include/lib/seg/mask_data.h new file mode 100644 index 0000000..595ffd6 --- /dev/null +++ b/include/lib/seg/mask_data.h @@ -0,0 +1,46 @@ +#ifndef INC_LIB_SEG_MASK_DATA_H +#define INC_LIB_SEG_MASK_DATA_H + +#include <lib/algo/avl_tree.h> +#include <lib/monad.h> + +struct MaskData { + uint16_t label; + size_t area; + size_t perimeter; +}; + +// Allocate Mask Data for Label +struct MaskData* create_mask_data(uint16_t label); + +// Compare mask data labels +bool_t compare_labels(struct MaskData* left, struct MaskData* right); + +// Create AVL Mask node +struct AVLNode* create_avl_mask_node(struct MaskData* data); + +// Insert MaskData into the AVL Tree +struct Result insert_mask(struct AVLNode* node, struct MaskData* data); + +// Allocate a label's Mask data in a tree +// If it already exists, skip the allocation +struct AVLNode* insert_mask_alloc(struct AVLNode* node, uint16_t label); + +// Print AVL Node Mask Data Label +void print_label(struct AVLNode* root); + +// Increase the label's area +bool_t increase_label_area(struct AVLNode* root, uint16_t label); + +// Increase the label's perimeter +bool_t increase_label_perimeter(struct AVLNode* root, uint16_t label); + +// Increase the label's area +// Create an AVL node if it doesn't exist +struct AVLNode* increase_label_area_alloc(struct AVLNode* root, uint16_t label); + +// Increase the label's perimeter +// Create an AVL node if it doesn't exist +struct AVLNode* increase_label_perimeter_alloc(struct AVLNode* root, uint16_t label); + +#endif |