void init(const char *s) { int i, freq[128] = {0}; char c[16]; while (*s) freq[(int)*s++]++; for (i = 0; i < 128; i++) if (freq[i]) qinsert(new_node(freq[i], i, 0, 0)); while (qend > 2) qinsert(new_node(0, 0, qremove(), qremove())); build_code(q[1], c, 0); }
void cc_compress_cleanup(struct cc **output, int bufsize) { struct cc **end; /* the previous output phase may have been interrupted */ qinsertq(&cc_q0b, &cc_q0a); for (end = output + bufsize; output < end;) { struct cc *p; int length; if ((p = *output) == 0) { output++; continue; } length = p->length; if (!p->flag) { } else if (p->code >= 0) { qinsert(p, &cc_q0b); p->flag = 0; } else if (p->ccount == 0) { *output = 0; } else if (p->ccount >= thresh(length) #ifndef cc_weight || wthreshp(p->weight, length) #endif ) { p->flag = 0; } else { p->ccount = 0; *output = 0; } output += length; } }
static void *smalloc(const char *fname, int lineno, unsigned int nbytes) { char *buf; /* * Note: Unix MALLOC actually permits a zero length to be * passed and allocates a valid block with zero user bytes. * Such a block can later be expanded with realloc(). We * disallow this based on the belief that it's better to make * a special case and allocate one byte in the rare case this * is desired than to miss all the erroneous occurrences where * buffer length calculation code results in a zero. */ ASSERT(nbytes > 0); nbytes += HEAD_SIZE + 1; if ((buf = (char *)malloc(nbytes)) != NULL) { struct abufhead *head = (struct abufhead *)buf; P(mutex); /* * Enqueue buffer on allocated list */ qinsert(&abqueue, (struct b_queue *) buf); head->ablen = nbytes; head->abfname = bufimode ? NULL : fname; head->ablineno = (uint32_t)lineno; head->abin_use = true; /* * Emplace end-clobber detector at end of buffer */ buf[nbytes - 1] = (uint8_t)((((intptr_t) buf) & 0xFF) ^ 0xC5); /* * Increment to user data start */ buf += HEAD_SIZE; if (++sm_buffers > sm_max_buffers) { sm_max_buffers = sm_buffers; } sm_bytes += nbytes; if (sm_bytes > sm_max_bytes) { sm_max_bytes = sm_bytes; } V(mutex); } else { smart_alloc_msg(__FILE__, __LINE__, _("Out of memory\n")); } #if SMALLOC_SANITY_CHECK > 0 if (sm_bytes > SMALLOC_SANITY_CHECK) { smart_alloc_msg(__FILE__, __LINE__, _("Too much memory used.")); } #endif return (void *)buf; }
void init(const char *s) { int i, freq[128] = {0}; char c[16]; while (*s) { //printf("haha:%c, %d\n", *s, (int)*s); freq[(int)*s]++; s++; } for (i = 0; i < 128; i++) if (freq[i]) qinsert(new_node(freq[i], i, 0, 0)); while (qend > 2) qinsert(new_node(0, 0, qremove(), qremove())); build_code(q[1], c, 0); }
void cc_output_phase(char *buffer, struct cc **output, int bufsize) { int i; struct cc *p, *p1; for (i = 0; i < bufsize;) { if ((p = output[i]) == 0) { ttputc(buffer[i]); i++; } else if (p->code >= 0) { if (--p->ccount == 0) qinsert(p, &cc_q0a); (*tt.tt_put_token)(p->code, p->string, p->length); wwntokuse++; wwntoksave += put_token_score(p->length); i += p->length; } else if ((p1 = cc_q0a.qback) != &cc_q0a) { p->code = p1->code; p1->code = -1; qinsert(p1, &cc_q1a); if (--p->ccount == 0) qinsert(p, &cc_q0a); else qinsert(p, &cc_q0b); (*tt.tt_set_token)(p->code, p->string, p->length); wwntokdef++; wwntoksave -= tt.tt_set_token_cost; i += p->length; } else { p->ccount--; ttwrite(p->string, p->length); wwntokbad++; i += p->length; } } wwntokc += bufsize; }
void mount_request(JCR *jcr, BSOCK *bs, char *buf) { MNT_REQ *mreq; mreq = (MNT_REQ *) malloc(sizeof(MNT_REQ)); memset(mreq, 0, sizeof(MNT_REQ)); mreq->jcr = jcr; mreq->bs = bs; P(mutex); num_reqs++; qinsert(&mountq, &mreq->bq); V(mutex); return; }
static int insert (SLOT *sp, char ch, int asis) { if (sp->flags.die) return 0; if (ch == '\n' && !asis) { if (!insert (sp, '\r', 1)) return 0; } if ((unsigned char)ch == IAC && !asis) { if (!insert (sp, IAC, 1)) return 0; } qinsert (sp->flags.wstop ? &sp->stopq : &sp->outq, ch); /* * In the following code fragment transmit() could block and hang * the server for some time. Ideally, transmit() should be called * only after successful select() call. */ /* if (qlength (&sp->outq) > sp->outq.qsize * 3 / 4) { if (writequeue (sp, &sp->outq) < 0) { if (sp->acct.chan < NUMCHANNELS) { remove_from_channel (sp, sp->acct.chan); remove_from_channel (sp, MAINLIST); } if (sp->acct.chan && sp->flags.on) { paabout (sp, DISCONNECTED); sp->acct.last_logout = time (NULL); } inactivate_slot (sp, 0); return 0; } } */ return 1; }
void main() { clrscr(); do { printf("\n1-->insert\n"); printf("2-->delete\n"); printf("3-->display\n"); printf("4-->exit\n"); printf("enter your choice\n"); scanf("%d",&choice); switch(choice) { case 1:qinsert(); break; case 2:qdelete(); break; case 3:qdisplay(); break; case 4:return; } } while(choice!=4); }
int cc_sweep(char *buffer, int bufsize, struct cc **tokens, int length) { struct cc *p; char *cp; int i; short *hc; short *places = cc_places[length]; struct cc **pp = tokens; short threshold = thresh(length); #ifndef cc_weight short wthreshold = wthresh(length); short limit = wlimit(length); #endif int time0; short pc = tt.tt_padc; i = length - 1; bufsize -= i; cp = buffer + i; hc = cc_hashcodes; time0 = cc_time0; for (i = 0; i < bufsize; i++, time0++) { struct cc **h; { short *hc1 = hc; short c = *cp++; short hh; if ((hh = *hc1) < 0 || c == pc) { *hc1++ = -1; hc = hc1; continue; } h = cc_htab + (*hc1++ = hash(hh, c)); hc = hc1; } for (p = *h; p != 0; p = p->hforw) if (p->length == (char) length) { char *p1 = p->string; char *p2 = cp - length; int n = length; do if (*p1++ != *p2++) goto fail; while (--n); break; fail: ; } if (p == 0) { p = cc_q1a.qback; if (p == &cc_q1a || (p->time >= cc_time0 && p->length == (char) length)) continue; if (p->hback != 0) if ((*p->hback = p->hforw) != 0) p->hforw->hback = p->hback; { char *p1 = p->string; char *p2 = cp - length; int n = length; do *p1++ = *p2++; while (--n); } p->length = length; #ifndef cc_weight p->weight = cc_weight; #endif p->time = time0; p->bcount = 1; p->ccount = 0; p->flag = 0; if ((p->hforw = *h) != 0) p->hforw->hback = &p->hforw; *h = p; p->hback = h; qinsert(p, &cc_q1a); places[i] = -1; p->places = i; #ifdef STATS ntoken_stat++; #endif } else if (p->time < cc_time0) { #ifndef cc_weight if ((p->weight += p->time - time0) < 0) p->weight = cc_weight; else if ((p->weight += cc_weight) > limit) p->weight = limit; #endif p->time = time0; p->bcount = 1; p->ccount = 0; if (p->code >= 0) { p->flag = 1; *pp++ = p; } else #ifndef cc_weight if (p->weight >= wthreshold) { p->flag = 1; *pp++ = p; qinsert(p, &cc_q1b); } else #endif { p->flag = 0; qinsert(p, &cc_q1a); } places[i] = -1; p->places = i; #ifdef STATS ntoken_stat++; #endif } else if (p->time + length > time0) { /* * overlapping token, don't count as two and * don't update time0, but do adjust weight to offset * the difference */ #ifndef cc_weight if (cc_weight != 0) { /* XXX */ p->weight += time0 - p->time; if (!p->flag && p->weight >= wthreshold) { p->flag = 1; *pp++ = p; qinsert(p, &cc_q1b); } } #endif places[i] = p->places; p->places = i; } else { #ifndef cc_weight if ((p->weight += p->time - time0) < 0) p->weight = cc_weight; else if ((p->weight += cc_weight) > limit) p->weight = limit; #endif p->time = time0; p->bcount++; if (!p->flag && /* code must be < 0 if flag false here */ (p->bcount >= threshold #ifndef cc_weight || p->weight >= wthreshold #endif )) { p->flag = 1; *pp++ = p; qinsert(p, &cc_q1b); } places[i] = p->places; p->places = i; } } if ((i = pp - tokens) > 0) { *pp = 0; if (cc_reverse) cc_sweep_reverse(tokens, places); if (cc_sort && i > 1) { qsort((char *) tokens, i, sizeof *tokens, cc_token_compare); } if (cc_chop) { if ((i = i * cc_chop / 100) == 0) i = 1; tokens[i] = 0; } i++; } return i; }