我正在制作LZ77压缩算法,但我不明白如何实现滑动窗口,以及如何将信息写入缓冲区,然后将其移位。 我有一些代码
int encode(const char *infile_path, const char *outfile_path, unsigned sb_size, unsigned la_size)
{
FILE *infile = NULL, *outfile = NULL;
if (bread_file(&infile, infile_path) || bwrite_file(&outfile, outfile_path)) {
return -1;
}
size_t win_size = sb_size + la_size;
char *window = malloc(sizeof * window * win_size);
if (window == NULL) {
fprintf(stderr, "%s() error: Memory allocation failure!\n", __func__);
return -1;
}
size_t buf_size;
buf_size = fread(window + sb_size, sizeof(char), win_size - sb_size, infile);
if (feof(infile)) {
printf("EOF has been reached!\n");
}
else {
fprintf(stderr, "%s() error: Couldn't read info from the file!\n\n", __func__);
return -1;
}
}
我被困在这里。您能对此提供任何详细信息吗?