⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 brute.c

📁 LZSS 压缩/解压算法 算法简单
💻 C
字号:
/****************************************************************************          Lempel, Ziv, Storer, and Szymanski Encoding and Decoding**   File    : brute.c*   Purpose : Implement brute force matching of uncoded strings for LZSS*             algorithm.*   Author  : Michael Dipperstein*   Date    : February 18, 2004******************************************************************************   UPDATES**   $Id: brute.c,v 1.2 2005/12/28 06:03:30 michael Exp $*   $Log: brute.c,v $*   Revision 1.2  2005/12/28 06:03:30  michael*   Use slower but clearer Get/PutBitsInt for reading/writing bits.*   Replace mod with conditional Wrap macro.**   Revision 1.1  2004/02/22 17:21:37  michael*   Initial revision of brute force search.  Mostly code removed from lzss.c.******************************************************************************** Brute: Brute force matching routines used by LZSS Encoding/Decoding*        Routine* Copyright (C) 2004 by Michael Dipperstein (mdipper@cs.ucsb.edu)** This library is free software; you can redistribute it and/or* modify it under the terms of the GNU Lesser General Public* License as published by the Free Software Foundation; either* version 2.1 of the License, or (at your option) any later version.** This library is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU* Lesser General Public License for more details.** You should have received a copy of the GNU Lesser General Public* License along with this library; if not, write to the Free Software* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA****************************************************************************//****************************************************************************                             INCLUDED FILES***************************************************************************/#include "lzlocal.h"/****************************************************************************                            GLOBAL VARIABLES***************************************************************************//* cyclic buffer sliding window of already read characters */extern unsigned char slidingWindow[];extern unsigned char uncodedLookahead[];/*****************************************************************************   Function   : InitializeSearchStructures*   Description: This function initializes structures used to speed up the*                process of mathcing uncoded strings to strings in the*                sliding window.  The brute force search doesn't use any*                special structures, so this function doesn't do anything.*   Parameters : None*   Effects    : None*   Returned   : None****************************************************************************/void InitializeSearchStructures(){    return;}/*****************************************************************************   Function   : FindMatch*   Description: This function will search through the slidingWindow*                dictionary for the longest sequence matching the MAX_CODED*                long string stored in uncodedLookahed.*   Parameters : windowHead - head of sliding window*                uncodedHead - head of uncoded lookahead buffer*   Effects    : None*   Returned   : The sliding window index where the match starts and the*                length of the match.  If there is no match a length of*                zero will be returned.****************************************************************************/encoded_string_t FindMatch(unsigned int windowHead, unsigned int uncodedHead){    encoded_string_t matchData;    unsigned int i, j;    matchData.length = 0;    matchData.offset = 0;    i = windowHead;  /* start at the beginning of the sliding window */    j = 0;    while (TRUE)    {        if (slidingWindow[i] == uncodedLookahead[uncodedHead])        {            /* we matched one how many more match? */            j = 1;            while(slidingWindow[Wrap((i + j), WINDOW_SIZE)] ==                uncodedLookahead[Wrap((uncodedHead + j), MAX_CODED)])            {                if (j >= MAX_CODED)                {                    break;                }                j++;            };            if (j > matchData.length)            {                matchData.length = j;                matchData.offset = i;            }        }        if (j >= MAX_CODED)        {            matchData.length = MAX_CODED;            break;        }        i = Wrap((i + 1), WINDOW_SIZE);        if (i == windowHead)        {            /* we wrapped around */            break;        }    }    return matchData;}/*****************************************************************************   Function   : ReplaceChar*   Description: This function replaces the character stored in*                slidingWindow[charIndex] with the one specified by*                replacement.  The hash table entries effected by the*                replacement are also corrected.*   Parameters : charIndex - sliding window index of the character to be*                            removed from the linked list.*   Effects    : slidingWindow[charIndex] is replaced by replacement.  Old*                hash entries for strings containing slidingWindow[charIndex]*                are removed and new ones are added.*   Returned   : None****************************************************************************/void ReplaceChar(unsigned int charIndex, unsigned char replacement){    slidingWindow[charIndex] = replacement;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -