1 #pragma src "/sys/src/libndb"
5 * this include file requires includes of <u.h> and <bio.h>
7 typedef struct Ndb Ndb;
8 typedef struct Ndbtuple Ndbtuple;
9 typedef struct Ndbhf Ndbhf;
10 typedef struct Ndbs Ndbs;
11 typedef struct Ndbcache Ndbcache;
13 #pragma incomplete Ndbhf
14 #pragma incomplete Ndbcache
18 Ndbalen= 32, /* max attribute length */
19 Ndbvlen= 64, /* max value length */
29 Biobufhdr b; /* buffered input file */
30 uchar buf[256]; /* and its buffer */
32 ulong mtime; /* mtime of db file */
33 Qid qid; /* qid of db file */
34 char file[128]; /* path name of db file */
35 ulong length; /* length of db file */
37 int nohash; /* don't look for hash files */
38 Ndbhf *hf; /* open hash files */
40 int ncache; /* size of tuple cache */
41 Ndbcache *cache; /* cached entries */
45 * a parsed entry, doubly linked
49 char attr[Ndbalen]; /* attribute name */
50 char *val; /* value(s) */
51 Ndbtuple *entry; /* next tuple in this entry */
52 Ndbtuple *line; /* next tuple on this line */
53 ulong ptr; /* (for the application - starts 0) */
54 char valbuf[Ndbvlen]; /* initial allocation for value */
58 * each hash file is of the form
60 * +---------------------------------------+
61 * | mtime of db file (4 bytes) |
62 * +---------------------------------------+
63 * | size of table (in entries - 4 bytes) |
64 * +---------------------------------------+
66 * +---------------------------------------+
68 * +---------------------------------------+
70 * hash collisions are resolved using chained entries added to the
71 * the end of the hash table.
73 * Hash entries are of the form
75 * +-------------------------------+
76 * | offset (3 bytes) |
77 * +-------------------------------+
79 * Chain entries are of the form
81 * +-------------------------------+
82 * | offset1 (3 bytes) |
83 * +-------------------------------+
84 * | offset2 (3 bytes) |
85 * +-------------------------------+
87 * The top bit of an offset set to 1 indicates a pointer to a hash chain entry.
89 #define NDBULLEN 4 /* unsigned long length in bytes */
90 #define NDBPLEN 3 /* pointer length in bytes */
91 #define NDBHLEN (2*NDBULLEN) /* hash file header length in bytes */
94 * finger pointing to current point in a search
98 Ndb *db; /* data base file being searched */
99 Ndbhf *hf; /* hash file being searched */
101 ulong ptr; /* current pointer */
102 ulong ptr1; /* next pointer */
103 Ndbtuple *t; /* last attribute value pair found */
107 * bit defs for pointers in hash files
109 #define NDBSPEC (1<<23)
110 #define NDBCHAIN NDBSPEC /* points to a collision chain */
111 #define NDBNAP (NDBSPEC|1) /* not a pointer */
114 * macros for packing and unpacking pointers
116 #define NDBPUTP(v,a) { (a)[0] = v; (a)[1] = (v)>>8; (a)[2] = (v)>>16; }
117 #define NDBGETP(a) ((a)[0] | ((a)[1]<<8) | ((a)[2]<<16))
120 * macros for packing and unpacking unsigned longs
122 #define NDBPUTUL(v,a) { (a)[0] = v; (a)[1] = (v)>>8; (a)[2] = (v)>>16; (a)[3] = (v)>>24; }
123 #define NDBGETUL(a) ((a)[0] | ((a)[1]<<8) | ((a)[2]<<16) | ((a)[3]<<24))
127 Ndbtuple* csgetval(char*, char*, char*, char*, char*);
128 char* csgetvalue(char*, char*, char*, char*, Ndbtuple**);
129 Ndbtuple* csipinfo(char*, char*, char*, char**, int);
130 Ndbtuple* dnsquery(char*, char*, char*);
132 Ndb* ndbcat(Ndb*, Ndb*);
133 int ndbchanged(Ndb*);
135 Ndbtuple* ndbconcatenate(Ndbtuple*, Ndbtuple*);
136 Ndbtuple* ndbdiscard(Ndbtuple*, Ndbtuple*);
137 void ndbfree(Ndbtuple*);
138 Ndbtuple* ndbgetipaddr(Ndb*, char*);
139 Ndbtuple* ndbgetval(Ndb*, Ndbs*, char*, char*, char*, char*);
140 char* ndbgetvalue(Ndb*, Ndbs*, char*, char*, char*, Ndbtuple**);
141 Ndbtuple* ndbfindattr(Ndbtuple*, Ndbtuple*, char*);
142 ulong ndbhash(char*, int);
143 Ndbtuple* ndbipinfo(Ndb*, char*, char*, char**, int);
144 Ndbtuple* ndblookval(Ndbtuple*, Ndbtuple*, char*, char*);
145 Ndbtuple* ndbnew(char*, char*);
147 Ndbtuple* ndbparse(Ndb*);
149 Ndbtuple* ndbreorder(Ndbtuple*, Ndbtuple*);
150 Ndbtuple* ndbsearch(Ndb*, Ndbs*, char*, char*);
151 void ndbsetval(Ndbtuple*, char*, int);
152 Ndbtuple* ndbsnext(Ndbs*, char*, char*);
153 Ndbtuple* ndbsubstitute(Ndbtuple*, Ndbtuple*, Ndbtuple*);
154 void ndbsetmalloctag(Ndbtuple*, uintptr);