Bioplib
Protein Structure C Library
|
Flexible hash functions. More...
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include "hash.h"
#include "macros.h"
#include "MathUtil.h"
Go to the source code of this file.
Functions | |
HASHTABLE * | blInitializeHash (ULONG hashsize) |
void | blFreeHashKeyList (char **keylist) |
char ** | blGetHashKeyList (HASHTABLE *hashtable) |
void | blFreeHash (HASHTABLE *hashtable) |
BOOL | blSetHashValue (HASHTABLE *hashtable, char *key, int type,...) |
BOOL | blSetHashValueString (HASHTABLE *hashtable, char *key, char *value) |
BOOL | blSetHashValueInt (HASHTABLE *hashtable, char *key, int value) |
BOOL | blSetHashValueDouble (HASHTABLE *hashtable, char *key, double value) |
BOOL | blSetHashValuePointer (HASHTABLE *hashtable, char *key, BPTR ptr) |
BOOL | blSetHashValueChar (HASHTABLE *hashtable, char *key, char value) |
int | blGetHashValueInt (HASHTABLE *hashtable, char *key) |
double | blGetHashValueDouble (HASHTABLE *hashtable, char *key) |
char | blGetHashValueChar (HASHTABLE *hashtable, char *key) |
char * | blGetHashValueString (HASHTABLE *hashtable, char *key) |
BPTR | blGetHashValuePointer (HASHTABLE *hashtable, char *key) |
BPTR | blGetHashValue (HASHTABLE *hashtable, char *key, int *type) |
BOOL | blDumpHash (FILE *out, HASHTABLE *hashtable) |
BOOL | blHashKeyDefined (HASHTABLE *hashtable, char *key) |
void | blDeleteHashKey (HASHTABLE *hashtable, char *key) |
Flexible hash functions.
This code is NOT IN THE PUBLIC DOMAIN, but it may be copied according to the conditions laid out in the accompanying file COPYING.DOC.
The code may be modified as required, but any modifications must be documented so that the person responsible can be identified.
The code may not be sold commercially or included as part of a commercial product except as described in the file COPYING.DOC.
Based very loosely on code from http://www.sourcecodesworld.com/source/show.asp?ScriptID=1188
Compile with -finline-functions
Definition in file hash.c.
void blDeleteHashKey | ( | HASHTABLE * | hashtable, |
char * | key | ||
) |
void blFreeHash | ( | HASHTABLE * | hashtable | ) |
void blFreeHashKeyList | ( | char ** | keylist | ) |
[in] | keylist | List of keys returned by blGetHashKeyList() |
Frees memory allocated for a list of keys in the hash
char** blGetHashKeyList | ( | HASHTABLE * | hashtable | ) |
[in] | hashtable | The hashtable |
Gets a list of the keys in the hash. Allocates memory which must be freed using blFreeHashKeyList()
[in] | hashtable | The hash table |
[in] | key | The hash key |
[out] | type | The type for that item (or NULL) |
Obtain an entry from the hash. Type 'type' parameter can be NULL if you are sure you know what the type is and don't want to check. The value is returned as a pointer. If the value is itself a pointer or a string then this is what you want, but you will need to cast it appropriately. If it is an int, double or char then you need to cast and dereference this:
string: (char *)value pointer: (my-type *)value int: *(int *)value double: *(double *)value char: *(char *)value
char blGetHashValueChar | ( | HASHTABLE * | hashtable, |
char * | key | ||
) |
[in] | hashtable | The hash table |
[in] | key | The hash key |
Simple wrapper to blGetHashValue() for extracting characters
double blGetHashValueDouble | ( | HASHTABLE * | hashtable, |
char * | key | ||
) |
[in] | hashtable | The hash table |
[in] | key | The hash key |
Simple wrapper to blGetHashValue() for extracting doubles
int blGetHashValueInt | ( | HASHTABLE * | hashtable, |
char * | key | ||
) |
[in] | hashtable | The hash table |
[in] | key | The hash key |
Simple wrapper to blGetHashValue() for extracting integers
[in] | hashtable | The hash table |
[in] | key | The hash key |
Simple wrapper to blGetHashValue() for extracting pointers
char* blGetHashValueString | ( | HASHTABLE * | hashtable, |
char * | key | ||
) |
[in] | hashtable | The hash table |
[in] | key | The hash key |
Simple wrapper to blGetHashValue() for extracting strings
[in] | hashsize | An estimate of the size of the hash (or 0) |
The size estimate is used to allocate a hash table. If too large you waste memory; if too small lookups will take longer. You can use 0 for the default hash size of 1001
A future version will implement dynamic hashing.
[in] | *hashtable | The hash table |
[in] | *key | The key for the hash entry |
[in] | *value | The value for the hash entry |
Wrapper to blSetHashValue()
[in] | *hashtable | The hash table |
[in] | *key | The key for the hash entry |
[in] | *value | The value for the hash entry |
Set a double value in a hash Wrapper to blSetHashValue()
[in] | *hashtable | The hash table |
[in] | *key | The key for the hash entry |
[in] | *value | The value for the hash entry |
Set an int value in a hash Wrapper to blSetHashValue()
[in] | *hashtable | The hash table |
[in] | *key | The key for the hash entry |
[in] | *value | The value for the hash entry |
Set a general pointer (BPTR) value in a hash Wrapper to blSetHashValue()
[in] | *hashtable | The hash table |
[in] | *key | The key for the hash entry |
[in] | *value | The value for the hash entry |
Set a string value in a hash Wrapper to blSetHashValue()