The outage for Sunday 24th November has been cancelled.
Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
Data Structures | Macros | Typedefs | Functions
hash.h File Reference

Defines for using hash functions. More...

#include <stdarg.h>
#include "SysDefs.h"

Go to the source code of this file.

Data Structures

struct  _hashTab
 
struct  HASHTABLE
 

Macros

#define DEF_HASHSIZE   1009 /* Must be a prime number */
 
#define HASHTYPE_STRING   0
 
#define HASHTYPE_INT   1
 
#define HASHTYPE_CHAR   2
 
#define HASHTYPE_DOUBLE   3
 
#define HASHTYPE_POINTER   4
 

Typedefs

typedef struct _hashTab _HASHENTRY
 

Functions

HASHTABLEblInitializeHash (ULONG hashsize)
 
void blFreeHash (HASHTABLE *hashtable)
 
char * blStrdup (char *instr)
 
void blFreeHashKeyList (char **keylist)
 
char ** blGetHashKeyList (HASHTABLE *hashtable)
 
BOOL blSetHashValue (HASHTABLE *hashtable, char *key, int type,...)
 
BPTR blGetHashValue (HASHTABLE *hashtable, char *key, int *type)
 
BOOL blDumpHash (FILE *out, HASHTABLE *hashtable)
 
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)
 
BOOL blHashKeyDefined (HASHTABLE *hashtable, char *key)
 
void blDeleteHashKey (HASHTABLE *hashtable, char *key)
 

Detailed Description

Defines for using hash functions.

Version
V1.2
Date
26.11.15
Author
Dr. Andrew C. R. Martin
Institute of Structural & Molecular Biology, University College London, Gower Street, London. WC1E 6BT.
andre.nosp@m.w@bi.nosp@m.oinf..nosp@m.org..nosp@m.uk andre.nosp@m.w.ma.nosp@m.rtin@.nosp@m.ucl..nosp@m.ac.uk

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.

Description:

Usage:

Revision History:

Definition in file hash.h.

Macro Definition Documentation

#define DEF_HASHSIZE   1009 /* Must be a prime number */

Definition at line 64 of file hash.h.

#define HASHTYPE_CHAR   2

Definition at line 67 of file hash.h.

#define HASHTYPE_DOUBLE   3

Definition at line 68 of file hash.h.

#define HASHTYPE_INT   1

Definition at line 66 of file hash.h.

#define HASHTYPE_POINTER   4

Definition at line 69 of file hash.h.

#define HASHTYPE_STRING   0

Definition at line 65 of file hash.h.

Typedef Documentation

typedef struct _hashTab _HASHENTRY

Function Documentation

void blDeleteHashKey ( HASHTABLE hashtable,
char *  key 
)
Parameters
[in]hashtableThe hash table
[in]keyThe hash key

Deletes a hash key

  • 14.05.15 Original By: ACRM

Definition at line 798 of file hash.c.

BOOL blDumpHash ( FILE *  out,
HASHTABLE hashtable 
)
Parameters
[in]outFile pointer
[in]hashtableThe hash table
Returns
Success

Dumps the contents of the hash to the specified file pointer

  • 12.05.15 Original By: ACRM

Definition at line 720 of file hash.c.

void blFreeHash ( HASHTABLE hashtable)
Parameters
[in]hashtableThe hash table

Frees all memory used by the hash

  • 12.05.15 Original By: ACRM

Definition at line 293 of file hash.c.

void blFreeHashKeyList ( char **  keylist)
Parameters
[in]keylistList of keys returned by blGetHashKeyList()

Frees memory allocated for a list of keys in the hash

  • 12.05.15 Original By: ACRM

Definition at line 200 of file hash.c.

char** blGetHashKeyList ( HASHTABLE hashtable)
Parameters
[in]hashtableThe hashtable
Returns
Array of strings representing hash keys

Gets a list of the keys in the hash. Allocates memory which must be freed using blFreeHashKeyList()

  • 12.05.15 Original By: ACRM

Definition at line 226 of file hash.c.

BPTR blGetHashValue ( HASHTABLE hashtable,
char *  key,
int *  type 
)
Parameters
[in]hashtableThe hash table
[in]keyThe hash key
[out]typeThe type for that item (or NULL)
Returns
Pointer to the value

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

  • 12.05.15 Original By: ACRM

Definition at line 668 of file hash.c.

char blGetHashValueChar ( HASHTABLE hashtable,
char *  key 
)
Parameters
[in]hashtableThe hash table
[in]keyThe hash key
Returns
The value

Simple wrapper to blGetHashValue() for extracting characters

  • 12.05.15 Original By: ACRM

Definition at line 599 of file hash.c.

double blGetHashValueDouble ( HASHTABLE hashtable,
char *  key 
)
Parameters
[in]hashtableThe hash table
[in]keyThe hash key
Returns
The value

Simple wrapper to blGetHashValue() for extracting doubles

  • 12.05.15 Original By: ACRM

Definition at line 575 of file hash.c.

int blGetHashValueInt ( HASHTABLE hashtable,
char *  key 
)
Parameters
[in]hashtableThe hash table
[in]keyThe hash key
Returns
The value

Simple wrapper to blGetHashValue() for extracting integers

  • 12.05.15 Original By: ACRM
  • 23.08.15 Added cast of NAN

Definition at line 551 of file hash.c.

BPTR blGetHashValuePointer ( HASHTABLE hashtable,
char *  key 
)
Parameters
[in]hashtableThe hash table
[in]keyThe hash key
Returns
The value

Simple wrapper to blGetHashValue() for extracting pointers

  • 12.05.15 Original By: ACRM

Definition at line 638 of file hash.c.

char* blGetHashValueString ( HASHTABLE hashtable,
char *  key 
)
Parameters
[in]hashtableThe hash table
[in]keyThe hash key
Returns
The value

Simple wrapper to blGetHashValue() for extracting strings

  • 12.05.15 Original By: ACRM

Definition at line 620 of file hash.c.

BOOL blHashKeyDefined ( HASHTABLE hashtable,
char *  key 
)
Parameters
[in]hashtableThe hash table
[in]keyKey for which we are searching
Returns
Key found

Checks whether a hash key has been defined

  • 14.05.15 Original By: ACRM

Definition at line 775 of file hash.c.

HASHTABLE* blInitializeHash ( ULONG  hashsize)
Parameters
[in]hashsizeAn estimate of the size of the hash (or 0)
Returns
A pointer to a hashtable structure

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.

  • 12.05.15 Original By: ACRM

Definition at line 163 of file hash.c.

BOOL blSetHashValue ( HASHTABLE hashtable,
char *  key,
int  type,
  ... 
)
Parameters
[in]hashtableThe hash table
[in]keyThe hash key
[in]typeThe value type
[in]...The value
Returns
Success

Sets a value in the hash. 'type' is one of

  • HASHTYPE_INT
  • HASHTYPE_STRING
  • HASHTYPE_DOUBLE
  • HASHTYPE_CHAR
  • HASHTYPE_POINTER
  • 12.05.15 Original By: ACRM

Definition at line 350 of file hash.c.

BOOL blSetHashValueChar ( HASHTABLE hashtable,
char *  key,
char  value 
)
Parameters
[in]*hashtableThe hash table
[in]*keyThe key for the hash entry
[in]*valueThe value for the hash entry
Returns
Success

Wrapper to blSetHashValue()

  • 03.06.15 Original By: ACRM

Definition at line 532 of file hash.c.

BOOL blSetHashValueDouble ( HASHTABLE hashtable,
char *  key,
double  value 
)
Parameters
[in]*hashtableThe hash table
[in]*keyThe key for the hash entry
[in]*valueThe value for the hash entry
Returns
Success

Set a double value in a hash Wrapper to blSetHashValue()

  • 03.06.15 Original By: ACRM

Definition at line 493 of file hash.c.

BOOL blSetHashValueInt ( HASHTABLE hashtable,
char *  key,
int  value 
)
Parameters
[in]*hashtableThe hash table
[in]*keyThe key for the hash entry
[in]*valueThe value for the hash entry
Returns
Success

Set an int value in a hash Wrapper to blSetHashValue()

  • 03.06.15 Original By: ACRM

Definition at line 472 of file hash.c.

BOOL blSetHashValuePointer ( HASHTABLE hashtable,
char *  key,
BPTR  ptr 
)
Parameters
[in]*hashtableThe hash table
[in]*keyThe key for the hash entry
[in]*valueThe value for the hash entry
Returns
Success

Set a general pointer (BPTR) value in a hash Wrapper to blSetHashValue()

  • 03.06.15 Original By: ACRM

Definition at line 513 of file hash.c.

BOOL blSetHashValueString ( HASHTABLE hashtable,
char *  key,
char *  value 
)
Parameters
[in]*hashtableThe hash table
[in]*keyThe key for the hash entry
[in]*valueThe value for the hash entry
Returns
Success

Set a string value in a hash Wrapper to blSetHashValue()

  • 03.06.15 Original By: ACRM

Definition at line 452 of file hash.c.

char* blStrdup ( char *  instr)
Parameters
[in]instrA string
Returns
A malloc'd copy of the string

An implementation of SVr4, 4.3BSD, POSIX.1-2001 strdup() which is not standard ANSI C

  • 12.05.15 Original By: ACRM

Definition at line 157 of file stringutil.c.