Multi-ApplicationOnlineProfiling  2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Hash_Tree.h
Go to the documentation of this file.
1 /* ############################ MALP License ############################## */
2 /* # Fri Jan 18 14:00:00 CET 2013 # */
3 /* # Copyright or (C) or Copr. Commissariat a l'Energie Atomique # */
4 /* # # */
5 /* # This software is governed by the CeCILL-C license under French law # */
6 /* # and abiding by the rules of distribution of free software. You can # */
7 /* # use, modify and/ or redistribute the software under the terms of # */
8 /* # the CeCILL-C license as circulated by CEA, CNRS and INRIA at the # */
9 /* # following URL http://www.cecill.info. # */
10 /* # # */
11 /* # The fact that you are presently reading this means that you have # */
12 /* # had knowledge of the CeCILL-C license and that you accept its # */
13 /* # terms. # */
14 /* # # */
15 /* # Authors: # */
16 /* # - BESNARD Jean-Baptiste jean-baptiste.besnard@cea.fr # */
17 /* # # */
18 /* ######################################################################## */
19 
26 #ifndef HASH_TREE_H
27 #define HASH_TREE_H
28 
29 
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #endif
34 
35 #include "Hash_Table.h"
36 #include "Spinlock.h"
37 #include "Chained_List.h"
38 
39 /*
40  * Hash tree nodes
41  */
42 
43 
44 struct Hash_Tree_node
45 {
46  uint64_t request_entry_key;
47 
48  void *request_entry;
49  size_t request_size;
50 
51  void *payload;
52 
53  /* Tree links */
54  struct Hash_Tree_node *parent;
55  struct Chained_List children;
56 };
57 
58 void Hash_Tree_node_init(struct Hash_Tree_node *node,
59  struct Hash_Tree_node *parent,
60  void *request,
61  size_t request_size,
62  void *payload,
63  size_t payload_size );
64 
65 void Hash_Tree_node_release( struct Hash_Tree_node *node );
66 
67 void Hash_Tree_node_push_child( struct Hash_Tree_node *node,
68  struct Hash_Tree_node *child);
69 
70 
71 static inline struct Hash_Tree_node * Hash_Tree_node_get_parent( struct Hash_Tree_node *node )
72 {
73  return node?node->parent:NULL;
74 }
75 
76 static inline int Hash_Tree_node_get_child_count( struct Hash_Tree_node *node )
77 {
78  return node?Chained_List_count(&node->children):0;
79 }
80 
81 static inline struct Hash_Tree_node * Hash_Tree_node_get_nth_child( struct Hash_Tree_node *node, int id )
82 {
83  if(!node )
84  return NULL;
85 
86 
87  struct Hash_Tree_node **ret = (struct Hash_Tree_node **)Chained_List_get_nth(&node->children, id);
88 
89  if(!ret)
90  return NULL;
91 
92  return *ret;
93 }
94 
95 static inline void * Hash_Tree_node_payload( struct Hash_Tree_node *node )
96 {
97  return node?node->payload:NULL;
98 }
99 
100 static inline void * Hash_Tree_node_request( struct Hash_Tree_node *node )
101 {
102  return node?node->request_entry:NULL;
103 }
104 
105 
106 /*
107  * Hash table handling
108  */
109 
110 #define HASH_TREE_NODE_COLL_AVOID 2
111 
112 struct Hash_Tree_node_cell
113 {
114  struct Hash_Table_Internal ___;
115  struct Hash_Tree_node nodes[HASH_TREE_NODE_COLL_AVOID];
116 };
117 
118 
122 struct Hash_Tree
123 {
124  struct Hash_Table nodes;
126  size_t payload_size;
127  size_t request_size;
129  uint64_t node_count;
131  MALP_Spinlock lock;
132 };
133 
134 void Hash_Tree_init( struct Hash_Tree *htr, size_t request_size, size_t payload_size );
135 void Hash_Tree_release( struct Hash_Tree *htr, void (*free_func)(void *elemp) );
136 
137 int Hash_Tree_elem_exits( struct Hash_Tree *htr, void *prequest );
138 
139 struct Hash_Tree_node * Hash_Tree_get_elem( struct Hash_Tree *htr, void *prequest );
140 struct Hash_Tree_node * Hash_Tree_push( struct Hash_Tree *htr, void *parent_request, void *new_request, void *payload );
141 
142 void Hash_Tree_walk(struct Hash_Tree *htr, void *starting_point_request, void (*handler)(void *, void *), void *extra_arg);
143 
144 #ifdef __cplusplus
145 }
146 #endif
147 
148 
149 #endif /* HASH_TREE_H */
150 
struct Hash_Tree_node * Hash_Tree_get_elem(struct Hash_Tree *htr, void *request)
Definition: Hash_Tree.c:158
void Hash_Tree_node_release(struct Hash_Tree_node *node)
Definition: Hash_Tree.c:64
void Hash_Tree_init(struct Hash_Tree *htr, size_t request_size, size_t payload_size)
Definition: Hash_Tree.c:118
size_t payload_size
the size of elements that can be stored in the list
Definition: Chained_List.h:277
This is the structure used to store the clusters (items that have the same hash)
Definition: Hash_Table.h:44
static void * Chained_List_get_nth(struct Chained_List *list, uint64_t n)
Gets the nth element of the list.
Definition: Chained_List.h:383
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)
Definition: Hash_Tree.c:28
struct Hash_Tree_node * Hash_Tree_push(struct Hash_Tree *htr, void *parent_request, void *new_request, void *payload)
Definition: Hash_Tree.c:164
static uint64_t Chained_List_count(struct Chained_List *list)
Counts the elements in the list.
Definition: Chained_List.h:328
This a structure wrapps the use of chained_list This is the main chain list structure to use...
Definition: Chained_List.h:273
This is the main hask table structure.
Definition: Hash_Table.h:53
void Hash_Tree_node_push_child(struct Hash_Tree_node *node, struct Hash_Tree_node *child)
Definition: Hash_Tree.c:80
volatile unsigned int MALP_Spinlock
The type of spinlocks in MALP.
Definition: Spinlock.h:63
int Hash_Tree_elem_exits(struct Hash_Tree *htr, void *request)
Definition: Hash_Tree.c:152
void Hash_Tree_walk(struct Hash_Tree *htr, void *starting_point_request, void(*handler)(void *, void *), void *extra_arg)
Definition: Hash_Tree.c:252
void Hash_Tree_release(struct Hash_Tree *htr, void(*free_func)(void *))
Definition: Hash_Tree.c:143