1 |
< |
/* Copyright (c) 1994 Regents of the University of California */ |
2 |
< |
|
3 |
< |
/* SCCSid "$SunId$ LBL" */ |
4 |
< |
|
1 |
> |
/* RCSid $Id$ */ |
2 |
|
/* |
3 |
|
* Header file for general associative table lookup routines |
4 |
|
*/ |
5 |
+ |
#ifndef _RAD_LOOKUP_H_ |
6 |
+ |
#define _RAD_LOOKUP_H_ |
7 |
|
|
8 |
+ |
#ifdef __cplusplus |
9 |
+ |
extern "C" { |
10 |
+ |
#endif |
11 |
+ |
|
12 |
+ |
typedef void lut_free_t(void *p); |
13 |
+ |
typedef unsigned long lut_hashf_t(const void *); |
14 |
+ |
typedef int lut_keycmpf_t(const void *, const void *); |
15 |
+ |
|
16 |
|
typedef struct { |
17 |
< |
char *key; /* key name */ |
18 |
< |
long hval; /* key hash value (for efficiency) */ |
19 |
< |
char *data; /* pointer to client data */ |
17 |
> |
char *key; /* key name */ |
18 |
> |
unsigned long hval; /* key hash value (for efficiency) */ |
19 |
> |
char *data; /* pointer to client data */ |
20 |
|
} LUENT; |
21 |
|
|
22 |
|
typedef struct { |
23 |
< |
long (*hashf)(); /* key hash function */ |
24 |
< |
int (*keycmp)(); /* key comparison function */ |
25 |
< |
void (*freek)(); /* free a key */ |
26 |
< |
void (*freed)(); /* free the data */ |
27 |
< |
int tsiz; /* current table size */ |
28 |
< |
LUENT *tabl; /* table, if allocated */ |
29 |
< |
int ndel; /* number of deleted entries */ |
23 |
> |
lut_hashf_t *hashf; /* key hash function */ |
24 |
> |
lut_keycmpf_t *keycmp; /* key comparison function */ |
25 |
> |
lut_free_t *freek; /* free a key */ |
26 |
> |
lut_free_t *freed; /* free the data */ |
27 |
> |
int tsiz; /* current table size */ |
28 |
> |
LUENT *tabl; /* table, if allocated */ |
29 |
> |
int ndel; /* number of deleted entries */ |
30 |
|
} LUTAB; |
31 |
|
|
25 |
– |
#define LU_SINIT(fk,fd) {lu_shash,strcmp,(void (*)())(fk),\ |
26 |
– |
(void (*)())(fd),0,NULL,0} |
32 |
|
|
33 |
|
/* |
34 |
|
* The lu_init routine is called to initialize a table. The number of |
61 |
|
* The lu_delete routine frees an entry's data (if any) by calling |
62 |
|
* the freed member function, but does not free the key field. This |
63 |
|
* will be freed later during (or instead of) table reallocation. |
64 |
+ |
* It is therefore an error to reuse or do anything with the key |
65 |
+ |
* field after calling lu_delete. |
66 |
|
* |
67 |
+ |
* The lu_doall routine loops through every filled table entry, calling |
68 |
+ |
* the given function once on each entry. If a NULL pointer is passed |
69 |
+ |
* for this function, then lu_doall simply returns the total number of |
70 |
+ |
* active entries. Otherwise, it returns the sum of all the function |
71 |
+ |
* evaluations. |
72 |
+ |
* |
73 |
|
* The lu_done routine calls the given free function once for each |
74 |
|
* assigned table entry (i.e. each entry with an assigned key value). |
75 |
|
* The user must define these routines to free the key and the data |
77 |
|
* allocated table itself. |
78 |
|
*/ |
79 |
|
|
80 |
< |
extern int lu_init(); |
68 |
< |
extern LUENT *lu_find(); |
69 |
< |
extern void lu_delete(); |
70 |
< |
extern void lu_done(); |
71 |
< |
extern long lu_shash(); |
80 |
> |
typedef int lut_doallf_t(const LUENT *e, void *p); |
81 |
|
|
82 |
< |
extern int strcmp(); |
82 |
> |
extern lut_keycmpf_t lu_strcmp; |
83 |
> |
extern int lu_init(LUTAB *tbl, int nel); |
84 |
> |
extern unsigned long lu_shash(const void *s); |
85 |
> |
extern LUENT *lu_find(LUTAB *tbl, const char *key); |
86 |
> |
extern void lu_delete(LUTAB *tbl, const char *key); |
87 |
> |
extern int lu_doall(const LUTAB *tbl, lut_doallf_t *f, void *p); |
88 |
> |
extern void lu_done(LUTAB *tbl); |
89 |
> |
|
90 |
> |
#define LU_SINIT(fk,fd) {lu_shash,lu_strcmp,fk,fd,0,NULL,0} |
91 |
> |
|
92 |
> |
#ifdef __cplusplus |
93 |
> |
} |
94 |
> |
#endif |
95 |
> |
#endif /* _RAD_LOOKUP_H_ */ |
96 |
> |
|