hashtable.c File Reference

Hashtable implementation internals. More...

#include <stdlib.h>
#include <string.h>
#include "hashtable.h"

Go to the source code of this file.

Defines

#define NEW(T)   (T*) malloc(sizeof(T))
 Allocate memory for some type.
#define NEWARRAY(T, N)   (T*) calloc((N), sizeof(T))
 Allocate memory for an array.

Functions

struct hashtablecopy_hashtable (struct hashtable *dest, struct hashtable *src)
 Insert all elements from one hash table into another.
void free_hashtable (struct hashtable *table)
 Free all the memory used by a hash table.
int hashtable_add (struct hashtable *table, char *key, void *value)
 Add an entry to a hash table.
unsigned int hashtable_default_hash (const char *key)
 The default hash function.
void hashtable_iter (const struct hashtable *table, void(*func)(char *key, void *value))
 Call a function for each entry in a hash table.
void * hashtable_lookup (const struct hashtable *table, const char *key)
 Look up the value bound to a key.
struct hashtablemake_hashtable (unsigned int(*hash)(const char *), unsigned int nbuckets)
 Create a hash table.

Detailed Description

Hashtable implementation internals.

This file contains the full documentation of all functions, types, constants, and variables used in the hashtable implementation, including those that are intended only for internal use. For the public interface to hash tables, see hashtable.h.

Definition in file hashtable.c.


Define Documentation

#define NEW (  )     (T*) malloc(sizeof(T))

Allocate memory for some type.

Parameters:
T The type to allocate memory for.
Returns:
A pointer to the newly allocated storage.

Definition at line 18 of file hashtable.c.

#define NEWARRAY ( T,
 )     (T*) calloc((N), sizeof(T))

Allocate memory for an array.

Parameters:
T The type of the elements of the array.
N The number of elements in the array.
Returns:
A pointer to the array.

Definition at line 25 of file hashtable.c.


Function Documentation

struct hashtable* copy_hashtable ( struct hashtable dest,
struct hashtable src 
) [read]

Insert all elements from one hash table into another.

Parameters:
dest The hash table to insert elements into.
src The hash table whose elements are to be inserted.
Returns:
dest

Definition at line 73 of file hashtable.c.

void free_hashtable ( struct hashtable table  ) 

Free all the memory used by a hash table.

Parameters:
table The hash table to be deallocated.

Definition at line 108 of file hashtable.c.

int hashtable_add ( struct hashtable table,
char *  key,
void *  value 
)

Add an entry to a hash table.

Parameters:
table The hash table the entry is to be added to.
key The key for the entry.
value The value for the entry.
Returns:
Nonzero on success, 0 on failure.

Definition at line 45 of file hashtable.c.

unsigned int hashtable_default_hash ( const char *  key  ) 

The default hash function.

This function can be used as the hash parameter to make_hash_table().

Parameters:
key The key to be hashed.
Returns:
The hash for the key.

Definition at line 93 of file hashtable.c.

void hashtable_iter ( const struct hashtable table,
void(*)(char *key, void *value)  func 
)

Call a function for each entry in a hash table.

Parameters:
table The hash table whose entries to iterate over.
func The function to call for each entry. The function receives two argument: 1. The key of the entry. 2. The value of the entry.

Definition at line 133 of file hashtable.c.

void* hashtable_lookup ( const struct hashtable table,
const char *  key 
)

Look up the value bound to a key.

Parameters:
table The hash table in which to look up the key.
key The key to look up.
Returns:
The value belonging to the key if found, NULL if not found.

Definition at line 151 of file hashtable.c.

struct hashtable* make_hashtable ( unsigned int(*)(const char *)  hash,
unsigned int  nbuckets 
) [read]

Create a hash table.

Parameters:
hash The hash function to use with this hash table. The function has to map NUL-terminated strings to unsigned ints.
nbuckets The number of buckets in the hash table.
Returns:
The new hash table on success, NULL on failure.

Definition at line 171 of file hashtable.c.

 All Data Structures Files Functions Variables Defines
Generated on Sun Jul 11 13:37:58 2010 for hashtable by  doxygen 1.6.3