KTH framework for Nek5000 toolboxes; testing version  0.0.1
dictionary.h
Go to the documentation of this file.
1 
2 /*-------------------------------------------------------------------------*/
12 /*--------------------------------------------------------------------------*/
13 
14 #ifndef _DICTIONARY_H_
15 #define _DICTIONARY_H_
16 
17 /*---------------------------------------------------------------------------
18  Includes
19  ---------------------------------------------------------------------------*/
20 
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <unistd.h>
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 /*---------------------------------------------------------------------------
31  New types
32  ---------------------------------------------------------------------------*/
33 
34 
35 /*-------------------------------------------------------------------------*/
44 /*-------------------------------------------------------------------------*/
45 typedef struct _dictionary_ {
46  int n ;
47  ssize_t size ;
48  char ** val ;
49  char ** key ;
50  unsigned * hash ;
52 
53 
54 /*---------------------------------------------------------------------------
55  Function prototypes
56  ---------------------------------------------------------------------------*/
57 
58 /*-------------------------------------------------------------------------*/
69 /*--------------------------------------------------------------------------*/
70 unsigned dictionary_hash(const char * key);
71 
72 /*-------------------------------------------------------------------------*/
82 /*--------------------------------------------------------------------------*/
83 dictionary * dictionary_new(size_t size);
84 
85 /*-------------------------------------------------------------------------*/
93 /*--------------------------------------------------------------------------*/
94 void dictionary_del(dictionary * vd);
95 
96 /*-------------------------------------------------------------------------*/
109 /*--------------------------------------------------------------------------*/
110 const char * dictionary_get(const dictionary * d, const char * key, const char * def);
111 
112 
113 /*-------------------------------------------------------------------------*/
138 /*--------------------------------------------------------------------------*/
139 int dictionary_set(dictionary * vd, const char * key, const char * val);
140 
141 /*-------------------------------------------------------------------------*/
151 /*--------------------------------------------------------------------------*/
152 void dictionary_unset(dictionary * d, const char * key);
153 
154 
155 /*-------------------------------------------------------------------------*/
166 /*--------------------------------------------------------------------------*/
167 void dictionary_dump(const dictionary * d, FILE * out);
168 
169 #ifdef __cplusplus
170 }
171 #endif
172 
173 #endif
void dictionary_unset(dictionary *d, const char *key)
Delete a key in a dictionary.
Definition: dictionary.c:314
struct _dictionary_ dictionary
Dictionary object.
unsigned dictionary_hash(const char *key)
Compute the hash key for a string.
Definition: dictionary.c:118
const char * dictionary_get(const dictionary *d, const char *key, const char *def)
Get a value from a dictionary.
Definition: dictionary.c:209
void dictionary_del(dictionary *vd)
Delete a dictionary object.
Definition: dictionary.c:177
int dictionary_set(dictionary *vd, const char *key, const char *val)
Set a value in a dictionary.
Definition: dictionary.c:255
void dictionary_dump(const dictionary *d, FILE *out)
Dump a dictionary to an opened file pointer.
Definition: dictionary.c:363
dictionary * dictionary_new(size_t size)
Create a new dictionary object.
Definition: dictionary.c:150
Dictionary object.
Definition: dictionary.h:45
unsigned * hash
Definition: dictionary.h:50
char ** key
Definition: dictionary.h:49
char ** val
Definition: dictionary.h:48
ssize_t size
Definition: dictionary.h:47