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 |
+ |
#include <string.h> /* strcmp() */ |
9 |
+ |
|
10 |
+ |
#ifdef __cplusplus |
11 |
+ |
extern "C" { |
12 |
+ |
#endif |
13 |
+ |
|
14 |
|
typedef struct { |
15 |
< |
char *key; /* key name */ |
16 |
< |
long hval; /* key hash value (for efficiency) */ |
17 |
< |
char *data; /* pointer to client data */ |
15 |
> |
char *key; /* key name */ |
16 |
> |
unsigned long hval; /* key hash value (for efficiency) */ |
17 |
> |
char *data; /* pointer to client data */ |
18 |
|
} LUENT; |
19 |
|
|
20 |
|
typedef struct { |
21 |
< |
long (*hashf)(); /* key hash function */ |
22 |
< |
int (*keycmp)(); /* key comparison function */ |
23 |
< |
void (*freek)(); /* free a key */ |
24 |
< |
void (*freed)(); /* free the data */ |
25 |
< |
int tsiz; /* current table size */ |
26 |
< |
LUENT *tabl; /* table, if allocated */ |
27 |
< |
int ndel; /* number of deleted entries */ |
21 |
> |
unsigned long (*hashf)(); /* key hash function */ |
22 |
> |
int (*keycmp)(); /* key comparison function */ |
23 |
> |
void (*freek)(); /* free a key */ |
24 |
> |
void (*freed)(); /* free the data */ |
25 |
> |
int tsiz; /* current table size */ |
26 |
> |
LUENT *tabl; /* table, if allocated */ |
27 |
> |
int ndel; /* number of deleted entries */ |
28 |
|
} LUTAB; |
29 |
|
|
30 |
+ |
#undef strcmp |
31 |
|
#define LU_SINIT(fk,fd) {lu_shash,strcmp,(void (*)())(fk),\ |
32 |
|
(void (*)())(fd),0,NULL,0} |
33 |
|
|
65 |
|
* It is therefore an error to reuse or do anything with the key |
66 |
|
* field after calling lu_delete. |
67 |
|
* |
68 |
+ |
* The lu_doall routine loops through every filled table entry, calling |
69 |
+ |
* the given function once on each entry. If a NULL pointer is passed |
70 |
+ |
* for this function, then lu_doall simply returns the total number of |
71 |
+ |
* active entries. Otherwise, it returns the sum of all the function |
72 |
+ |
* evaluations. |
73 |
+ |
* |
74 |
|
* The lu_done routine calls the given free function once for each |
75 |
|
* assigned table entry (i.e. each entry with an assigned key value). |
76 |
|
* The user must define these routines to free the key and the data |
78 |
|
* allocated table itself. |
79 |
|
*/ |
80 |
|
|
81 |
< |
extern int lu_init(); |
82 |
< |
extern LUENT *lu_find(); |
83 |
< |
extern void lu_delete(); |
84 |
< |
extern void lu_done(); |
85 |
< |
extern long lu_shash(); |
81 |
> |
extern int lu_init(LUTAB *tbl, int nel); |
82 |
> |
extern unsigned long lu_shash(char *s); |
83 |
> |
extern LUENT *lu_find(LUTAB *tbl, char *key); |
84 |
> |
extern void lu_delete(LUTAB *tbl, char *key); |
85 |
> |
extern int lu_doall(LUTAB *tbl, int (*f)()); |
86 |
> |
extern void lu_done(LUTAB *tbl); |
87 |
|
|
88 |
< |
extern int strcmp(); |
88 |
> |
|
89 |
> |
#ifdef __cplusplus |
90 |
> |
} |
91 |
> |
#endif |
92 |
> |
#endif /* _RAD_LOOKUP_H_ */ |
93 |
> |
|