MP7 MapReduce
libdictionary.c File Reference
#include <search.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include "libdictionary.h"

Functions

void dictionary_init (dictionary_t *d)
 Must be called first, initializes the dictionary data structure.
int dictionary_add (dictionary_t *d, const char *key, const char *value)
 Adds a (key, value) pair to the dictionary.
const char * dictionary_get (dictionary_t *d, const char *key)
int dictionary_remove (dictionary_t *d, const char *key)
 Removes the (key, value) entry from the dictionary.
int dictionary_remove_free (dictionary_t *d, const char *key)
 Removes the (key, value) entry from the dictionary.
void dictionary_destroy (dictionary_t *d)
 Frees all internal memory associated with the dictionary.
void dictionary_destroy_free (dictionary_t *d)
 Frees all internal memory associated with the dictionary AND makes a call to dictionary_remove_free() for each entry that still exists in the dictionary at the time dictionary_destroy_free() is called.

Detailed Description


Function Documentation

int dictionary_add ( dictionary_t d,
const char *  key,
const char *  value 
)

Adds a (key, value) pair to the dictionary.

Returns:
0 on success or KEY_EXISTS if the key already exists in the dictionary.

Frees all internal memory associated with the dictionary.

Must be called last.

Frees all internal memory associated with the dictionary AND makes a call to dictionary_remove_free() for each entry that still exists in the dictionary at the time dictionary_destroy_free() is called.

Since this function makes use of dictionary_remove_free(), this function is unsafe if you have used non-heap memory when calling dictionary_add().

const char* dictionary_get ( dictionary_t d,
const char *  key 
)
Returns:
the stored value associated with the key if the key exists in the dictionary. If the key does not exist, this function will return NULL.

Must be called first, initializes the dictionary data structure.

Same as MP1.

int dictionary_remove ( dictionary_t d,
const char *  key 
)

Removes the (key, value) entry from the dictionary.

Returns:
0 on success or NO_KEY_EXISTS if the key was not present in the dictionary. This function does not free the memory used by key or value.
int dictionary_remove_free ( dictionary_t d,
const char *  key 
)

Removes the (key, value) entry from the dictionary.

Returns:
0 on success or NO_KEY_EXISTS if the key was not present in the dictionary. This function WILL call free(key) and free(value) on the (key, value) pair stored in the dictionary before returning. This function is unsafe if you have used non-heap memory when calling dictionary_add().
 All Data Structures Files Functions