The outage for Sunday 24th November has been cancelled.
Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
hash.h
Go to the documentation of this file.
1 /************************************************************************/
2 /**
3 
4  \file hash.h
5 
6  \version V1.2
7  \date 26.11.15
8  \brief Defines for using hash functions
9 
10  \copyright (c) UCL / Dr. Andrew C. R. Martin 2015
11  \author Dr. Andrew C. R. Martin
12  \par
13  Institute of Structural & Molecular Biology,
14  University College London,
15  Gower Street,
16  London.
17  WC1E 6BT.
18  \par
19  andrew@bioinf.org.uk
20  andrew.martin@ucl.ac.uk
21 
22 **************************************************************************
23 
24  This code is NOT IN THE PUBLIC DOMAIN, but it may be copied
25  according to the conditions laid out in the accompanying file
26  COPYING.DOC.
27 
28  The code may be modified as required, but any modifications must be
29  documented so that the person responsible can be identified.
30 
31  The code may not be sold commercially or included as part of a
32  commercial product except as described in the file COPYING.DOC.
33 
34 **************************************************************************
35 
36  Description:
37  ============
38 
39 **************************************************************************
40 
41  Usage:
42  ======
43 
44 **************************************************************************
45 
46  Revision History:
47  =================
48 - V1.0 14.05.15 Original By: ACRM
49 - V1.1 03.06.15 Added wrappers to blSetHashValue()
50 - V1.2 26.11.15 Added check on __HASH_H__
51 
52 *************************************************************************/
53 #ifndef __HASH_H__
54 #define __HASH_H__
55 
56 /* Includes
57 */
58 #include <stdarg.h>
59 #include "SysDefs.h"
60 
61 /************************************************************************/
62 /* Defines and macros
63 */
64 #define DEF_HASHSIZE 1009 /* Must be a prime number */
65 #define HASHTYPE_STRING 0
66 #define HASHTYPE_INT 1
67 #define HASHTYPE_CHAR 2
68 #define HASHTYPE_DOUBLE 3
69 #define HASHTYPE_POINTER 4
70 
71 /* Internal hash structure for actual entries */
72 typedef struct _hashTab
73 {
74  struct _hashTab *next;
75  char *key;
76  char *string;
78  double doubleValue;
79  int intValue;
80  int type;
81  char charValue;
82 } _HASHENTRY;
83 
84 /* End user hash structure */
85 typedef struct
86 {
89 } HASHTABLE;
90 
91 
92 /************************************************************************/
93 /* Prototypes
94 */
96 void blFreeHash(HASHTABLE *hashtable);
97 char *blStrdup(char *instr);
98 void blFreeHashKeyList(char **keylist);
99 char **blGetHashKeyList(HASHTABLE *hashtable);
100 BOOL blSetHashValue(HASHTABLE *hashtable, char *key, int type, ...);
101 BPTR blGetHashValue(HASHTABLE *hashtable, char *key, int *type);
102 BOOL blDumpHash(FILE *out, HASHTABLE *hashtable);
103 BOOL blSetHashValueString(HASHTABLE *hashtable, char *key, char *value);
104 BOOL blSetHashValueInt(HASHTABLE *hashtable, char *key, int value);
105 BOOL blSetHashValueDouble(HASHTABLE *hashtable, char *key, double value);
106 BOOL blSetHashValuePointer(HASHTABLE *hashtable, char *key, BPTR ptr);
107 BOOL blSetHashValueChar(HASHTABLE *hashtable, char *key, char value);
108 int blGetHashValueInt(HASHTABLE *hashtable, char *key);
109 double blGetHashValueDouble(HASHTABLE *hashtable, char *key);
110 char blGetHashValueChar(HASHTABLE *hashtable, char *key);
111 char *blGetHashValueString(HASHTABLE *hashtable, char *key);
112 BPTR blGetHashValuePointer(HASHTABLE *hashtable, char *key);
113 BOOL blHashKeyDefined(HASHTABLE *hashtable, char *key);
114 void blDeleteHashKey(HASHTABLE *hashtable, char *key);
115 
116 #endif
BOOL blHashKeyDefined(HASHTABLE *hashtable, char *key)
Definition: hash.c:775
char * BPTR
Definition: SysDefs.h:60
HASHTABLE * blInitializeHash(ULONG hashsize)
Definition: hash.c:163
char blGetHashValueChar(HASHTABLE *hashtable, char *key)
Definition: hash.c:599
_HASHENTRY ** table
Definition: hash.h:87
BOOL blSetHashValueInt(HASHTABLE *hashtable, char *key, int value)
Definition: hash.c:472
short BOOL
Definition: SysDefs.h:64
BPTR blGetHashValuePointer(HASHTABLE *hashtable, char *key)
Definition: hash.c:638
BOOL blSetHashValue(HASHTABLE *hashtable, char *key, int type,...)
Definition: hash.c:350
Definition: hash.h:72
BPTR blGetHashValue(HASHTABLE *hashtable, char *key, int *type)
Definition: hash.c:668
struct _hashTab * next
Definition: hash.h:74
struct _hashTab _HASHENTRY
void blFreeHash(HASHTABLE *hashtable)
Definition: hash.c:293
BOOL blSetHashValueChar(HASHTABLE *hashtable, char *key, char value)
Definition: hash.c:532
char * blStrdup(char *instr)
Definition: stringutil.c:157
unsigned long ULONG
Definition: SysDefs.h:66
void blDeleteHashKey(HASHTABLE *hashtable, char *key)
Definition: hash.c:798
Definition: hash.h:85
double doubleValue
Definition: hash.h:78
char * blGetHashValueString(HASHTABLE *hashtable, char *key)
Definition: hash.c:620
int type
Definition: hash.h:80
char * string
Definition: hash.h:76
BPTR ptrValue
Definition: hash.h:77
BOOL blSetHashValueString(HASHTABLE *hashtable, char *key, char *value)
Definition: hash.c:452
int intValue
Definition: hash.h:79
BOOL blDumpHash(FILE *out, HASHTABLE *hashtable)
Definition: hash.c:720
void blFreeHashKeyList(char **keylist)
Definition: hash.c:200
BOOL blSetHashValueDouble(HASHTABLE *hashtable, char *key, double value)
Definition: hash.c:493
char ** blGetHashKeyList(HASHTABLE *hashtable)
Definition: hash.c:226
char charValue
Definition: hash.h:81
System-type variable type definitions.
ULONG size
Definition: hash.h:88
char * key
Definition: hash.h:75
BOOL blSetHashValuePointer(HASHTABLE *hashtable, char *key, BPTR ptr)
Definition: hash.c:513
double blGetHashValueDouble(HASHTABLE *hashtable, char *key)
Definition: hash.c:575
int blGetHashValueInt(HASHTABLE *hashtable, char *key)
Definition: hash.c:551