GEL  0.99
util.h
Go to the documentation of this file.
1 /*
2  * $Id$
3  * Copyright (c) 2011, IRIT- UPS
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 #ifndef GEL_UTIL_H
20 #define GEL_UTIL_H
21 
22 #include <gel/common.h>
23 #include <gel/types.h>
24 
26 
27 /* list management */
28 typedef struct descripteur *gel_list_t;
30 void gel_list_first(gel_list_t desc);
31 int gel_list_end(gel_list_t desc);
32 void *gel_list_get(gel_list_t desc);
33 int gel_list_contains(gel_list_t desc, void *val);
34 int gel_list_add(gel_list_t desc, void *val);
35 int gel_list_remove(gel_list_t desc, void *val);
36 void gel_list_clear(gel_list_t desc);
37 void gel_list_delete(gel_list_t desc);
38 void gel_list_delete_items(gel_list_t desc, void (*free)(void *));
39 int gel_list_length(gel_list_t desc);
41 
42 
43 /* hash table management */
44 typedef struct hashage *gel_hash_t;
45 gel_hash_t gel_hash_new(int size);
46 
55 int hash_put(gel_hash_t hash, char *key, void *value);
56 
64 void *hash_get(gel_hash_t hash, char *key);
65 
73 int hash_del(gel_hash_t hash, char *key);
74 
80 void hash_free(gel_hash_t hash);
81 
89 
90 
91 void hash_enum_free(gel_enum_t *en);
92 
93 
94 
98 struct item {
99  char *key;
100  void *value;
101  struct item *next;
102 };
103 
104 
105 typedef struct item *item_t;
106 
107 /* Straight enumeration of hash table */
108 typedef struct gel_hash_enum_t {
110  int index;
111  struct item *item;
116 #define gel_hash_key(en) ((en)->item->key)
117 #define gel_hash_value(en) ((en)->item->value)
118 
120 
121 #endif // GEL_UTIL_H
122 
#define __END_DECLS
Definition: common.h:29
#define __BEGIN_DECLS
Definition: common.h:28
void gel_list_first(gel_list_t desc)
Definition: util.c:342
void gel_list_delete(gel_list_t desc)
Definition: util.c:435
void gel_list_delete_items(gel_list_t desc, void(*free)(void *))
Definition: util.c:446
int gel_list_remove(gel_list_t desc, void *val)
Definition: util.c:483
void * gel_list_get(gel_list_t desc)
Definition: util.c:363
int gel_list_end(gel_list_t desc)
Definition: util.c:352
int gel_list_contains(gel_list_t desc, void *val)
Definition: util.c:380
gel_list_t gel_list_new(void)
Definition: util.c:327
int gel_list_length(gel_list_t desc)
Definition: util.c:464
int gel_list_add(gel_list_t desc, void *val)
Definition: util.c:397
int gel_list_empty(gel_list_t a)
Definition: util.c:317
void gel_list_clear(gel_list_t desc)
Definition: util.c:419
Definition: util.h:108
gel_hash_t htab
Definition: util.h:109
struct item * item
Definition: util.h:111
int index
Definition: util.h:110
Definition: util.h:98
void * value
Definition: util.h:100
struct item * next
Definition: util.h:101
char * key
Definition: util.h:99
struct gel_enum_s gel_enum_t
Definition: types.h:42
void * gel_hash_enum_init(gel_hash_enum_t *en, gel_hash_t htab)
Definition: util.c:519
typedef__BEGIN_DECLS struct descripteur * gel_list_t
Definition: util.h:28
void hash_free(gel_hash_t hash)
Definition: util.c:266
void * hash_get(gel_hash_t hash, char *key)
Definition: util.c:222
struct item * item_t
Definition: util.h:105
struct hashage * gel_hash_t
Definition: util.h:44
int hash_del(gel_hash_t hash, char *key)
Definition: util.c:241
gel_enum_t * hash_enum(gel_hash_t h)
Definition: util.c:172
void gel_hash_enum_end(gel_hash_enum_t *en, gel_hash_t htab)
Definition: util.c:558
void hash_enum_free(gel_enum_t *en)
Definition: util.c:120
struct gel_hash_enum_t gel_hash_enum_t
void * gel_hash_enum_next(gel_hash_enum_t *en)
Definition: util.c:536
gel_hash_t gel_hash_new(int size)
Definition: util.c:290
int hash_put(gel_hash_t hash, char *key, void *value)
Definition: util.c:197