Mercurial > hg > cdb
annotate cdb.h @ 13:0a35d8de4296
support profiling with gprof
| author | Henry S. Thompson <ht@inf.ed.ac.uk> |
|---|---|
| date | Fri, 07 Feb 2025 14:43:27 +0000 |
| parents | 0e21568dec72 |
| children | 70f4df5a7283 |
| rev | line source |
|---|---|
|
0
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
1 /* Public domain. */ |
|
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
2 |
|
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
3 #ifndef CDB_H |
|
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
4 #define CDB_H |
|
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
5 |
|
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
6 #include "uint32.h" |
|
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
7 |
|
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
8 #define CDB_HASHSTART 5381 |
|
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
9 extern uint32 cdb_hashadd(uint32,unsigned char); |
|
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
10 extern uint32 cdb_hash(char *,unsigned int); |
|
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
11 |
|
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
12 struct cdb { |
|
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
13 char *map; /* 0 if no map is available */ |
|
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
14 int fd; |
|
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
15 uint32 size; /* initialized if map is nonzero */ |
|
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
16 uint32 loop; /* number of hash slots searched under this key */ |
|
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
17 uint32 khash; /* initialized if loop is nonzero */ |
|
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
18 uint32 kpos; /* initialized if loop is nonzero */ |
|
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
19 uint32 hpos; /* initialized if loop is nonzero */ |
|
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
20 uint32 hslots; /* initialized if loop is nonzero */ |
|
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
21 uint32 dpos; /* initialized if cdb_findnext() returns 1 */ |
|
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
22 uint32 dlen; /* initialized if cdb_findnext() returns 1 */ |
|
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
23 } ; |
|
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
24 |
| 1 | 25 typedef struct cdb Cdb; |
| 26 | |
| 27 extern Cdb* cdb_new(void); | |
| 28 | |
|
12
0e21568dec72
allocate a Cdb struct rather than using a single static one,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
1
diff
changeset
|
29 extern void cdb_clear(Cdb *); |
| 1 | 30 extern void cdb_init(Cdb *,int fd); |
| 31 | |
| 32 extern int cdb_read(Cdb *,char *,unsigned int,uint32); | |
|
0
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
33 |
| 1 | 34 extern void cdb_findstart(Cdb *); |
| 35 extern int cdb_findnext(Cdb *,char *,unsigned int); | |
| 36 extern int cdb_find(Cdb *,char *,unsigned int); | |
|
0
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
37 |
|
12
0e21568dec72
allocate a Cdb struct rather than using a single static one,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
1
diff
changeset
|
38 /*extern uint32 cdb_pos(); |
|
0e21568dec72
allocate a Cdb struct rather than using a single static one,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
1
diff
changeset
|
39 extern uint32 cdb_len();*/ |
|
0e21568dec72
allocate a Cdb struct rather than using a single static one,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
1
diff
changeset
|
40 #define cdb_pos(c) ((c)->dpos) |
|
0e21568dec72
allocate a Cdb struct rather than using a single static one,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
1
diff
changeset
|
41 #define cdb_len(c) ((c)->dlen) |
| 1 | 42 |
|
12
0e21568dec72
allocate a Cdb struct rather than using a single static one,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
1
diff
changeset
|
43 /*extern char *cdb_mmap(); |
|
0e21568dec72
allocate a Cdb struct rather than using a single static one,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
1
diff
changeset
|
44 extern uint32 cdb_msize();*/ |
|
0e21568dec72
allocate a Cdb struct rather than using a single static one,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
1
diff
changeset
|
45 #define cdb_mmap(c) ((c)->map) |
|
0e21568dec72
allocate a Cdb struct rather than using a single static one,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
1
diff
changeset
|
46 #define cdb_msize(c) ((c)->size) |
|
0
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
47 |
|
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
48 #define cdb_datapos(c) ((c)->dpos) |
|
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
49 #define cdb_datalen(c) ((c)->dlen) |
|
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
50 |
|
2cb46628feec
from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
51 #endif |
