Lines Matching refs:db

200 bsd_clear(struct bsd_db *db)  in bsd_clear()  argument
202 db->clear_count++; in bsd_clear()
203 db->max_ent = FIRST-1; in bsd_clear()
204 db->n_bits = BSD_INIT_BITS; in bsd_clear()
205 db->ratio = 0; in bsd_clear()
206 db->bytes_out = 0; in bsd_clear()
207 db->in_count = 0; in bsd_clear()
208 db->checkpoint = CHECK_GAP; in bsd_clear()
225 bsd_check(struct bsd_db *db) in bsd_check() argument
229 if (db->in_count >= db->checkpoint) { in bsd_check()
231 if (db->in_count >= RATIO_MAX in bsd_check()
232 || db->bytes_out >= RATIO_MAX) { in bsd_check()
233 db->in_count -= db->in_count/4; in bsd_check()
234 db->bytes_out -= db->bytes_out/4; in bsd_check()
237 db->checkpoint = db->in_count + CHECK_GAP; in bsd_check()
239 if (db->max_ent >= db->maxmaxcode) { in bsd_check()
247 new_ratio = db->in_count << RATIO_SCALE_LOG; in bsd_check()
248 if (db->bytes_out != 0) in bsd_check()
249 new_ratio /= db->bytes_out; in bsd_check()
251 if (new_ratio < db->ratio || new_ratio < 1 * RATIO_SCALE) { in bsd_check()
252 bsd_clear(db); in bsd_check()
255 db->ratio = new_ratio; in bsd_check()
267 struct bsd_db *db = (struct bsd_db *) state; in bsd_comp_stats() local
270 stats->unc_bytes = db->uncomp_bytes; in bsd_comp_stats()
271 stats->unc_packets = db->uncomp_count; in bsd_comp_stats()
272 stats->comp_bytes = db->comp_bytes; in bsd_comp_stats()
273 stats->comp_packets = db->comp_count; in bsd_comp_stats()
274 stats->inc_bytes = db->incomp_bytes; in bsd_comp_stats()
275 stats->inc_packets = db->incomp_count; in bsd_comp_stats()
276 stats->ratio = db->in_count; in bsd_comp_stats()
277 out = db->bytes_out; in bsd_comp_stats()
292 struct bsd_db *db = (struct bsd_db *) state; in bsd_reset() local
294 db->seqno = 0; in bsd_reset()
295 bsd_clear(db); in bsd_reset()
296 db->clear_count = 0; in bsd_reset()
307 struct bsd_db *db; in bsd_alloc() local
343 newlen = sizeof(*db) + (hsize-1) * (sizeof(db->dict[0])); in bsd_alloc()
344 db = malloc(newlen, M_DEVBUF, M_NOWAIT|M_ZERO); in bsd_alloc()
345 if (!db) in bsd_alloc()
349 db->lens = NULL; in bsd_alloc()
351 db->lens = malloc((maxmaxcode+1) * sizeof(db->lens[0]), in bsd_alloc()
353 if (!db->lens) { in bsd_alloc()
354 free(db, M_DEVBUF); in bsd_alloc()
359 db->totlen = newlen; in bsd_alloc()
360 db->hsize = hsize; in bsd_alloc()
361 db->hshift = hshift; in bsd_alloc()
362 db->maxmaxcode = maxmaxcode; in bsd_alloc()
363 db->maxbits = bits; in bsd_alloc()
365 return (void *) db; in bsd_alloc()
371 struct bsd_db *db = (struct bsd_db *) state; in bsd_free() local
373 if (db->lens) in bsd_free()
374 free(db->lens, M_DEVBUF); in bsd_free()
375 free(db, M_DEVBUF); in bsd_free()
394 bsd_init(struct bsd_db *db, u_char *options, int opt_len, int unit, int hdrlen, in bsd_init() argument
402 || BSD_NBITS(options[2]) != db->maxbits in bsd_init()
403 || (decomp && db->lens == NULL)) in bsd_init()
409 db->lens[--i] = 1; in bsd_init()
411 i = db->hsize; in bsd_init()
413 db->dict[--i].codem1 = BADCODEM1; in bsd_init()
414 db->dict[i].cptr = 0; in bsd_init()
417 db->unit = unit; in bsd_init()
418 db->hdrlen = hdrlen; in bsd_init()
419 db->mru = mru; in bsd_init()
423 db->debug = 1; in bsd_init()
425 bsd_reset(db); in bsd_init()
458 struct bsd_db *db = (struct bsd_db *) state; in bsd_compress() local
459 int hshift = db->hshift; in bsd_compress()
460 u_int max_ent = db->max_ent; in bsd_compress()
461 u_int n_bits = db->n_bits; in bsd_compress()
524 if (maxolen + db->hdrlen > MLEN) in bsd_compress()
526 m->m_data += db->hdrlen; in bsd_compress()
541 *wptr++ = db->seqno >> 8; in bsd_compress()
542 *wptr++ = db->seqno; in bsd_compress()
544 ++db->seqno; in bsd_compress()
566 dictp = &db->dict[hval]; in bsd_compress()
580 if (hval >= db->hsize) in bsd_compress()
581 hval -= db->hsize; in bsd_compress()
582 dictp = &db->dict[hval]; in bsd_compress()
593 if (max_ent < db->maxmaxcode) { in bsd_compress()
597 db->n_bits = ++n_bits; in bsd_compress()
602 dictp2 = &db->dict[max_ent+1]; in bsd_compress()
603 if (db->dict[dictp2->cptr].codem1 == max_ent) in bsd_compress()
604 db->dict[dictp2->cptr].codem1 = BADCODEM1; in bsd_compress()
609 db->max_ent = ++max_ent; in bsd_compress()
615 db->bytes_out += olen; in bsd_compress()
616 db->in_count += ilen; in bsd_compress()
618 ++db->bytes_out; /* count complete bytes */ in bsd_compress()
620 if (bsd_check(db)) in bsd_compress()
639 if (max_ent >= MAXCODE(n_bits) && max_ent < db->maxmaxcode) in bsd_compress()
640 db->n_bits++; in bsd_compress()
642 db->uncomp_bytes += ilen; in bsd_compress()
643 ++db->uncomp_count; in bsd_compress()
648 ++db->incomp_count; in bsd_compress()
649 db->incomp_bytes += ilen; in bsd_compress()
651 ++db->comp_count; in bsd_compress()
652 db->comp_bytes += olen + BSD_OVHD; in bsd_compress()
668 struct bsd_db *db = (struct bsd_db *) state; in bsd_incomp() local
669 u_int hshift = db->hshift; in bsd_incomp()
670 u_int max_ent = db->max_ent; in bsd_incomp()
671 u_int n_bits = db->n_bits; in bsd_incomp()
691 db->seqno++; in bsd_incomp()
710 dictp = &db->dict[hval]; in bsd_incomp()
724 if (hval >= db->hsize) in bsd_incomp()
725 hval -= db->hsize; in bsd_incomp()
726 dictp = &db->dict[hval]; in bsd_incomp()
737 if (max_ent < db->maxmaxcode) { in bsd_incomp()
741 db->n_bits = ++n_bits; in bsd_incomp()
746 dictp2 = &db->dict[max_ent+1]; in bsd_incomp()
747 if (db->dict[dictp2->cptr].codem1 == max_ent) in bsd_incomp()
748 db->dict[dictp2->cptr].codem1 = BADCODEM1; in bsd_incomp()
753 db->max_ent = ++max_ent; in bsd_incomp()
754 db->lens[max_ent] = db->lens[ent]+1; in bsd_incomp()
760 db->bytes_out += bitno/8; in bsd_incomp()
761 db->in_count += ilen; in bsd_incomp()
762 (void)bsd_check(db); in bsd_incomp()
764 ++db->incomp_count; in bsd_incomp()
765 db->incomp_bytes += ilen; in bsd_incomp()
766 ++db->uncomp_count; in bsd_incomp()
767 db->uncomp_bytes += ilen; in bsd_incomp()
772 if (max_ent >= MAXCODE(n_bits) && max_ent < db->maxmaxcode) in bsd_incomp()
773 db->n_bits++; in bsd_incomp()
796 struct bsd_db *db = (struct bsd_db *) state; in bsd_decompress() local
797 u_int max_ent = db->max_ent; in bsd_decompress()
800 u_int n_bits = db->n_bits; in bsd_decompress()
837 if (seq != db->seqno) { in bsd_decompress()
838 if (db->debug) in bsd_decompress()
840 db->unit, seq, db->seqno - 1); in bsd_decompress()
843 ++db->seqno; in bsd_decompress()
855 dmp->m_data += db->hdrlen; in bsd_decompress()
907 if (db->debug) in bsd_decompress()
908 printf("bsd_decomp%d: bad CLEAR\n", db->unit); in bsd_decompress()
912 bsd_clear(db); in bsd_decompress()
917 if (incode > max_ent + 2 || incode > db->maxmaxcode in bsd_decompress()
920 if (db->debug) { in bsd_decompress()
922 db->unit, incode, oldcode); in bsd_decompress()
924 max_ent, explen, db->seqno); in bsd_decompress()
938 codelen = db->lens[finchar]; in bsd_decompress()
940 if (explen > db->mru + 1) { in bsd_decompress()
942 if (db->debug) { in bsd_decompress()
943 printf("bsd_decomp%d: ran out of mru\n", db->unit); in bsd_decompress()
984 dictp = &db->dict[db->dict[finchar].cptr]; in bsd_decompress()
997 db->unit, codelen, incode, max_ent); in bsd_decompress()
1010 if (oldcode != CLEAR && max_ent < db->maxmaxcode) { in bsd_decompress()
1016 hval = BSD_HASH(oldcode,finchar,db->hshift); in bsd_decompress()
1017 dictp = &db->dict[hval]; in bsd_decompress()
1024 if (hval >= db->hsize) in bsd_decompress()
1025 hval -= db->hsize; in bsd_decompress()
1026 dictp = &db->dict[hval]; in bsd_decompress()
1034 dictp2 = &db->dict[max_ent+1]; in bsd_decompress()
1035 if (db->dict[dictp2->cptr].codem1 == max_ent) { in bsd_decompress()
1036 db->dict[dictp2->cptr].codem1 = BADCODEM1; in bsd_decompress()
1042 db->max_ent = ++max_ent; in bsd_decompress()
1043 db->lens[max_ent] = db->lens[oldcode]+1; in bsd_decompress()
1046 if (max_ent >= MAXCODE(n_bits) && max_ent < db->maxmaxcode) { in bsd_decompress()
1047 db->n_bits = ++n_bits; in bsd_decompress()
1059 db->bytes_out += ilen; in bsd_decompress()
1060 db->in_count += explen; in bsd_decompress()
1061 if (bsd_check(db) && db->debug) { in bsd_decompress()
1063 db->unit); in bsd_decompress()
1066 ++db->comp_count; in bsd_decompress()
1067 db->comp_bytes += ilen + BSD_OVHD; in bsd_decompress()
1068 ++db->uncomp_count; in bsd_decompress()
1069 db->uncomp_bytes += explen; in bsd_decompress()
1077 printf("bsd_decomp%d: fell off end of chain ", db->unit); in bsd_decompress()
1079 incode, finchar, db->dict[finchar].cptr, max_ent); in bsd_decompress()
1082 db->unit, incode, finchar); in bsd_decompress()
1084 db->dict[finchar].cptr, dictp->codem1); in bsd_decompress()