Loading...
Searching...
No Matches
dictionary.h
Go to the documentation of this file.
#ifndef _DICTIONARY_H_
#define _DICTIONARY_H_
/* Copyright (c) 2000-2007 by Nicolas Devillard.
* Copyright (x) 2009 by Tim Post <tinkertim@gmail.com>
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
typedef struct _dictionary_ {
int n;
int size;
char** val;
char** key;
unsigned* hash;
} dictionary;
unsigned dictionary_hash(const char* key);
dictionary* dictionary_new(int size);
void dictionary_del(dictionary* vd);
const char* dictionary_get(dictionary* d, const char* key, const char* def);
int dictionary_set(dictionary* vd, const char* key, const char* val);
void dictionary_unset(dictionary* d, const char* key);
void dictionary_dump(dictionary* d, FILE* out);
#ifdef __cplusplus
}
#endif
#endif
dictionary_unset
void dictionary_unset(dictionary *d, const char *key)
Delete a key in a dictionary.
Definition dictionary.c:206
dictionary
struct _dictionary_ dictionary
Dictionary object.
dictionary_dump
void dictionary_dump(dictionary *d, FILE *out)
Dump a dictionary to an opened file pointer.
Definition dictionary.c:241
dictionary_hash
unsigned dictionary_hash(const char *key)
Compute the hash key for a string.
Definition dictionary.c:74
dictionary_new
dictionary * dictionary_new(int size)
Create a new dictionary object.
Definition dictionary.c:92
dictionary_get
const char * dictionary_get(dictionary *d, const char *key, const char *def)
Get a value from a dictionary.
Definition dictionary.c:128
dictionary_del
void dictionary_del(dictionary *d)
Delete a dictionary object.
Definition dictionary.c:109
dictionary_set
int dictionary_set(dictionary *d, const char *key, const char *val)
Set a value in a dictionary.
Definition dictionary.c:147
_dictionary_
Dictionary object.
Definition dictionary.h:67