static Block blocks_sort( /* Sort 'b1' on 'live_bytes'. */ Block b1) { int len = block_count(b1); if (len < 2) return b1; { Block b2 = blocks_split(b1, len / 2); return blocks_merge(blocks_sort(b1), blocks_sort(b2) ); } }
/* Convert blocks into windows whilst ensuring blocks which * transverse buffers are accounted for */ int process_block(char *block) { long sz, bsz; char *regex_b, *b = NULL; bool alloced = false; window_t *w = NULL; extern int store_count; /* previous block didn't terminate so we need to merge it * with the current block */ if(blocks_require_merge()) { if((sz = blocks_merge(block, &b)) == RERROR) return RERROR; alloced = true; } else { b = block; sz = strlen(block); } regex_b = regex_creplace(b); bsz = strlen(regex_b); if(win_init(&w, regex_b, bsz)==RERROR) { setlocation(LOCATION, __func__); return RERROR; } free(regex_b); // need this for ngram computation over blocks w->mcount = store_count; lgprintf(LG_INFO, "merged window size: %d\n", w->wc); win_store_add(w); /* this block does not terminate so we need to store it so * that blocks from the next buffer can be merged with it. */ if(!block_match(b[sz-1])) blocks_store(w); else blocks_clear(); if(alloced) { free(b); alloced = false; } return 0; }