home *** CD-ROM | disk | FTP | other *** search
-
- #ifndef DICTIONARY_H
- #define DICTIONARY_H
-
- #include <stdlib.h>
- #include <stdio.h>
-
- #define DEF_CAPACITY 17
- #define GROW_PERCENTAGE 0.90
- #define GROWTH_RATE 2
-
- typedef struct _dict *Dictionary;
- typedef struct _dictState DictState;
-
- struct listnode
- {
-
- struct listnode *next;
- char * key;
- void * value;
-
- };
-
- struct _dict
- {
- struct listnode **hashtable;
- unsigned int size;
- unsigned int used;
- };
-
- struct _dictState
- {
- unsigned int curIndex;
- struct listnode *curNode;
- Dictionary dict;
- unsigned int bumpedCurNode;/* Used when removing nodes */
- };
-
- Dictionary dict_alloc();
-
- void dict_free(Dictionary aDict);/* Doesnt free the values */
-
- /* Frees the values also, using the function freer */
- void dict_freeWithData(Dictionary aDict,void(*freer)());
-
- int dict_isKey(Dictionary aDict, const char *aStr);
-
- /* Set the value and return the old one, if it exists, copies the key */
- void * dict_setValueForKey(Dictionary aDict, const char *aKey, void *theValue);
-
- /* Returns 0 if no value */
- void * dict_valueForKey(Dictionary aDict, const char *theKey);
-
- /* Returns the value, and frees the key */
-
- void * dict_orphanValueForKey(Dictionary aDict, const char *theKey);
-
- /* Convience function to print the dictionary to std out */
-
- void dict_printToStdout(Dictionary theDict);
-
- DictState dict_initState(Dictionary aDict);
-
- int dict_nextState(DictState *aState);
-
- #endif
-