Lines Matching refs:c

39 static int cdb_make_write(struct cdb_make *c, char *buf, uint32 sz) {  in cdb_make_write()  argument
40 return php_stream_write(c->fp, buf, sz) == sz ? 0 : -1; in cdb_make_write()
44 static int cdb_posplus(struct cdb_make *c, uint32 len) in cdb_posplus() argument
46 uint32 newpos = c->pos + len; in cdb_posplus()
51 c->pos = newpos; in cdb_posplus()
57 int cdb_make_start(struct cdb_make *c, php_stream * f) in cdb_make_start() argument
59 c->head = 0; in cdb_make_start()
60 c->split = 0; in cdb_make_start()
61 c->hash = 0; in cdb_make_start()
62 c->numentries = 0; in cdb_make_start()
63 c->fp = f; in cdb_make_start()
64 c->pos = sizeof(c->final); in cdb_make_start()
65 if (php_stream_seek(f, c->pos, SEEK_SET) == -1) { in cdb_make_start()
69 return php_stream_tell(c->fp); in cdb_make_start()
74 int cdb_make_addend(struct cdb_make *c, unsigned int keylen, unsigned int datalen, uint32 h) in cdb_make_addend() argument
78 head = c->head; in cdb_make_addend()
84 head->next = c->head; in cdb_make_addend()
85 c->head = head; in cdb_make_addend()
88 head->hp[head->num].p = c->pos; in cdb_make_addend()
90 ++c->numentries; in cdb_make_addend()
91 if (cdb_posplus(c,8) == -1) in cdb_make_addend()
93 if (cdb_posplus(c, keylen) == -1) in cdb_make_addend()
95 if (cdb_posplus(c, datalen) == -1) in cdb_make_addend()
102 int cdb_make_addbegin(struct cdb_make *c, unsigned int keylen, unsigned int datalen) in cdb_make_addbegin() argument
117 if (cdb_make_write(c, buf, 8) != 0) in cdb_make_addbegin()
123 int cdb_make_add(struct cdb_make *c,char *key,unsigned int keylen,char *data,unsigned int datalen) in cdb_make_add() argument
125 if (cdb_make_addbegin(c, keylen, datalen) == -1) in cdb_make_add()
127 if (cdb_make_write(c, key, keylen) != 0) in cdb_make_add()
129 if (cdb_make_write(c, data, datalen) != 0) in cdb_make_add()
131 return cdb_make_addend(c, keylen, datalen, cdb_hash(key, keylen)); in cdb_make_add()
136 int cdb_make_finish(struct cdb_make *c) in cdb_make_finish() argument
149 c->count[i] = 0; in cdb_make_finish()
151 for (x = c->head; x; x = x->next) { in cdb_make_finish()
154 ++c->count[255 & x->hp[i].h]; in cdb_make_finish()
159 u = c->count[i] * 2; in cdb_make_finish()
164 memsize += c->numentries; /* no overflow possible up to now */ in cdb_make_finish()
172 c->split = (struct cdb_hp *) safe_emalloc(memsize, sizeof(struct cdb_hp), 0); in cdb_make_finish()
173 if (!c->split) in cdb_make_finish()
176 c->hash = c->split + c->numentries; in cdb_make_finish()
180 u += c->count[i]; /* bounded by numentries, so no overflow */ in cdb_make_finish()
181 c->start[i] = u; in cdb_make_finish()
184 for (x = c->head; x; x = x->next) { in cdb_make_finish()
187 c->split[--c->start[255 & x->hp[i].h]] = x->hp[i]; in cdb_make_finish()
191 count = c->count[i]; in cdb_make_finish()
194 uint32_pack(c->final + 8 * i,c->pos); in cdb_make_finish()
195 uint32_pack(c->final + 8 * i + 4,len); in cdb_make_finish()
198 c->hash[u].h = c->hash[u].p = 0; in cdb_make_finish()
200 hp = c->split + c->start[i]; in cdb_make_finish()
203 while (c->hash[where].p) in cdb_make_finish()
206 c->hash[where] = *hp++; in cdb_make_finish()
210 uint32_pack(buf, c->hash[u].h); in cdb_make_finish()
211 uint32_pack(buf + 4, c->hash[u].p); in cdb_make_finish()
212 if (cdb_make_write(c, buf, 8) != 0) in cdb_make_finish()
214 if (cdb_posplus(c, 8) == -1) in cdb_make_finish()
219 if (c->split) in cdb_make_finish()
220 efree(c->split); in cdb_make_finish()
222 for (x = c->head; x; c->head = x) { in cdb_make_finish()
224 efree(c->head); in cdb_make_finish()
227 if (php_stream_flush(c->fp) != 0) in cdb_make_finish()
229 php_stream_rewind(c->fp); in cdb_make_finish()
230 if (php_stream_tell(c->fp) != 0) in cdb_make_finish()
232 if (cdb_make_write(c, c->final, sizeof(c->final)) != 0) in cdb_make_finish()
234 return php_stream_flush(c->fp); in cdb_make_finish()