Lines Matching defs:db

179 bsd_clear(db)
180 struct bsd_db *db;
182 db->clear_count++;
183 db->max_ent = FIRST-1;
184 db->n_bits = BSD_INIT_BITS;
185 db->ratio = 0;
186 db->bytes_out = 0;
187 db->in_count = 0;
188 db->checkpoint = CHECK_GAP;
205 bsd_check(db)
206 struct bsd_db *db;
210 if (db->in_count >= db->checkpoint) {
212 if (db->in_count >= RATIO_MAX
213 || db->bytes_out >= RATIO_MAX) {
214 db->in_count -= db->in_count/4;
215 db->bytes_out -= db->bytes_out/4;
218 db->checkpoint = db->in_count + CHECK_GAP;
220 if (db->max_ent >= db->maxmaxcode) {
226 * db->in_count <= RATIO_MAX.
228 new_ratio = db->in_count << RATIO_SCALE_LOG;
229 if (db->bytes_out != 0)
230 new_ratio /= db->bytes_out;
232 if (new_ratio < db->ratio || new_ratio < 1 * RATIO_SCALE) {
233 bsd_clear(db);
236 db->ratio = new_ratio;
250 struct bsd_db *db = (struct bsd_db *) state;
253 stats->unc_bytes = db->uncomp_bytes;
254 stats->unc_packets = db->uncomp_count;
255 stats->comp_bytes = db->comp_bytes;
256 stats->comp_packets = db->comp_count;
257 stats->inc_bytes = db->incomp_bytes;
258 stats->inc_packets = db->incomp_count;
259 stats->ratio = db->in_count;
260 out = db->bytes_out;
276 struct bsd_db *db = (struct bsd_db *) state;
278 db->seqno = 0;
279 bsd_clear(db);
280 db->clear_count = 0;
293 struct bsd_db *db;
329 newlen = sizeof(*db) + (hsize-1) * (sizeof(db->dict[0]));
330 db = (struct bsd_db *) malloc(newlen);
331 if (!db)
333 memset(db, 0, sizeof(*db) - sizeof(db->dict));
336 db->lens = NULL;
338 db->lens = (u_short *) malloc((maxmaxcode+1) * sizeof(db->lens[0]));
339 if (!db->lens) {
340 free(db);
345 db->totlen = newlen;
346 db->hsize = hsize;
347 db->hshift = hshift;
348 db->maxmaxcode = maxmaxcode;
349 db->maxbits = bits;
351 return (void *) db;
358 struct bsd_db *db = (struct bsd_db *) state;
360 if (db->lens)
361 free(db->lens);
362 free(db);
377 bsd_init(db, options, opt_len, unit, hdrlen, mru, debug, decomp)
378 struct bsd_db *db;
387 || BSD_NBITS(options[2]) != db->maxbits
388 || decomp && db->lens == NULL)
394 db->lens[--i] = 1;
396 i = db->hsize;
398 db->dict[--i].codem1 = BADCODEM1;
399 db->dict[i].cptr = 0;
402 db->unit = unit;
403 db->hdrlen = hdrlen;
404 db->mru = mru;
406 db->debug = 1;
408 bsd_reset(db);
434 struct bsd_db *db = (struct bsd_db *) state;
435 u_int hshift = db->hshift;
436 u_int max_ent = db->max_ent;
437 u_int n_bits = db->n_bits;
457 db->seqno++;
466 dictp = &db->dict[hval];
480 if (hval >= db->hsize)
481 hval -= db->hsize;
482 dictp = &db->dict[hval];
493 if (max_ent < db->maxmaxcode) {
497 db->n_bits = ++n_bits;
502 dictp2 = &db->dict[max_ent+1];
503 if (db->dict[dictp2->cptr].codem1 == max_ent)
504 db->dict[dictp2->cptr].codem1 = BADCODEM1;
509 db->max_ent = ++max_ent;
510 db->lens[max_ent] = db->lens[ent]+1;
515 db->bytes_out += bitno/8;
516 db->in_count += ilen;
517 (void)bsd_check(db);
519 ++db->incomp_count;
520 db->incomp_bytes += ilen;
521 ++db->uncomp_count;
522 db->uncomp_bytes += ilen;
527 if (max_ent >= MAXCODE(n_bits) && max_ent < db->maxmaxcode)
528 db->n_bits++;
554 struct bsd_db *db = (struct bsd_db *) state;
555 u_int max_ent = db->max_ent;
558 u_int n_bits = db->n_bits;
578 if (seq != db->seqno++) {
579 if (db->debug)
581 db->unit, seq, db->seqno - 1);
585 wptr = dmp + db->hdrlen;
611 if (db->debug)
612 printf("bsd_decomp%d: bad CLEAR\n", db->unit);
615 bsd_clear(db);
620 if (incode > max_ent + 2 || incode > db->maxmaxcode
622 if (db->debug) {
624 db->unit, incode, oldcode);
626 max_ent, dlen, db->seqno);
640 codelen = db->lens[finchar];
642 if (explen > db->mru + 1) {
643 if (db->debug)
644 printf("bsd_decomp%d: ran out of mru\n", db->unit);
653 dictp = &db->dict[db->dict[finchar].cptr];
657 printf("bsd_decomp%d: fell off end of chain ", db->unit);
659 incode, finchar, db->dict[finchar].cptr, max_ent);
664 db->unit, incode, finchar);
666 db->dict[finchar].cptr, dictp->codem1);
678 db->unit, codelen, incode, max_ent);
691 if (oldcode != CLEAR && max_ent < db->maxmaxcode) {
697 hval = BSD_HASH(oldcode,finchar,db->hshift);
698 dictp = &db->dict[hval];
705 if (hval >= db->hsize)
706 hval -= db->hsize;
707 dictp = &db->dict[hval];
715 dictp2 = &db->dict[max_ent+1];
716 if (db->dict[dictp2->cptr].codem1 == max_ent) {
717 db->dict[dictp2->cptr].codem1 = BADCODEM1;
723 db->max_ent = ++max_ent;
724 db->lens[max_ent] = db->lens[oldcode]+1;
727 if (max_ent >= MAXCODE(n_bits) && max_ent < db->maxmaxcode) {
728 db->n_bits = ++n_bits;
734 *outlenp = wptr - (dmp + db->hdrlen);
740 db->bytes_out += ilen;
741 db->in_count += explen;
742 if (bsd_check(db) && db->debug) {
744 db->unit);
747 ++db->comp_count;
748 db->comp_bytes += ilen + BSD_OVHD;
749 ++db->uncomp_count;
750 db->uncomp_bytes += explen;