annotate cdb.h @ 17:d9c11148df3b default tip

shh...
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Thu, 28 Aug 2025 11:02:58 +0100
parents 70f4df5a7283
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
41b9b6a160d1 access functions,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
25 typedef struct cdb Cdb;
41b9b6a160d1 access functions,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
26
41b9b6a160d1 access functions,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
27 extern Cdb* cdb_new(void);
41b9b6a160d1 access functions,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
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
41b9b6a160d1 access functions,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
30 extern void cdb_init(Cdb *,int fd);
16
70f4df5a7283 add cdb_write,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
31 extern void cdb_init_nomap(Cdb *,int fd);
1
41b9b6a160d1 access functions,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
32
41b9b6a160d1 access functions,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
33 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
34
1
41b9b6a160d1 access functions,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
35 extern void cdb_findstart(Cdb *);
41b9b6a160d1 access functions,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
36 extern int cdb_findnext(Cdb *,char *,unsigned int);
41b9b6a160d1 access functions,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
37 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
38
16
70f4df5a7283 add cdb_write,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
39 extern int cdb_write(Cdb *c,int fd);
70f4df5a7283 add cdb_write,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 12
diff changeset
40
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
41 /*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
42 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
43 #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
44 #define cdb_len(c) ((c)->dlen)
1
41b9b6a160d1 access functions,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents: 0
diff changeset
45
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
46 /*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
47 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
48 #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
49 #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
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 #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
52 #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
53
2cb46628feec from cdb-0.75 per http://cr.yp.to/cdb.html,
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff changeset
54 #endif