Lines Matching refs:db

194 bsd_clear(struct bsd_db *db)
196 db->clear_count++;
197 db->max_ent = FIRST-1;
198 db->n_bits = BSD_INIT_BITS;
199 db->ratio = 0;
200 db->bytes_out = 0;
201 db->in_count = 0;
202 db->checkpoint = CHECK_GAP;
219 bsd_check(struct bsd_db *db)
223 if (db->in_count >= db->checkpoint) {
225 if (db->in_count >= RATIO_MAX
226 || db->bytes_out >= RATIO_MAX) {
227 db->in_count -= db->in_count/4;
228 db->bytes_out -= db->bytes_out/4;
231 db->checkpoint = db->in_count + CHECK_GAP;
233 if (db->max_ent >= db->maxmaxcode) {
239 * db->in_count <= RATIO_MAX.
241 new_ratio = db->in_count << RATIO_SCALE_LOG;
242 if (db->bytes_out != 0)
243 new_ratio /= db->bytes_out;
245 if (new_ratio < db->ratio || new_ratio < 1 * RATIO_SCALE) {
246 bsd_clear(db);
249 db->ratio = new_ratio;
261 struct bsd_db *db = (struct bsd_db *) state;
264 stats->unc_bytes = db->uncomp_bytes;
265 stats->unc_packets = db->uncomp_count;
266 stats->comp_bytes = db->comp_bytes;
267 stats->comp_packets = db->comp_count;
268 stats->inc_bytes = db->incomp_bytes;
269 stats->inc_packets = db->incomp_count;
270 stats->ratio = db->in_count;
271 out = db->bytes_out;
286 struct bsd_db *db = (struct bsd_db *) state;
288 db->seqno = 0;
289 bsd_clear(db);
290 db->clear_count = 0;
301 struct bsd_db *db;
337 newlen = sizeof(*db) + (hsize-1) * (sizeof(db->dict[0]));
338 db = (struct bsd_db *) malloc(newlen);
339 if (!db)
341 memset(db, 0, sizeof(*db) - sizeof(db->dict));
344 db->lens = NULL;
346 db->lens = (u_short *) malloc((maxmaxcode+1) * sizeof(db->lens[0]));
347 if (!db->lens) {
348 free(db);
353 db->totlen = newlen;
354 db->hsize = hsize;
355 db->hshift = hshift;
356 db->maxmaxcode = maxmaxcode;
357 db->maxbits = bits;
359 return (void *) db;
365 struct bsd_db *db = (struct bsd_db *) state;
367 if (db->lens)
368 free(db->lens);
369 free(db);
382 bsd_init(struct bsd_db *db, u_char *options, int opt_len, int unit,
390 || BSD_NBITS(options[2]) != db->maxbits
391 || (decomp && db->lens == NULL))
397 db->lens[--i] = 1;
399 i = db->hsize;
401 db->dict[--i].codem1 = BADCODEM1;
402 db->dict[i].cptr = 0;
405 db->unit = unit;
406 db->hdrlen = hdrlen;
407 db->mru = mru;
409 db->debug = 1;
411 bsd_reset(db);
432 struct bsd_db *db = (struct bsd_db *) state;
433 u_int hshift = db->hshift;
434 u_int max_ent = db->max_ent;
435 u_int n_bits = db->n_bits;
455 db->seqno++;
464 dictp = &db->dict[hval];
478 if (hval >= db->hsize)
479 hval -= db->hsize;
480 dictp = &db->dict[hval];
491 if (max_ent < db->maxmaxcode) {
495 db->n_bits = ++n_bits;
500 dictp2 = &db->dict[max_ent+1];
501 if (db->dict[dictp2->cptr].codem1 == max_ent)
502 db->dict[dictp2->cptr].codem1 = BADCODEM1;
507 db->max_ent = ++max_ent;
508 db->lens[max_ent] = db->lens[ent]+1;
513 db->bytes_out += bitno/8;
514 db->in_count += ilen;
515 (void)bsd_check(db);
517 ++db->incomp_count;
518 db->incomp_bytes += ilen;
519 ++db->uncomp_count;
520 db->uncomp_bytes += ilen;
525 if (max_ent >= MAXCODE(n_bits) && max_ent < db->maxmaxcode)
526 db->n_bits++;
549 struct bsd_db *db = (struct bsd_db *) state;
550 u_int max_ent = db->max_ent;
553 u_int n_bits = db->n_bits;
573 if (seq != db->seqno++) {
574 if (db->debug)
576 db->unit, seq, db->seqno - 1);
580 wptr = (*out)->buf + db->hdrlen;
606 if (db->debug)
607 printf("bsd_decomp%d: bad CLEAR\n", db->unit);
610 bsd_clear(db);
615 if (incode > max_ent + 2 || incode > db->maxmaxcode
617 if (db->debug) {
619 db->unit, incode, oldcode);
621 max_ent, db->seqno);
635 codelen = db->lens[finchar];
637 if (explen > db->mru + 1) {
638 if (db->debug)
639 printf("bsd_decomp%d: ran out of mru\n", db->unit);
648 dictp = &db->dict[db->dict[finchar].cptr];
652 printf("bsd_decomp%d: fell off end of chain ", db->unit);
654 incode, finchar, db->dict[finchar].cptr, max_ent);
659 db->unit, incode, finchar);
661 db->dict[finchar].cptr, dictp->codem1);
673 db->unit, codelen, incode, max_ent);
686 if (oldcode != CLEAR && max_ent < db->maxmaxcode) {
692 hval = BSD_HASH(oldcode,finchar,db->hshift);
693 dictp = &db->dict[hval];
700 if (hval >= db->hsize)
701 hval -= db->hsize;
702 dictp = &db->dict[hval];
710 dictp2 = &db->dict[max_ent+1];
711 if (db->dict[dictp2->cptr].codem1 == max_ent) {
712 db->dict[dictp2->cptr].codem1 = BADCODEM1;
718 db->max_ent = ++max_ent;
719 db->lens[max_ent] = db->lens[oldcode]+1;
722 if (max_ent >= MAXCODE(n_bits) && max_ent < db->maxmaxcode) {
723 db->n_bits = ++n_bits;
729 (*out)->len = wptr - ((*out)->buf + db->hdrlen);
735 db->bytes_out += ilen;
736 db->in_count += explen;
737 if (bsd_check(db) && db->debug) {
739 db->unit);
742 ++db->comp_count;
743 db->comp_bytes += ilen + BSD_OVHD;
744 ++db->uncomp_count;
745 db->uncomp_bytes += explen;