Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Improve the code dynar example by explaining that freeing the stuff twice is of cours...
[simgrid.git] / src / xbt / dict_private.h
1 /* $Id$ */
2
3 /* dict_elm - elements of generic dictionnaries                             */
4 /* This file is not to be loaded from anywhere but dict.c                   */
5
6 /* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved.            */
7
8 /* This program is free software; you can redistribute it and/or modify it
9  * under the terms of the license (GNU LGPL) which comes with this package. */
10
11 #ifndef _XBT_DICT_PRIVATE_H__
12 #define _XBT_DICT_PRIVATE_H__
13
14 #include "xbt/sysdep.h"
15 #include "xbt/log.h"
16 #include "xbt/ex.h"
17 #include "xbt/dynar.h"
18 #include "xbt/dict.h"
19 #include "xbt/mallocator.h"
20
21 typedef struct xbt_dictelm_ *xbt_dictelm_t;
22
23 #define MAX_FILL_PERCENT 80
24
25 typedef struct xbt_dictelm_ {
26   int dictielem:1;
27   char *key;
28   int key_len;
29   unsigned int hash_code;
30
31   void *content;
32   void_f_pvoid_t free_f;
33
34   xbt_dictelm_t next;
35 } s_xbt_dictelm_t;
36
37 typedef struct xbt_dict_ {
38   xbt_dictelm_t *table;
39   int table_size;
40   int count;
41   int fill;
42 } s_xbt_dict_t;
43
44 typedef struct xbt_dict_cursor_ s_xbt_dict_cursor_t;
45
46 extern xbt_mallocator_t dict_elm_mallocator;
47 extern void *dict_elm_mallocator_new_f(void);
48 extern void dict_elm_mallocator_free_f(void *elem);
49 extern void dict_elm_mallocator_reset_f(void *elem);
50
51 /*####[ Function prototypes ]################################################*/
52 xbt_dictelm_t xbt_dictelm_new(const char *key, int key_len,
53                               unsigned int hash_code, void *content,
54                               void_f_pvoid_t free_f);
55 xbt_dictelm_t xbt_dictielm_new(uintptr_t key, unsigned int hash_code, uintptr_t content);
56 void xbt_dictelm_free(xbt_dictelm_t element);
57 void xbt_dict_add_element(xbt_dict_t dict, xbt_dictelm_t element);
58
59 #endif /* _XBT_DICT_PRIVATE_H_ */