PULSAR  2.0.0
Parallel Ultra-Light Systolic Array Runtime
 All Data Structures Files Functions Typedefs Enumerations Macros Groups
icl_hash.c File Reference

Dependency-free hash table. More...

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <limits.h>
#include "icl_hash.h"

Go to the source code of this file.

Macros

#define BITS_IN_int   (sizeof(int) * CHAR_BIT)
 
#define THREE_QUARTERS   ((int)((BITS_IN_int * 3) / 4))
 
#define ONE_EIGHTH   ((int)(BITS_IN_int / 8))
 
#define HIGH_BITS   (~((unsigned int)(~0) >> ONE_EIGHTH))
 

Functions

icl_hash_ticl_hash_create (int nbuckets, unsigned int(*hash_function)(void *), int(*hash_key_compare)(void *, void *))
 Creates a new hash table. More...
 
void * icl_hash_find (icl_hash_t *ht, void *key)
 Searches for an entry in a hash table. More...
 
icl_entry_ticl_hash_insert (icl_hash_t *ht, void *key, void *data)
 Inserts an item into a hash table. More...
 
icl_entry_ticl_hash_update_insert (icl_hash_t *ht, void *key, void *data, void **olddata)
 Replaces an entry in a hash table with a given entry. More...
 
int icl_hash_delete (icl_hash_t *ht, void *key, void(*free_key)(void *), void(*free_data)(void *))
 Frees one hash table entry located by a key. Key and data are freed using functions. More...
 
int icl_hash_destroy (icl_hash_t *ht, void(*free_key)(void *), void(*free_data)(void *))
 Destroys a hash table. Keys and data are freed using functions. More...
 
int icl_hash_dump (FILE *stream, icl_hash_t *ht)
 Dumps the hash table's contents to the given file pointer. More...
 

Detailed Description

Dependency-free hash table.

Author
Keith Seymour

PULSAR Runtime http://icl.utk.edu/pulsar/ Copyright (C) 2012-2015 University of Tennessee.

Definition in file icl_hash.c.

Function Documentation

icl_hash_t* icl_hash_create ( int  nbuckets,
unsigned int(*)(void *)  hash_function,
int(*)(void *, void *)  hash_key_compare 
)

Creates a new hash table.

Parameters
nbuckets– The number of buckets to create.
hash_function– The pointer to the hashing function.
hash_key_compare– The pointer to the hash key comparison function.
Returns
A pointer to new hash table.

Definition at line 71 of file icl_hash.c.

int icl_hash_delete ( icl_hash_t ht,
void *  key,
void(*)(void *)  free_key,
void(*)(void *)  free_data 
)

Frees one hash table entry located by a key. Key and data are freed using functions.

Parameters
ht– The hash table.
key– The key of the item to be deleted.
free_key– The pointer to the function that frees the key.
free_data– The pointer to the function that frees the data.
Return values
0on success.
-1on failure.

Definition at line 234 of file icl_hash.c.

int icl_hash_destroy ( icl_hash_t ht,
void(*)(void *)  free_key,
void(*)(void *)  free_data 
)

Destroys a hash table. Keys and data are freed using functions.

Parameters
ht– The hash table to destroy.
free_key– The pointer to function that frees the keys.
free_data– The pointer to function that frees the data.
Return values
0on success.
-1on failure.

Definition at line 282 of file icl_hash.c.

int icl_hash_dump ( FILE *  stream,
icl_hash_t ht 
)

Dumps the hash table's contents to the given file pointer.

Parameters
stream– The file to dump the hash table to.
ht– The hash table to be dumped.
Return values
0on success.
-1on failure.

Definition at line 323 of file icl_hash.c.

void* icl_hash_find ( icl_hash_t ht,
void *  key 
)

Searches for an entry in a hash table.

Parameters
ht– The hash table to be searched.
key– The key of the item to search for.
Returns
A pointer to the data corresponding to the key. NULL if the key is not found.

Definition at line 109 of file icl_hash.c.

icl_entry_t* icl_hash_insert ( icl_hash_t ht,
void *  key,
void *  data 
)

Inserts an item into a hash table.

Parameters
ht– The hash table.
key– The key of the new item.
data– The pointer to the new item's data.
Returns
A pointer to the new item. NULL on error.

Definition at line 135 of file icl_hash.c.

icl_entry_t* icl_hash_update_insert ( icl_hash_t ht,
void *  key,
void *  data,
void **  olddata 
)

Replaces an entry in a hash table with a given entry.

Parameters
ht– The hash table.
key– The key of the new item.
data– The pointer to the new item's data.
olddata– The pointer to the old item's data (set upon return).
Returns
A pointer to the new item. NULL on error.

Definition at line 174 of file icl_hash.c.