Lines Matching defs:db

165 static void	bsd_clear(struct bsd_db *db);
166 static int bsd_check(struct bsd_db *db);
168 static int bsd_init_comp_db(struct bsd_db *db, u_char *options,
233 bsd_clear(db)
234 struct bsd_db *db;
236 db->clear_count++;
237 db->max_ent = FIRST-1;
238 db->n_bits = BSD_INIT_BITS;
239 db->ratio = 0;
240 db->bytes_out = 0;
241 db->in_count = 0;
242 db->checkpoint = CHECK_GAP;
259 bsd_check(db)
260 struct bsd_db *db;
264 if (db->in_count >= db->checkpoint) {
266 if (db->in_count >= RATIO_MAX
267 || db->bytes_out >= RATIO_MAX) {
268 db->in_count -= db->in_count/4;
269 db->bytes_out -= db->bytes_out/4;
272 db->checkpoint = db->in_count + CHECK_GAP;
274 if (db->max_ent >= db->maxmaxcode) {
280 * db->in_count <= RATIO_MAX.
282 new_ratio = db->in_count << RATIO_SCALE_LOG;
283 if (db->bytes_out != 0)
284 new_ratio /= db->bytes_out;
286 if (new_ratio < db->ratio || new_ratio < 1 * RATIO_SCALE) {
287 bsd_clear(db);
290 db->ratio = new_ratio;
304 struct bsd_db *db = (struct bsd_db *) state;
307 stats->unc_bytes = db->uncomp_bytes;
308 stats->unc_packets = db->uncomp_count;
309 stats->comp_bytes = db->comp_bytes;
310 stats->comp_packets = db->comp_count;
311 stats->inc_bytes = db->incomp_bytes;
312 stats->inc_packets = db->incomp_count;
313 stats->ratio = db->in_count;
314 out = db->bytes_out;
330 struct bsd_db *db = (struct bsd_db *) state;
332 db->seqno = 0;
333 bsd_clear(db);
334 db->clear_count = 0;
347 struct bsd_db *db;
383 newlen = sizeof(*db) + (hsize-1) * (sizeof(db->dict[0]));
384 MALLOC(db, struct bsd_db *, newlen, M_DEVBUF, M_NOWAIT);
385 if (!db)
387 bzero(db, sizeof(*db) - sizeof(db->dict));
390 db->lens = NULL;
392 MALLOC(db->lens, u_int16_t *, (maxmaxcode+1) * sizeof(db->lens[0]),
394 if (!db->lens) {
395 FREE(db, M_DEVBUF);
400 db->totlen = newlen;
401 db->hsize = hsize;
402 db->hshift = hshift;
403 db->maxmaxcode = maxmaxcode;
404 db->maxbits = bits;
406 return (void *) db;
413 struct bsd_db *db = (struct bsd_db *) state;
415 if (db->lens)
416 FREE(db->lens, M_DEVBUF);
417 FREE(db, M_DEVBUF);
440 bsd_init_comp_db(db, options, opt_len, unit, hdrlen, mru, debug, decomp)
441 struct bsd_db *db;
450 || BSD_NBITS(options[2]) != db->maxbits
451 || (decomp && db->lens == NULL))
457 db->lens[--i] = 1;
459 i = db->hsize;
461 db->dict[--i].codem1 = BADCODEM1;
462 db->dict[i].cptr = 0;
465 db->unit = unit;
466 db->hdrlen = hdrlen;
467 db->mru = mru;
471 db->debug = 1;
473 bsd_reset(db);
512 struct bsd_db *db = (struct bsd_db *) state;
513 int hshift = db->hshift;
514 u_int max_ent = db->max_ent;
515 u_int n_bits = db->n_bits;
578 if (maxolen + db->hdrlen > MLEN)
580 m->m_data += db->hdrlen;
595 *wptr++ = db->seqno >> 8;
596 *wptr++ = db->seqno;
598 ++db->seqno;
620 dictp = &db->dict[hval];
634 if (hval >= db->hsize)
635 hval -= db->hsize;
636 dictp = &db->dict[hval];
647 if (max_ent < db->maxmaxcode) {
651 db->n_bits = ++n_bits;
656 dictp2 = &db->dict[max_ent+1];
657 if (db->dict[dictp2->cptr].codem1 == max_ent)
658 db->dict[dictp2->cptr].codem1 = BADCODEM1;
663 db->max_ent = ++max_ent;
669 db->bytes_out += olen;
670 db->in_count += ilen;
672 ++db->bytes_out; /* count complete bytes */
674 if (bsd_check(db))
693 if (max_ent >= MAXCODE(n_bits) && max_ent < db->maxmaxcode)
694 db->n_bits++;
696 db->uncomp_bytes += ilen;
697 ++db->uncomp_count;
704 ++db->incomp_count;
705 db->incomp_bytes += ilen;
707 ++db->comp_count;
708 db->comp_bytes += olen + BSD_OVHD;
726 struct bsd_db *db = (struct bsd_db *) state;
727 u_int hshift = db->hshift;
728 u_int max_ent = db->max_ent;
729 u_int n_bits = db->n_bits;
749 db->seqno++;
768 dictp = &db->dict[hval];
782 if (hval >= db->hsize)
783 hval -= db->hsize;
784 dictp = &db->dict[hval];
795 if (max_ent < db->maxmaxcode) {
799 db->n_bits = ++n_bits;
804 dictp2 = &db->dict[max_ent+1];
805 if (db->dict[dictp2->cptr].codem1 == max_ent)
806 db->dict[dictp2->cptr].codem1 = BADCODEM1;
811 db->max_ent = ++max_ent;
812 db->lens[max_ent] = db->lens[ent]+1;
818 db->bytes_out += bitno/8;
819 db->in_count += ilen;
820 (void)bsd_check(db);
822 ++db->incomp_count;
823 db->incomp_bytes += ilen;
824 ++db->uncomp_count;
825 db->uncomp_bytes += ilen;
830 if (max_ent >= MAXCODE(n_bits) && max_ent < db->maxmaxcode)
831 db->n_bits++;
856 struct bsd_db *db = (struct bsd_db *) state;
857 u_int max_ent = db->max_ent;
860 u_int n_bits = db->n_bits;
897 if (seq != db->seqno) {
898 if (db->debug)
900 db->unit, seq, db->seqno - 1);
903 ++db->seqno;
915 dmp->m_data += db->hdrlen;
970 if (db->debug)
971 printf("bsd_decomp%d: bad CLEAR\n", db->unit);
975 bsd_clear(db);
980 if (incode > max_ent + 2 || incode > db->maxmaxcode
983 if (db->debug) {
985 db->unit, incode, oldcode);
987 max_ent, explen, db->seqno);
1001 codelen = db->lens[finchar];
1003 if (explen > db->mru + 1) {
1005 if (db->debug) {
1006 printf("bsd_decomp%d: ran out of mru\n", db->unit);
1047 dictp = &db->dict[db->dict[finchar].cptr];
1060 db->unit, codelen, incode, max_ent);
1073 if (oldcode != CLEAR && max_ent < db->maxmaxcode) {
1079 hval = BSD_HASH(oldcode,finchar,db->hshift);
1080 dictp = &db->dict[hval];
1087 if (hval >= db->hsize)
1088 hval -= db->hsize;
1089 dictp = &db->dict[hval];
1097 dictp2 = &db->dict[max_ent+1];
1098 if (db->dict[dictp2->cptr].codem1 == max_ent) {
1099 db->dict[dictp2->cptr].codem1 = BADCODEM1;
1105 db->max_ent = ++max_ent;
1106 db->lens[max_ent] = db->lens[oldcode]+1;
1109 if (max_ent >= MAXCODE(n_bits) && max_ent < db->maxmaxcode) {
1110 db->n_bits = ++n_bits;
1122 db->bytes_out += ilen;
1123 db->in_count += explen;
1124 if (bsd_check(db) && db->debug) {
1126 db->unit);
1129 ++db->comp_count;
1130 db->comp_bytes += ilen + BSD_OVHD;
1131 ++db->uncomp_count;
1132 db->uncomp_bytes += explen;
1140 printf("bsd_decomp%d: fell off end of chain ", db->unit);
1142 incode, finchar, db->dict[finchar].cptr, max_ent);
1145 db->unit, incode, finchar);
1147 db->dict[finchar].cptr, dictp->codem1);