Corrected a long-standing error in which ending text with a literal
[xcircuit.git] / spiceparser / hash.h
blob4c2ef79a895c2a7cb4642d42198f541296c7e6f1
1 /********************
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
20 ******************/
21 /* hash.h, hash function headers
22 Conrad Ziesler
26 #ifndef __HASH_H__
27 #define __HASH_H__
29 #ifndef UCHAR
30 typedef unsigned char uchar;
31 #define UCHAR
32 #endif
35 #ifndef _SYS_TYPES_H
36 typedef unsigned int uint;
37 #endif
40 /**********************************/
41 /* HASH TABLES ********************/
43 typedef struct hashbin_st
45 struct hashbin_st *next;
46 int size;
47 /* alloc in place data here */
48 }hashbin_t;
50 typedef struct hash_st
52 int uniq;
53 uint (*hashfunc)(int max, void *data, int size);
54 int (*hashcmp)(int sa, void *a, int sb, void *b);
55 int qbin;
56 hashbin_t **bins;
57 int qalloc;
58 void **alloc;
59 }hash_t;
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)))
67 hash_t *hash_new (
68 int qbins,
69 uint (*hashfunc)(int max, void *data, int size),
70 int (*hashcmp)(int sizea, void *a, int sizeb, void *b)
71 ) ;
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
91 void *ptr;
92 char flag;
93 /* inplace string to follow */
94 }hclient_ptrflagstr_t;
96 uint hclient_ptrflagstr_hash(int max, void *data, int size);
100 /* binary object
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);
109 #endif