bglibs: cdb.h Source File

bglibs

cdb.h
1 #ifndef CDB_H
2 #define CDB_H
3
4 #include "iobuf.h"
5 #include "sysdeps.h"
6
7 struct str;
8
9 #define CDB_HASHSTART 5381
10 extern uint32 cdb_hashadd(uint32,unsigned char);
11 extern uint32 cdb_hash(const char *,unsigned int);
12
13 struct cdb {
14 char *map; /* 0 if no map is available */
15 int fd;
16 uint32 size; /* initialized if map is nonzero */
17 uint32 loop; /* number of hash slots searched under this key */
18 uint32 khash; /* initialized if loop is nonzero */
19 uint32 kpos; /* initialized if loop is nonzero */
20 uint32 hpos; /* initialized if loop is nonzero */
21 uint32 hslots; /* initialized if loop is nonzero */
22 uint32 dpos; /* initialized if cdb_findnext() returns 1 */
23 uint32 dlen; /* initialized if cdb_findnext() returns 1 */
24
25 uint32 nextrec; /* initialized if cdb_{first,next}rec() returns 1 */
26 /* (uint32)-1 means no next record */
27 };
28
29 extern void cdb_free(struct cdb *);
30 extern void cdb_init(struct cdb *,int fd);
31
32 extern int cdb_read(struct cdb *,unsigned char *,unsigned int,uint32);
33
34 extern void cdb_findstart(struct cdb *);
35 extern int cdb_findnext(struct cdb *,const char *,unsigned int);
36 extern int cdb_find(struct cdb *,const char *,unsigned int);
37
38 #define cdb_datapos(c) ((c)->dpos)
39 #define cdb_datalen(c) ((c)->dlen)
40
41 extern int cdb_get(struct cdb*, const struct str* key, struct str* data);
42 extern int cdb_getnext(struct cdb*, const struct str* key, struct str* data);
43
44 struct cdb_hp;
45 struct cdb_hplist;
46
47 struct cdb_make {
48 unsigned char final[2048];
49 uint32 count[256];
50 uint32 start[256];
51 struct cdb_hplist *head;
52 struct cdb_hp *split; /* includes space for hash */
53 struct cdb_hp *hash;
54 uint32 numentries;
55 obuf b;
56 uint32 pos;
57 int fd;
58 } ;
59
60 extern int cdb_make_start(struct cdb_make *,int);
61 extern int cdb_make_addbegin(struct cdb_make *,unsigned int,unsigned int);
62 extern int cdb_make_addend(struct cdb_make *,unsigned int,unsigned int,uint32);
63 extern int cdb_make_add(struct cdb_make *,const char *,unsigned int,const char *,unsigned int);
64 extern int cdb_make_finish(struct cdb_make *);
65
66 #endif
cdb
Definition: cdb.h:13
obuf
Definition: obuf.h:21
str
Definition: str.h:30
cdb_make
Definition: cdb.h:47