29 struct Hash_Tree_node *parent,
35 node->parent = parent;
39 node->request_size = request_size;
40 node->request_entry = malloc( request_size );
42 if(!node->request_entry)
48 memcpy( node->request_entry, request, request_size );
50 node->request_entry_key =
MALP_Trace_crc64((
char*)node->request_entry, request_size);
52 node->payload = malloc( payload_size );
60 memcpy( node->payload, payload, payload_size );
68 free(node->request_entry);
71 memset(node, 0,
sizeof(
struct Hash_Tree_node ) );
81 struct Hash_Tree_node *child)
93 struct Hash_Tree_node *node = (
struct Hash_Tree_node *)elem;
95 if( key == node->request_entry_key )
99 if( !memcmp( arg, node->request_entry, node->request_size ) )
118 void Hash_Tree_init(
struct Hash_Tree *htr,
size_t request_size,
size_t payload_size )
121 4142, HASH_TREE_NODE_COLL_AVOID );
125 htr->payload_size = payload_size;
126 htr->request_size = request_size;
135 void (*free_func)(
void *) = (
void (*)(
void *))pfree_func;
149 memset( htr, 0,
sizeof(
struct Hash_Tree) );
164 struct Hash_Tree_node *
Hash_Tree_push(
struct Hash_Tree *htr,
void *parent_request,
void *new_request,
void *payload )
167 struct Hash_Tree_node *parent = NULL;
168 struct Hash_Tree_node *elem = NULL;
185 if( elem->parent != parent )
187 printf(
"Warning changing element parent in Hash_Tree\n");
188 elem->parent = parent;
191 memcpy(elem->payload, payload, htr->payload_size);
196 struct Hash_Tree_node node;
200 Hash_Tree_node_init(&node, parent, new_request, htr->request_size, payload, htr->payload_size );
202 elem = (
struct Hash_Tree_node * )
Hash_Table_push( &htr->nodes, &node , key );
217 struct Hash_Tree_node *node = (
struct Hash_Tree_node *)p_node;
218 void (*handler)(
void *,
void *) = (
void (*)(
void *,
void *)) phandler;
222 (handler)(Hash_Tree_node_payload(node), extra_arg);
237 (handler)(Hash_Tree_node_payload(node), extra_arg);
239 int child_count = Hash_Tree_node_get_child_count( node );
243 for( i = 0 ; i < child_count ; i++ )
245 struct Hash_Tree_node *child = Hash_Tree_node_get_nth_child( node, i );
252 void Hash_Tree_walk(
struct Hash_Tree *htr,
void *starting_point_request,
void (*handler)(
void *,
void *),
void *extra_arg)
258 if( starting_point_request == NULL )
264 struct Hash_Tree_node *starting_node =
Hash_Tree_get_elem( htr, starting_point_request);
struct Hash_Tree_node * Hash_Tree_get_elem(struct Hash_Tree *htr, void *request)
static uint64_t MALP_Trace_crc64(char *source, uint64_t size)
Computes the hash of a given data.
static void Hash_Table_use_lock(struct Hash_Table *ht)
Indicates that the hashtable must use a lock for operations (get/push)
void Hash_Tree_node_release(struct Hash_Tree_node *node)
void Hash_Tree_init(struct Hash_Tree *htr, size_t request_size, size_t payload_size)
void _Hash_Tree_walk_all_nodes_call_handler(void *p_node, void *phandler, void *extra_arg)
void Hash_Tree_node_init(struct Hash_Tree_node *node, struct Hash_Tree_node *parent, void *request, size_t request_size, void *payload, size_t payload_size)
void * Hash_Table_push(struct Hash_Table *ht, void *payload, uint64_t key)
adds an element to a hashtable
static void Chained_List_init(struct Chained_List *list, uint64_t chunk_size, size_t payload_size)
Initializes a Chained_List.
struct Hash_Tree_node * Hash_Tree_push(struct Hash_Tree *htr, void *parent_request, void *new_request, void *payload)
#define PERROR(string)
PERROR macro.
int MALP_Spinlock_unlock(MALP_Spinlock *mutex)
Unlocks the given MALP_Spinlock.
void __Hash_Tree_node_release(void *node)
static void * Chained_List_push(struct Chained_List *list, void *payload)
Adds an element to the list.
void Hash_Tree_node_push_child(struct Hash_Tree_node *node, struct Hash_Tree_node *child)
void Hash_Table_init(struct Hash_Table *ht, size_t sizeof_payload, uint64_t table_size, uint8_t coll_avoid)
Hash_Table initialization.
void Hash_Table_walkthrought_2p(struct Hash_Table *ht, void *second_arg, void(*action)(void *, void *))
Executes a function on every stored elements.
void * Hash_Table_get(struct Hash_Table *ht, uint64_t key, void *extra_arg, int(*test_func)(void *, uint64_t, void *))
retrieves an element from the hashtable
void Hash_Tree_call_free(void *elem, void *pfree_func)
void Hash_Table_release(struct Hash_Table *ht, void(*free_f)(void *))
Hash_Table release.
int MALP_Spinlock_lock(MALP_Spinlock *mutex)
Locks the given MALP_Spinlock.
void _Hash_Tree_walk_topological(struct Hash_Tree *htr, struct Hash_Tree_node *node, void(*handler)(void *, void *), void *extra_arg)
static void Chained_List_release(struct Chained_List *list)
Clears a Chained_List.
int Hash_Tree_test_func(void *elem, uint64_t key, void *arg)
int Hash_Tree_elem_exits(struct Hash_Tree *htr, void *request)
void Hash_Tree_walk(struct Hash_Tree *htr, void *starting_point_request, void(*handler)(void *, void *), void *extra_arg)
void Hash_Table_walkthrought_3p(struct Hash_Table *ht, void *second_arg, void *third_arg, void(*action)(void *, void *, void *))
Executes a function on every stored elements.
void _Hash_Tree_walk_all_nodes(struct Hash_Tree *htr, void(*handler)(void *, void *), void *extra_arg)
void Hash_Tree_release(struct Hash_Tree *htr, void(*free_func)(void *))