Author: gherzan Date: Tue Mar 9 15:47:43 2010 New Revision: 2111 Log: Add dictionary header, part of uthash replacement. Added: trunk/libpisa/dict.h Added: trunk/libpisa/dict.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/libpisa/dict.h Tue Mar 9 15:47:43 2010 (r2111) @@ -0,0 +1,76 @@ +/* vim: set expandtab tabstop=4 shiftwidth=4: */ +/* + * Copyright (c) 2009, Distributed Systems Group, RWTH Aachen + * All rights reserved. + */ + +/** + * @file dict.h + * @brief Dictionary wrappers to provide library-independence. + * @author Mircea Gherzan <mgherzan@xxxxxxxxx> + * @date Feb. 2010 + */ + +#ifndef _PISA_DICT_H +#define _PISA_DICT_H + +#include "config.h" + +/* option/flag defitions */ + +#define PISA_DICT_KEY_32BIT 0 +#define PISA_DICT_KEY_128BIT 1 +#define PISA_DICT_KEY_MAC 2 +#define PISA_DICT_KEY_IP_HIT 3 + +struct pisa_dict; + +/** + * Create a new dictionary + * @param ktype key type specifier + * @param opts options for the underlying implementation + * @return the new structure on success, NULL on failure + */ +static inline struct pisa_dict *pisa_dict_create(int ktype, int opts); + +/** + * Add an entry to a dictionary + * @param d the dictionary to add to + * @param k the key of the entry + * @param v the value of the entry + * @return 0 on success, non-zero otherwise + */ +static inline int pisa_dict_add(struct pisa_dict *d, const void *k, + const void *v); + +/** + * Find a dictionary entry by its key + * @param d the dictionaty to be searched + * @param k the key of the wanted entry + * @return pointer to the matching entry, if found, and NULL otherwise + */ +static inline void *pisa_dict_find(struct pisa_dict *d, const void *k); + +/** + * Delete and entry from the hash table + * @param d the hash table + * @param k the key indentifying the entry + * @return 0 on success, non-zero otherwise + */ +static inline int pisa_dict_del(struct pisa_dict *d, const void *k); + +/** + * Destroy a dictionary (only the structure, NOT the contained data) + * @param d dictionary to be destroyed + * @param f free the _entries_ before destroying/free the dictionary + * @return 0 on success, non-zero otherwise + */ +static inline int pisa_dict_free(struct pisa_dict *d, int f); + +#ifdef CONFIG_PISA_DICT_MAA +# include "dict-maa.h" +#elif defined(CONFIG_PISA_DICT_EINA) +# include "dict-eina.h" +#endif + +#endif // _PISA_DICT_H