2 This file is part of the software library CADLIB written by Conrad Ziesler
3 Copyright 2003, Conrad Ziesler, all rights reserved.
5 *************************
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 /* hash.h, hash function headers
30 typedef unsigned char uchar
;
36 typedef unsigned int uint
;
40 /**********************************/
41 /* HASH TABLES ********************/
43 typedef struct hashbin_st
45 struct hashbin_st
*next
;
47 /* alloc in place data here */
50 typedef struct hash_st
53 uint (*hashfunc
)(int max
, void *data
, int size
);
54 int (*hashcmp
)(int sa
, void *a
, int sb
, void *b
);
61 #define hash_bin2user(p) ((void *)(((char *)p)+sizeof(hashbin_t)))
62 #define hash_user2bin(p) ((hashbin_t *)((void *)(((char *)p)-sizeof(hashbin_t))))
63 #define hash_forall(h,i,p) for((i)=0;(i)<(h)->qbin;(i)++) for((p)=(h)->bins[(i)];(p)!=NULL;(p)=(p)->next)
64 #define hash_malloc(h,s) hash_alloc((h),malloc((s)))
69 uint (*hashfunc
)(int max
, void *data
, int size
),
70 int (*hashcmp
)(int sizea
, void *a
, int sizeb
, void *b
)
73 void hash_free (hash_t
*h
); /* free hash table and associated memory */
74 void *hash_find (hash_t
*h
, void *key
, int ksize
); /* find key in table */
75 void *hash_add (hash_t
*h
, void *key
, int ksize
); /* add key of size to table */
76 void *hash_alloc (hash_t
*h
, void *data
); /* add data to list of allocs */
77 int hash_size (void *user
); /* just return size of associated bin */
79 /* ----- some predefined hash clients --------- */
81 unsigned int hash_strhash(int max
, void *data
, int size
);
82 unsigned int hash_binhash(int max
, void *data
, int size
);
84 /* ptr,flag, in place string
85 do strcmp on strings, hash on the string only
86 store a payload of a ptr and a flag
89 typedef struct hash_ptrflagstr_st
93 /* inplace string to follow */
94 }hclient_ptrflagstr_t
;
96 uint
hclient_ptrflagstr_hash(int max
, void *data
, int size
);
101 straight binary comparison and hash
104 uint
hclient_bobject_hash(int max
, void *data
, int size
);
105 int hclient_bobject_cmp(int sizea
, void *a
, int sizeb
, void *b
);