#ifndef bci_method_dispatcher_h__ #define bci_method_dispatcher_h__ #include #include "base.h" typedef struct dispatch_tree_node_s { struct dispatch_tree_node_s * higher; struct dispatch_tree_node_s * lower; uint16_t word; bci_core_method_t method; } * dispatch_tree_node_t; typedef struct dispatch_tree_s { dispatch_tree_node_t root; } * dispatch_tree_t; dispatch_tree_t dispatch_tree_t_new(void); /* * This deletes the tree and will invoke dispatch_tree_node_t_del on * tree->root (which will delete all the other nodes recursively). * If you want to keep nodes you have to explicityl remove the reference to * them by setting them to NULL. * */ void dispatch_tree_t_del(dispatch_tree_t tree); dispatch_tree_node_t dispatch_tree_node_t_new(uint16_t word , bci_core_method_t method); /* * This deletes the node an will invoke dispatch_tree_node_t_del on * node->higher and node->lower. If you want to keep those nodes * you have to explicitly clear the reference by setting them to NULL. * */ void dispatch_tree_node_t_del(dispatch_tree_node_t node); /* * Insert a new key-value-pair into the tree. * * Return codes: * 0: OK * 1: out of memory * 2: key already in tree * */ char dispatch_tree_t_insert(dispatch_tree_t tree , uint16_t word , bci_core_method_t method); // TODO: // Figure out if that function is actually useful. // Maybe manually inserting the methods in a good order // is better. // //dispatch_tree_t optimize(dispatch_tree_t tree); bci_core_method_t dispatch_tree_t_dispatch(dispatch_tree_t tree , uint16_t word); #endif