void deflate_tree(InWindow &slWindow, OutBuffer &buf, int blockSize) { int storedBlockLen = blockSize * 8; vector<Symb> lz77coded; vector<unsigned char> charList; LZ77_encode(slWindow, blockSize, lz77coded, charList); vector<int> litProbs(288, 0); vector<int> dstProbs(32, 0); for (int i = 0; i < lz77coded.size(); i++) { if (lz77coded[i].isLit) litProbs[lz77coded[i].lit]++; else dstProbs[lz77coded[i].lit]++; } vector<int> fixedLitLen(288); for (int i = 0; i <= 143; i++) fixedLitLen[i] = 8; for (int i = 144; i <= 255; i++) fixedLitLen[i] = 9; for (int i = 256; i <= 279; i++) fixedLitLen[i] = 7; for (int i = 280; i <= 287; i++) fixedLitLen[i] = 8; vector<int> fixedDstLen(32, 5); int fixedBlockLen = count_len(litProbs, fixedLitLen) + count_len(dstProbs, fixedDstLen); vector<int> dynamicLitLen(288); Huffman_builder(litProbs, dynamicLitLen); vector<int> dynamicDstLen(32); Huffman_builder(dstProbs, dynamicDstLen); int dynamicBlockLen = deflate_dynamic_estimate(dynamicLitLen, dynamicDstLen) + count_len(litProbs, dynamicLitLen) + count_len(dstProbs, dynamicDstLen);; if (blockSize <= MAX_STORED_SIZE && storedBlockLen <= fixedBlockLen && storedBlockLen <= dynamicBlockLen) deflate_stored(buf, charList); else if (fixedBlockLen <= dynamicBlockLen) deflate_fixed(buf, lz77coded, fixedLitLen, fixedDstLen); else deflate_dynamic(buf, lz77coded, dynamicLitLen, dynamicDstLen); }
static void lenw_function(RfReference &ref) { int len = count_len(ref->GetFirst()); RfFormConstructor R; RfContext context; RfVariable_E e_Foo("e.Foo"); RefalMatchProcess(ref, (R|e_Foo), context); ref = RefalSubstitute((R|len, e_Foo), context, true); }
char *bin_to_str(unsigned int n) { int i; int j; char *str; i = 0; j = count_len(n); str = (char *)malloc(sizeof(char) * j + 1); while (i < j) { str[i] = (n & 1) + '0'; n = n >> 1; i++; } str[i] = '\0'; return (ft_strrev(str)); }