Lines Matching defs:key

29 /** Invalid key token */
78 @brief Compute the hash key for a string.
79 @param key Character string to use for key.
84 The key is stored anyway in the struct so that collision can be avoided
85 by comparing the key itself in last resort.
88 unsigned dictionary_hash(const char * key)
94 len = strlen(key);
96 hash += (unsigned)key[i] ;
129 d->key = (char **)calloc(size, sizeof(char*));
149 if (d->key[i]!=NULL)
150 free(d->key[i]);
155 free(d->key);
165 @param key Key to look for in the dictionary.
166 @param def Default value to return if key not found.
169 This function locates a key in a dictionary and returns a pointer to its
170 value, or the passed 'def' pointer if no such key can be found in
175 char * dictionary_get(dictionary * d, const char * key, char * def)
180 hash = dictionary_hash(key);
182 if (d->key[i]==NULL)
187 if (!strcmp(key, d->key[i])) {
199 @param key Key to modify or add.
203 If the given key is found in the dictionary, the associated value is
204 replaced by the provided one. If the key cannot be found in the
208 or the key are considered as errors: the function will return immediately
215 dictionary. It is not possible (in this implementation) to have a key in
221 int dictionary_set(dictionary * d, const char * key, const char * val)
226 if (d==NULL || key==NULL) return -1 ;
228 /* Compute hash for this key */
229 hash = dictionary_hash(key) ;
233 if (d->key[i]==NULL)
236 if (!strcmp(key, d->key[i])) { /* Same key */
253 d->key = (char **)mem_double(d->key, d->size * sizeof(char*)) ;
255 if ((d->val==NULL) || (d->key==NULL) || (d->hash==NULL)) {
263 /* Insert key in the first empty slot. Start at d->n and wrap at
266 for (i=d->n ; d->key[i] ; ) {
269 /* Copy key */
270 d->key[i] = xstrdup(key);
279 @brief Delete a key in a dictionary
281 @param key Key to remove.
284 This function deletes a key in a dictionary. Nothing is done if the
285 key cannot be found.
288 void dictionary_unset(dictionary * d, const char * key)
293 if (key == NULL) {
297 hash = dictionary_hash(key);
299 if (d->key[i]==NULL)
304 if (!strcmp(key, d->key[i])) {
305 /* Found key */
314 free(d->key[i]);
315 d->key[i] = NULL ;
347 if (d->key[i]) {
349 d->key[i],
382 printf("cannot get value for key [%s]\n", cval);