Method and system for data compression

Abstract: Disclosed is a method and system for data compression. In a preferred embodiment, an input stream of data bytes are compressed (30A,30B) into an encoded stream using an LZ77-based scheme. The preferred method searches for a matching sequence of already processed data bytes that is identical to a current sequence of bytes. Sequences of literals (bytes not forming part of a matching sequence) or match codes (encoded matching sequences) are identified by count values indicating the number of literals or match codes in the sequence. Preferably, the encoded stream is transmitted from a first computer (A) to a second computer (B), where the encoded stream is decompressed (32B). The method uses matching circular history buffers for compression (30A,30B) and decompression (32A,32B), the history buffers (72) being synchronized using a coherency byte included with each frame of encoded data transmitted. If an encoded frame is not received by the decompression device (32A,32B), the decompression device transmits a flush request to the compression device (30A,30B). The compression device flushes its history buffer (72) in response to the flush request, the flushing step making the previously processed bytes stored in the history buffer (72) incapable of becoming part of a matching sequence. The compression device (30A,30B) includes in the coherency code of the next encoded frame a control code (28A,28B) indicating whether a flush request has been received by the compression device.

Description: Technical Field This invention relates generally to a method and system for data compression, and more particularly to a method and system for compressing data using LZ77-based compression in an inter-computer communication environment. Background of the Invention A variety of data compression algorithms derive from work published in Ziv, Jacob and Lempel, Abraham, "A Universal Algorithm for Sequential Data Compression," IEEE Transactions on Information Theory 23(3) :337-343, May 1977. These algorithms are commonly referred to as LZ77 compression schemes. LZ77 compression schemes are based on the principle that repeated strings of characters can be replaced by a pointer to the earlier occurrence of the string. A pointer is typically represented by an indication of the position of the earlier occurrence (typically an offset from the start of the repeated string) and the number of characters that match (the length). The pointers are typically represented as <offset, length> pairs. For example, the following string "abcdabcdacdacdacdaeaaaaaa" may be represented in compressed form by the following "abcd<4,5><3,9>ea<1,5>" Since the first characters "abcd" do not match any previous character, they are output in uncompressed form as literals. The pair <4,5> indicates that the string starting at an offset of 4 and extending for 5 characters is repeated "abcda". The pair <3,9> indicates that the string starting at an offset of 3 and extending for 9 characters is repeated. The "ea" are output as literals and the pair <1,5> indicate a string starting at an offset of 1 and extending for 5 characters ("aaaaa"). Compression is achieved by representing the repeated strings as a pointer with fewer bits than it would take to repeat the string. Typically, an unmatched single byte, known as a literal, is not represented as a pointer. Rather, literals are output with a flag indicating literal encoding followed by the byte itself. A pointer is typically differentiated from a literal encoding by a different flag that is followed by the offset and length. The offset and length can be encoded in a variety of ways. By adding a flag to each literal and each pointer, the prior art LZ-based systems provide less than optimal compression and may even cause expansion. The great majority of prior art compression systems are directed to compression of data stored in a single medium, such as a floppy disk or computer hard drive. However, very little work has been in the area of lossless generic data compression over an unreliable link, such as in a network or modem communication. In such instances, the compressor and decompressor are physically detached and any information the compressor sends the decompressor might be lost along the way. Modern networks operate in layers. At one of the higher layers of a network, a redirector or requestor may transmit blocks of homogeneous data, such as a database or a file. The data blocks typically are sent to a transport layer that breaks the data blocks into packets of limited size, such as 1.5 kilobytes (KB) or less. The transport then adds transport headers to the packets and sends the packets to a Media Access Controller (MAC) that adds frame headers to the packets to form frames that are transmitted across the network. Although the packets sent from the transport often are consecutive portions of a single data block, the transport might send packets from two or more blocks stored in different buffer if there are two different sends simultaneously outstanding. Given the homogeneity of the data at the transport layer, optimum compression may be obtained by enabling the transport to compress the data. However, transports are very complicated and need to interface with existing operating systems, such as DOS, Windows, OS/2, and UNIX so the task of creating a new transport with compression is very large. Further, existing transports are already widely used, so creating a new transport would not automatically provide compression to the many users of existing transports. Some developers have attempted to employ compression at the MAC level. Some efforts are limited to compressing the transport header for each packet. Others compress the data in each packet, but compress each packet separately without using the data in previous frames. No known prior art system compresses frames based on the data in previous frames over an unreliable link. Further, no known prior art system employs LZ77-based compression to compress frames being sent across an unreliable communication link. WO 92/02989 discloses a system for dynamic encoding of a character stream having a single character encoder that includes a plurality of fonts, a string encoder that includes a circular history buffer, and an output selector that compares encodings from the single character encoder and the string encoder, and selects least cost encoding for output. The single character encoder generates and stores hash codes used for font access and the string encoder retrieves these same hash codes and uses them for history buffer access. The string encoder uses the circular history buffer to store a sliding dictionary. The circular history buffer comprises a first 256-byte FIFO buffer comprising the most recent 256 characters from the stream to be encoded, and a second 256-byte FIFO buffer comprising an exact copy of the first buffer and being contiguous with the first buffer in memory for facilitating string searching. It is the object of the invention to provide an improved method and system for compressing an input stream of data using an LZ77-based scheme. This object is solved by the methods as claimed in independent claims 1 and 9, by the apparatus as claimed in independent claim 12 and by the system as claimed in independent claim 19. Preferred embodiments of the invention are subject-matters of dependent claims. In a preferred embodiment, an input stream of data bytes are compressed into an encoded stream using an LZ77-based scheme. The preferred method searches for a matching sequence of already processed data bytes that is identical to a current sequence of bytes. Each data byte not forming part of such an identical sequence is appended to the encoded stream, such data byte being a literal. When a matching sequence is found, the method appends to the encoded data stream a match code that identifies both the location in the input stream of the matching sequence and the number of data bytes in the matching sequence. The method identifies a sequence of a predetermined number of literals in the encoded data stream and appends to the identified literal sequence a count value indicating the number of literals in the identified sequence. The method identifies a sequence of a predetermined number of match codes in the encoded data stream and appends to the identified match code sequence a count value indicating the number of match codes in the identified match code sequence. Preferably, the input stream is stored in a circular history buffer of a compression device. The method divides the encoded data stream into a plurality of encoded frames and appends a coherency code to each encoded frame. The method transmits each encoded frame to a remote decompression device having a circular history buffer for decompressing each encoded frame. The method uses the coherency codes to synchronize the history buffer of the decompression device with the history buffer of the compression device. If an encoded frame is not received by the decompression device, the decompression device transmits a flush request to the compression device. The compression device flushes the history buffer in response to the flush request, the flushing step making the previously processed bytes stored in the history buffer incapable of becoming part of a matching sequence. The compression device includes in the coherency code of the next encoded frame a control code indicating whether a flush request has been received by the compression device. In a preferred embodiment, the decompression device decompresses the encoded data stream into a decompressed stream identical to the input stream. The decompressing step includes locating a match count value, decoding a number of match codes equal to the match count value, and appending the decoded match codes to the decompressed stream. The decompression step also includes locating a literal count value and appending to the decompressed stream a number of literals equal to the literal count value. Brief Description of the Drawings Figure 1 is a block diagram of a data compression system according to the present invention. Figures 2A and 2B together are a flow diagram of a data compression method according to the present invention. Figure 3 is a block diagram of preferred search data structures used in the compression method shown in Figures 2A and 2B. Figures 4A and 4B together comprise a flow diagram of a data decompression method using by the data compression system shown in Figure 1. Figure 5 is a time diagram illustrating a method of synchronizing history buffers used in the system shown in Figure 1. Figure 6 is a block diagram of a data storage structure used in an alternative embodiment of the present invention. Detailed Description of the Invention The present invention provides a method and system for compressing an input stream of data into a compressed stream of data using an LZ77-based encoding. The present invention also provides a method and system for decompressing the compressed stream to create a decompressed stream that is identical to the input stream. In a preferred embodiment, the input stream is inserted sequentially into a circular history buffer after each byte is analyzed. The compression system searches the history buffer to determine whether it contains a previous occurrence of a byte sequence that matches the current byte sequence. If the history buffer contains such a matching byte sequence, the compression system encodes the current byte sequence as a pointer to the matching byte sequence and the length of the match together with a match flag indicating that the encoding represents a matched sequence. When the history buffer does not contain such a matching sequence, the compression system outputs the first byte of the current byte sequence together with a literal flag indicating that the byte is an unmatched literal byte. Preferably, the compression system identifies strings of consecutive literals or consecutive match codes and outputs a count value indicating the number of consecutive literal or match codes rather than outputting a match or literal flag with each match or literal. In the preferred embodiment, the compression system is used in conjunction with a computer network, such as a Local Area Network (LAN) or a Wide Area Network (WAN). In the preferred network embodiment, the input stream is divided into packets of limited size and a coherency byte is appended to each compressed packet when forming the packets into frames to ensure that the frames are decompressed in the same order that the packets are compressed. If a packet cannot fit completely at the end of the history buffer after the preceding packets, the packet preferably is inserted at the beginning of the history buffer to avoid wrap-around problems. Figure 1 is an overview block diagram of a data compression system 10 according to the preferred embodiment of the present invention. The data compression system includes a server computer 12 coupled to a client computer 14 via a communications link 16 that carries compressed data between computers. The communications link 16 can be any link for passing data between computers, including a cable for a LAN or a telephone or satellite connection for a WAN. The server and client computers each include a central processing unit (CPU) 17A, 17B, a memory 18A, 18B and a network connector 20A, 20B interconnected by a data bus 22A, 22B. The network connectors physically connect each computer to the communications link 16, e.g., a modem physically connects each computer to a telephone line. In alternate systems, a series of one or more computers may be physically connected over a variety of communications links with the data being routed across the communications.links from one computer to another. Thus, the spirit of this data compression system is not limited to just two computers, or even two endpoints. There may be one or more computers connected across a communications link just as there may be more than one communications link connected to a computer. Each memory 18A, 18B stores a network controller 23A, 23B that controls the data being sent across the communications link 16 via the network connectors 20A, 20B. Each network controller 23A, 23B includes a redirector server 24A, 24B coupled to a conventional transport 26A, 26B that is coupled to a media access controller (MAC) 28A, 28B. The redirector interfaces with the CPU 16A, 16B and memory 18A, 18B to provide file input and output. The transports ensure reliable data communication between the server computer 12 and the client computer 14 and can be any conventional transports such as TCP/IP, IPX/SPX and NETBEUI. The transports also divide the data being transported between computers into packets of limited size, such as 1.5 kilobytes or less. Included in each packet is transport header that includes an address of the computer sending the data and an address of the computer intended to receive the data. The MACs are responsible for synchronizing data transmission and adding frame headers to the packets to create frames for transmission between computers. The frame headers include bytes for synchronization, frame type, frame length, and a cyclic redundancy check (CRC). As is well known, a CRC is a value computed based on the data in the frame, which the receiving MAC uses to determine whether any data was lost or corrupted during transmission between computers. Each MAC includes a compressor 30A, 30B for compressing the packets before forming and sending the frames and a decompressor 32A, 32B for decompressing the frames. Figures 2A and 2B together constitute a flow diagram of the compression system 10 as controlled by the compressors 30A, 30B as shown in Figure 1. The discussion that follows is directed to an example in which an input stream of data is being compressed in the server computer 12 into compressed frames and the compressed frames are passed to the client computer 14 where they are decompressed by the client computer 14. An identical flow occurs when an input stream is compressed in the client computer and passed to the server computer for decompression. The input stream is stored in a transport buffer created in the memory 18A by the transport 26A. The compression system 10 begins by determining whether a first packet of the input stream is worth compressing (step 34). Small frames typically cannot be compressed to an extent that would justify the processing time and effort required to compress them. Furthermore, multicast and broadcast frames, in the preferred embodiment, are not compressed because these frames do not typically contain user data and may interfere with the current data stream of frames being transmitted or received. If the packet is not worth compressing then it is framed and output as an uncompressed frame, as described below. If the packet is determined in step 34 to be worth compressing, then in step 36 the compression system selects a sequence of a limited number of bytes of the packet (preferably two bytes) as a current byte sequence. In step 38 the compression system determines whether a matching sequence can be found in a search data structure that stores byte sequences previously occurring in the input stream. The previously occurring byte sequences can be part of the same packet as the current byte sequence or part of a previously processed packet. If a matching sequence is found in the search structure, then in step 40 the first byte of the current byte sequence is inserted into a circular history buffer maintained in the memory 18A. The history buffer preferably is 8 kilobytes in size, but can be made larger for better compression or smaller for less memory consumption. In step 41, the byte following the matching sequence in the history buffer is compared to the byte following the current byte sequence in an attempt to find a longer match. If the byte following the current byte sequence matches the byte following the matching sequence, then in step 40 the second byte of the current byte sequence is inserted into the history buffer. Each time that a byte match is found, the matching sequence and the current byte sequence are augmented with the matching byte. Steps 40 and 41 are repeated until a byte following the current byte sequence does not match a corresponding byte following the matching sequence as determined in step 41. By inserting each successive byte into the history buffer in step 40 before the next bytes are compared in step 41, the compression system 10 allows the matching sequence to overlap the current byte sequence. For example, assume that bytes A and B are stored in the history buffer at positions 1 and 2 and that the next three bytes of the input stream are A, B, and A. In step 38, the compression system 10 finds the sequence AB in the history buffer to match the AB in the current byte sequence of the input stream. In step 40, the A of the current byte sequence is inserted into the history buffer following the matching sequence AB at position 3. In step 41, the compression system determines that the A following the current byte sequence matches the A that was just inserted into the history buffer. As a result, the matching sequence becomes ABA and the last A of the matching sequence (position 3) is the same as the first A of the current byte sequence, so the sequences have overlapped. If the first A of the current byte sequence had not been inserted into the history buffer in step 40 before the next comparison was made in step 41 then the ABA matching sequence could not have been found. If it is determined in step 41 that the next byte following the current byte sequence does not match the next byte following the matching sequence, then in step 42 the compression system encodes the longest match resulting from the byte-by-byte comparison of step 41. The encoding scheme used is preferably variable, that is, shorter matches are encoded with fewer bits than longer matches. Such variable encoding schemes are well-known, examples of which can be found in Bell, A Unifying Theory and Improvements for Existing Approaches to Text Compression , Ph.D. Thesis, University of Canterbury, New Zealand, 1987. In step 43, the last byte of the matched current byte sequence is inserted into the history buffer. In prior art compression systems, each encoded match is appended to an encoding data stream along with a match flag indicating that the following data represent an encoded match. The purpose of each match flag is to distinguish between an encoded match and a raw or literal byte that is output when no matching sequence is found. When there are several consecutive encoded matches, using a match flag between each encoded match is unnecessary. The preferred embodiment of the present invention replaces at least some of the unnecessary match flags with a count value indicating the number of match flags replaced. In the preferred embodiment, the amount of storage used to encode the match count is typically less than the amount of storage used to encode the match flags replaced by the match count. Returning to the flow diagram shown in Figure 2A, the compression system 10 determines whether the number of consecutive encoded matches has reached a predetermined value X (e.g., X equals 6 in the preferred embodiment) in step 44. If the number of consecutive matches is less than X, then the compression system appends a match flag to the encoded data stream in step 46 and appends the encoded match to the encoded stream in step 48. If the number of consecutive matches is not less than X than in step 50 the compression system determines whether the number of consecutive matches equals X. If so, then a match count of zero is appended to the encoded stream in step 52 and the encoded match is appended to the encoded stream in step 48. If the match value is greater than X, then in step 54, the compression system increments the match count that was most recently appended to the encoded stream. In step 48 the compression system appends the encoded match to the encoded stream immediately after the most recently encoded match. In a preferred embodiment, five bits are reserved for each match count. With five bits, only 32 match count values are possible, so match counts from 0 to 31 are possible. If more than 31 matches follow the first x matches, then a second match count immediately follows the 31st match. As such, each successive string of 31 matches is followed by a new match count. When no matching sequence is found for the current byte sequence, prior art compression systems output the first byte of the current byte sequence as a raw byte or literal together with a literal flag indicating that no matching sequence was found. Like the redundancy caused by consecutive matches, it is unnecessary and wasteful to include a literal flag with each literal of a string of literals. In the preferred embodiment, at least some of the literal flags are replaced by a literal count value indicating the number of literal flags replaced. In the preferred embodiment, the amount of storage used to encode the literal count typically is less than the amount of storage used to encode the literal flags replaced by the literal count. Returning to the flow diagram of Figure 2A, if a matching sequence is not found in the search structure for the current byte sequence in step 38, then the compression system determines whether the number of consecutive literals is less than a predetermined value Y (e.g., Y equals 6 in the preferred embodiment) in step 56. If so, then a literal flag is appended to the encoded stream in step 58 and the literal is appended to the encoded stream in step 60. If the number of consecutive literals is not less than Y as determined in step 56, then the compression system determines whether the number of consecutive literals equals Y in step 62. If so, then a literal count of zero is appended to the encoded stream in step 64 and the literal is appended to the encoded stream in step 60. If not, then the number of literals must be greater than Y, so the previously appended literal count is incremented in step 66 to reflect the number of consecutive literals exceeding Y. Like the match count, the preferred embodiment limits each literal count to 0-31 (5 bits) and a new literal count follows each successive string of 31 literals. In step 60 the literal is appended to the encoded stream following the immediately previous literal. In step 67, each literal appended to the encoded stream in step 60 is appended to the history buffer to enable future matches of each literal. The flow diagram continues on Figure 2B in step 68 in which the search structure is updated to ensure that an entry in the search structure points to the most recent occurrence of a data byte. The updating step can be more easily understood in the context of the following example of the preferred search structure. Figure 3 is a block diagram illustrating a sample search data structure 70 in conjunction with a circular history buffer 72 in a preferred embodiment. The circular history buffer 72 contains one or more packets of an input stream of data bytes, which in the example are represented by letters. The number above each letter in the history buffer indicates the position of the letter within the history buffer. For example, the letter "f" is at the tenth position within the history buffer. The search data structure 70 is a multi-dimensional direct address table that contains an entry for each possible byte-value. Thus, when a byte contains 8 bits, the table contains 256 entries. For example, the byte-value for an ASCII "a" is 61h. The entry indexed by 61h contains search information relating to byte sequences that begin with an ASCII "a" or byte-value 61h. Each entry contains a number of slots. A slot contains information that identifies a previous occurrence of a byte sequence in the history buffer. In the example of Figure 3, each entry contains four slots. In a preferred embodiment, each entry contains eight slots. In an alternate embodiment, each entry has a variable number of slots based on the expected frequency of the byte-value in an input stream. One skilled in the art would appreciate that by using more slots, a greater amount of compression can be achieved, but generally at the expense of a greater time of compression. When an entry contains four slots, the search data structure can contain information for four byte sequences that begin with the indexed byte-value. Each slot contains a next byte field 70A and a position field 70B. The next byte field contains the byte-value of the next byte after the indexing byte. The position field contains the position of the next byte in the history buffer. One skilled in the art would appreciate that a next byte field is included to speed searching. The byte-value of the next byte could be obtained by using the position field as an index into the history buffer. As shown in Figure 3, the search data structure 70 contains information on the previous byte sequences when the current byte sequence starts at the ninth position in the history buffer as indicated by the arrow. The first eight bytes of the history buffer contain no matching byte sequences. The search data structure entry for "a" contains a slot that identifies each of the four previous byte sequences that begin with an "a", that is, "ad", "ac", "ab", and "ae." When the current byte sequence, "af' at positions 9 and 10, is processed, the search data structure 70 is searched to determine whether an "af" is identified as a previous byte sequence (step 38 of Figure 2A). In this example, no slot for the entry indexed by "a" contains an "f" as the next byte-value. Consequently, the compression system overwrites the slot for the letter "a" that has been least recently updated. In this case, the slot identifying the byte sequence "ad" is replaced with information to identify the current byte sequence "af". Specifically, the next byte field is overwritten with an "f" and the position field is overwritten with a 10. When the next byte sequence beginning with an "a" is encountered, "ae" at position 11, the compression system searches for a slot in the entry indexed by "a" identifying a matching sequence, that is, a previous byte sequence "ae". Since the fourth slot contains an "e", a matching sequence is found. The fourth slot points to position 8 as the location of the last byte of the matching sequence ("e"). The compression system attempts to extend the matching sequence by comparing the byte at position 12 with the byte at position 9 and finds the matching sequence "aea" (step 40 of Figure 2A). The compression system compares the byte at position 13 with the byte at position 10, but is unable to extend the matching sequence. The compression system encodes the current byte sequence "aea" as a match code including a pointer to the matching sequence "aea" beginning at position 7 and a count value of the length of the matching sequence for a match code representing (7, 3) (step 42 of Figure 2A). After checking for repeated match codes (step 44), the compression system appends the match code and a match flag to the encoded stream (steps 46, 48). The compression system updates the search structure 70 by replacing the position in the fourth slot with position 12 to identify the current byte sequence (step 68). An LRU (least-recently updated) data structure 74 contains an entry for each byte-value and is indexed by the byte-value. The entries identify the least recently updated slot for the corresponding entry in the search data structure. The LRU structure (as shown) actually contains the slot number (0...3) of the most recently updated slot. The least recently updated slot is obtained by adding 1 to the value in the LRU entry. For example, the least recently updated slot for "a" is slot 0; so the LRU data structure contains a 3 (3 + 1 mod 4 = 0). When the current byte sequence does not match any byte sequence in the search data structure, the LRU is updated to point to the next slot (in a circular fashion) and the next slot is overwritten with the first byte and position of the current byte sequence. One skilled in the art would appreciate that an estimate of a least recently updated slot can be made by selecting the slot with the smallest position value and thus making the LRU data structure unnecessary. In alternate embodiments, the byte sequence can be any number of bytes. The search data structure could be implemented as a direct access table indexed by two bytes and thus having 2 16 entries. Alternatively, the search data structure could be implemented as a hash table. When a hash table is used, byte sequences with different first bytes could hash to the same entry causing a collision. When a collision occurs, the first byte of each byte sequence identified by a slot would need to be checked to determine a match. In another embodiment, the slots for each entry could be maintained as a linked list. The linked list could be implemented as an array parallel to the input stream with a slot for each byte in the input stream. Each entry in the search data structure would point to a linked list of slots identifying next byte values. The slots in the linked list would link together next byte values for the same first byte. When searching the linked list, only a certain number of slots are checked for a match. When no match is found, a new slot is added to the beginning of the linked list to identify the current byte sequence. When a matching slot is found, it is preferably removed from the linked list and a new slot added to the beginning of the linked list to identify the current byte sequence. Returning to Figure 2B, in step 76 the compression system 10 determines whether the end of the packet has been reached. If not, then the compression system loops through steps 36-68 with a new current byte sequence. If the most recent current byte sequence did not result in a match, then the new current byte sequence begins with the second byte of the previous current byte sequence. If the previous current byte sequence resulted in a match, then the current byte sequence begins with the first byte following the previous current byte sequence (as augmented by the matching bytes found in the byte-by-byte comparison of step 41). Because the preferred embodiment of the compression system is used in conjunction with a network, there is a distinct possibility of losing all or part of the encoded frame during transmission from the server computer 12 to the client computer 14, especially when using a WAN. Prior art network compression systems have sought to alleviate the problem of dropped frames by providing a guaranteed delivery mechanism in the media access controllers (MACs) along with the compression programs. Such prior art schemes require the receiving MAC to transmit an acknowledgment back to the sending MAC after one or more frames is received. Such a delivery guarantee scheme wastes considerable transmission time and causes MACs to be unnecessarily complicated. In addition, the network transports already guarantee delivery, so the MAC delivery guarantee is redundant. As such, the transport may resend a frame while the media access controller is trying to do the same, so the frame may get sent twice. Rather than having the MAC 28A include a delivery guarantee mechanism, the compression system 10 simply relies on the transports 26A, 26B to ensure delivery. This presents a problem in that each frame is compressed based on the data in the previous frames, but since the transport 26A sits above the MAC 28A there is no way for the transport to guarantee delivery from MAC 28A to MAC 28B, only from transport 26A to transport 26B. Thus, if no measures were taken, the decompressor would attempt to decompress the subsequent frames, but because the dropped frame would not have gotten into the decompressor's history buffer, the decompressor would not be able to accurately decompress the subsequent frames. To compensate for this potential problem, the compression system 10 adds a coherency byte to each frame to ensure that the decompressor's history buffer remains synchronized with the compressor history buffer. Returning to Figure 2B, if the compression system 10 determines in step 76 that the end of a packet has been reached, the compression system frames the packet by adding a frame header, including a CRC and a coherency byte to form a frame in step 78. In step 80, the frame is sent to the decompressor 32B of the client computer across the communications link 16. In step 82, the compression system 10 determines whether all packets have been processed. If so, then the compression system is done and returns execution to whatever system caused the data to be sent between computers. If there are more packets to process, the compression system 10 in step 86 determines whether a flush request has been received from the decompressor. Such a flush request is issued by the decompressor 32B if a frame is received out of order, as indicated by a nonsequential coherency byte, indicating that a frame was dropped during transmission. If such a flush request is received, then the compressor 30A in step 88 flushes its history buffer by invalidating the bytes currently in the history buffer. In step 90, the compression system sets the next coherency byte to indicate that a flush request has been received and that the frame to be sent with the coherency byte was compressed with a reset history buffer. In step 92, the compression system sets a flag to indicate that each byte of the next packet, after it is analyzed for a match, should be inserted at the beginning of the history buffer so that the next packet is compressed without reference to previous packets. If no flush request is received in step 86, then in step 94 the compression system 10 determines whether there is sufficient space in the history buffer for the next packet after the immediately previous packet. If so, then in step 96 the compression system sets a flag indicating that each byte of the next packet, after it is analyzed for a match, should be inserted into the history buffer immediately after the previous packet. If not, then in step 92 the flag is set to indicate that each byte of the next packet, after it is analyzed for a match, should be inserted at the beginning of the history buffer. By inserting the next packet at the beginning of the buffer when it cannot entirely fit at the end of the buffer, the compression system avoids wrap-around problems associated with having a matching sequence continue from the end to the beginning of the history buffer. Such wrap-around problems include the necessity of constantly checking whether the end of the buffer has been reached during compression and decompression in order to remain within the history buffer. After inserting the next packet in the history buffer, the process continues to loop through steps 36-92 until all packets of the input stream have been processed. Shown in Figures 4A and 4B is a flow diagram of the decompression section of the compression system 10 as controlled by the decompressor 32B. In step 98, the decompressor 32B receives a frame from the compressor 30A. In step 100, the decompressor determines whether a flush request has been received from the compressor 30A. If such a flush request is received, then in step 102 the decompressor flushes its history buffer by invalidating the bytes currently in the history buffer. In step 104, the decompressor sets the next coherency byte to indicate that a flush request has been received and that the frame sent with the coherency byte was decompressed with a reset history buffer. In step 106, the decompressor sets a flag to indicate that each byte of the next frame, after it is decompressed, should be inserted at the beginning of the history buffer so that the next frame is decompressed without reference to previous frames. If no flush request is received in step 100, then in step 108 the decompressor 32B determines whether there is sufficient space in the history buffer for the next frame after the immediately previous frame. If so, then in step 110 the decompressor sets a flag indicating that each byte of the next packet, after it is decompressed, should be inserted into the history buffer immediately after the previous frame. If not, then in step 106 the flag is set to indicate that each byte of the next packet, after it is decompressed, should be inserted at the beginning of the history buffer. Such buffer checking keeps the decompressor's history buffer in sync with the compressor's history buffer. In step 112, the decompressor determines whether the frame received is in the correct sequential order by checking the sequence number of the coherency byte of the frame. If the sequence number is incorrect, then the decompressor determines that a frame has been dropped during transmission between the server computer 12 and the client computer 14. In step 114, the decompressor issues a flush request to the compressor which tells the compressor to reset its history buffer before compressing the next packet. The decompressor then returns to receive the next frame in step 98. Figure 5 is a time diagram illustrating an example of frames being transmitted between a server computer 12 and the client computer 14. Frames 1-4 are transmitted with sequential coherency bytes 00-03, respectively. Frames 1 and 2 are received with no mistakes by the client computer, but frame 3 is not received correctly by the client computer. The client computer may detect that a frame has been dropped by not receiving the frame within a specified time or receiving a frame but determining that the CRC did not match the data in the frame. In response to the dropped frame, the client computer transmits a flush request to the server computer by sending a control frame with a flush request coherency byte such as FF. Because of transmission delays, the flush request sent from the client computer is not received by the server computer until after the server computer has sent frame 4 to the client computer. As such, the client computer receives frame 4 with a coherency byte (03) that does not acknowledge that the server computer's compression history buffer has been flushed. As a result, the client computer determines that the frame 4 is out of order and does not decompress it. The server computer sends frame 5 with the upper nibble of the coherency byte changed to a 1 which indicates that the server's compression history buffer has been flushed and that frame 5 was compressed without referring to frames 1-4. When client computer receives frame 5 it recognizes the 1 in the upper nibble in the coherency byte as an indication of a buffer flush and the client computer decompresses frame 5 with its decompression history buffer flushed to match the server computer's flushed compression history buffer. It should be recognized that the coherency bytes are not always in strict sequential order. As shown in Figure 5, frame 7 is sent with a coherency byte of 7E rather than a coherency byte of 12 that would follow sequentially after the frame 6 coherency byte of 11. The coherency byte of 7E is reserved for frames that preferably are not compressed, such as small, multicast, and broadcast frames. Figure 5 also illustrates the ability of the preferred compression system to transmit frames from the server computer 12 to the client computer 14 while frames are being transmitted from the client computer to the server computer. The frames being sent to the client computer normally are processed separately from the frames being received by the server computer except when a frame is dropped. For example, the server computer determines that frame B has been dropped during transmission from the client computer to the server computer sometime before frame 10 has been sent. Rather than sending frame 10 with a sequential coherency byte of 14 and then sending a separate control frame with a flush request coherency byte, the server computer combines the frame 10 coherency byte with the flush request coherency byte to produce a coherency byte of 94. The client computer receives frame 10 and detects that frame 10 is in proper sequential order and that it has been coupled with a flush request. As a result, the client computer flushes its compression history buffer and transmits frame C along with a coherency byte of 10, the 1 in the upper nibble indicating that the buffer has been flushed and the 0 in the lower nibble indicating the start of a new numerical sequence of frames. The decompression flow diagram continues with Figure 4B, in which if a frame is received in the correct order, the decompressor determines whether it has already processed a sequence of a predetermined number (Y) of literals (Y equals 6 in the preferred embodiment) in step 116. If a sequence of literals was processed, then in step 118 the decompressor gets a count value (L) indicating the number of literals exceeding Y in the sequence of literals. In step 120 the decompressor outputs the next L bytes as literals. In step 122, the decompressor decodes the match immediately following the L literals. Recall that a match without a match flag always follows a string of literals, because if another literal followed the string of literals, then the literal would be part of the string of literals. In step 124, the decompressor outputs the decoded match. If there was no sequence of literals of length Y, then in step 126 the decompressor determines whether there is a sequence of a predetermined number (X) of match codes (X equals 6 in preferred embodiment). If so, then in step 128 the decompressor obtains a count value (m) indicating the number of match codes greater than X in the sequence of match codes. In step 130 the decompressor decodes M consecutive match codes by searching for matching sequences in the decompression history buffer that is maintained identically to the compression history buffer of the server computer 12. Upon finding the beginning of each matching sequence in the decompression history buffer, the decompressor simply counts the number of bytes indicated by each encoding and outputs the decoded matches in step 132. In step 134, the decompressor outputs the literal immediately following the M matches. If there are no sequences of match codes or literals, then the decompressor determines whether a literal flag is found in the next bit or bits (depending on the number of bits in each flag) in step 136. If so, then in step 134 the decompressor outputs a literal. If not, then the next bit or bits must be a match flag and in step 122 the decompressor decodes the match code following the match flag and outputs the decoded match in step 124. After outputting literals or matches in steps 120, 124, 132, and 134, the decompressor determines whether the end of the current frame has been reached in step 138. If not, then the execution loops through steps 116-138 for the next section of the encoded frame. When the end of the frame is reached, the decompressor determines whether all frames have been processed (step 140). If there are more frames to receive, the decompressor loops through steps 98-140 for the next frame. When all the frames have been processed, the decompressor is done and returns execution to the operating system of the client computer in step 142. As discussed above, the compression system 10 preferably inserts a new packet at the beginning of the history buffer when the new packet cannot fit at the end of the history buffer after the previous packet. In an alternate embodiment, only the portion of the new packet that does not fit in the end of the buffer is inserted into the beginning of the buffer. The compression system preallocates an extended buffer section that immediately follows the end of the history buffer. If a packet does not fit entirely into the history buffer, the portion of the packet that does not fit is inserted into the extended buffer section. This allows a current byte sequence occurring at the end of the history buffer to extend into the extended buffer section so that the compressor does not have to wrap-around to the beginning of the buffer while compressing a current byte sequence. The portion of the packet that extends into the extended buffer is then copied into the beginning of the history buffer for further compression after compression of that packet is completed. An example of alternate embodiment shown with respect to the examples shown in Figure 6. Figure 6 shows an 8K circular history buffer 144 and a 1.5K extended buffer 146 located immediately after the end of the history buffer. Packets 1-5 have previously been inserted in the history buffer and compressed as described above. The next packet to be compressed is packet 6 which is 1.5K bytes in length. The compression system inserts the first 0.5K bytes of packet 6 into the history buffer immediately after packet 5 and inserts the remaining 1K of packet 6 into the extended buffer. Assume that the first 499 bytes of packet 6 are compressed normally as described above. As such, the current byte sequence begins with the last byte of the history buffer and extends into the extended buffer. The extended buffer allows the compression system to ignore the fact that the current byte sequence extends past the history buffer and allows the current byte sequence to be augmented as much as necessary if an extended matching sequence is found. For example, if a match is found for the current byte sequence extending from position 7999 (the last position in the history buffer) and 8004 and the match can be found and encoded without wrapping around to the beginning of the history buffer. Given that the next current byte sequence of packet 6 does not begin within the history buffer, the last 1K bytes of the packet 6 are inserted into the beginning of the history buffer, thereby overwriting the first 1K bytes of packet 1. Therefore, the next current byte sequence will begin within the history buffer with the byte at position 5 (the byte immediately following the end of the previous current byte sequence) and compression proceeds as normal.

Claims: A data compression method for encoding an input stream, said input stream comprising packets of data bytes, said method comprising the steps of: receiving (34: Y) a current packet for storage into a history buffer (72; 144) in sequential order with a previous packet, said history buffer (72; 144) having a beginning and an end, said beginning logically following said end; searching (38) said history buffer (72; 144) for a matching sequence of already processed data bytes that is identical to a current sequence of data bytes; appending (60) to an encoded data stream each unmatched data byte not forming part of an identical sequence in case that a matching sequence has not been found, said unmatched data byte being referred to as literal; appending (48) to said encoded data stream a match code identifying both the location of said matching sequence in said history buffer (72; 144) and the number of data bytes in said matching sequence in case that said matching sequence has been found; dividing (78) said encoded data stream into a plurality of encoded frames; characterized by : determining whether said current packet fits into said history buffer (72; 144) between said previous packet and said end; in case that said current packet is determined to fit into said history buffer (72; 144): inserting said current packet into said history buffer (72; 144); in case that said current packet is determined not to fit into said history buffer (72; 144): inserting a first portion of said current packet into said history buffer (72; 144) between said previous packet and said end, inserting a second portion of said current packet at said beginning, and inserting said second portion into an overflow buffer (146), said overflow buffer (146) immediately logically following said end. The method according to claim 1, further comprising the steps of: transmitting an encoded frame to a remote decompression device (32A; 32B); transmitting (114) a flush request from the decompression device (32A; 32B) to the compression device (32B; 32A) if the encoded frame is not received by the decompression device (32A; 32B); and flushing (88) the history buffer (72; 144) in response to the flush request, the flushing step (88) making the bytes stored in the history buffer (72; 144) incapable of becoming part of a matching sequence. The method according to claim 2, further comprising the step of: appending (90) a coherency code to an encoded frame, the coherency code including a control code indicating whether a flush request has been received (86: N) and a sequential code indicating where in a sequence of encoded frames the encoded frame is located. The method according to claim 1, further comprising the steps of: determining (62) a sequence of a predetermined number of literals in the encoded data stream, said sequence being referred to as identified literal sequence; and appending (64) to the identified literal sequence a count value indicating the number of literals in the identified literal sequence. The method according to claim 4, further comprising the steps of: appending (58) a literal flag to the encoded data stream adjacent each literal not forming part of a literal sequence; and appending (58) a literal flag to each literal sequence. The method according to claim 1, further comprising the steps of: transmitting (80) the encoded data stream to a remote decompression device (32A; 32B); and decompressing the encoded data stream into a decompressed stream identical to the input stream. The method according to claim 1, further comprising the steps of: determining (50) a sequence of a predetermined number of match codes in the encoded data stream, said sequence being referred to as identified match code sequence; and appending (52) to the identified match code sequence a count value indicating the number of match codes in the identified match code sequence. The method according to claim 7, further comprising the steps of: appending (49) a match code flag to the encoded data stream adjacent each match code not forming part of a match code sequence; and appending (49) a match code flag to each match code sequence. A data transmission method, comprising the steps of: compressing an input stream according to the method of claim 7; transmitting (80) the encoded data stream to a remote decompression device (32A; 32B); and decompressing the encoded data stream into a decompressed stream identical to the input stream. The method according to claim 9, wherein the decompressing step includes: locating (128) a match count value; decoding (130) a number of match codes equal to the match count value; and appending (132) the decoded match codes to the decompressed stream. The method according to claim 1, further comprising the steps of: determining (34) whether a packet has fewer than a predetermined minimum number of data bytes; and appending (34: N) the packet onto the encoded data stream without searching for matching sequences of identical data bytes if the packet is determined to have fewer than the predetermined minimum number of data bytes. A data compression apparatus (30A, 30B) for encoding an input stream, said input stream comprising packets of data bytes, said apparatus (30A, 30B) comprising: a history buffer (72; 144) having an end and a beginning that logically follows the end, said history buffer (72; 144) storing a current packet in sequential order with a previous packet; means (70) for searching (38) said history buffer (72; 144) for a matching sequence of already processed data bytes that is identical to a current sequence of data bytes; means for appending (60) to an encoded data stream each unmatched data byte not forming part of an identical sequence in case that a matching sequence has not been found, said unmatched data byte being referred to as literal; means for appending (48) to said encoded data stream a match code identifying both the location of said matching sequence in said history buffer (72; 144) and the number of data bytes in said matching sequence in case that said matching sequence has been found; means for dividing (78) said encoded data stream into a plurality of encoded frames; characterized by : means for determining whether said current packet fits into said history buffer (72; 144) between said previous packet and said end; means for inserting said current packet into said history buffer (72; 144), in case that said current packet is determined to fit into said history buffer (72; 144); means for inserting a first portion of said current packet into said history buffer (72; 144) between said previous packet and said end, in case that said current packet is determined not to fit into said history buffer (72; 144); means for inserting a second portion of said current packet at said beginning, in case that said current packet is determined not to fit into said history buffer (72; 144); and means for inserting said second portion into an overflow buffer (146), said overflow buffer (146) immediately logically following said end. The apparatus (30A, 30B) according to claim 12, further comprising: means for determining (50) a sequence of a predetermined number of match codes in the encoded data stream, said sequence being referred to as identified match code sequence; and means for appending (52) to the identified match code sequence a count value indicating the number of match codes in the identified match code sequence. The apparatus (30A, 30B) according to claim 13, further comprising: means (16, 20A, 20B, 22A, 22B, 24A, 24B, 26A, 26B) for transmitting (80) the encoded data stream to a remote decompression device (32A; 32B); and means (32A; 32B) for decompressing the encoded data stream into a decompressed stream identical to the input stream. The apparatus (30A, 30B) according to claim 14, wherein the means (32A; 32B) for decompressing includes: means for locating (128) a match count value; means for decoding (130) a number of match codes equal to the match count value; and means for appending (132) the decoded match codes to the decompressed stream. The apparatus (30A, 30B) according to claim 13, further comprising: means for appending (49) a match code flag to the encoded data steam adjacent each match code not forming part of a match code sequences; and means for appending (49) a match code to each match code sequence. The apparatus (30A, 30B) according to claim 12, further comprising: means for determining (62) a sequence of a predetermined number of literals in the encoded data stream, said sequence being referred to as identified literal sequence; and means for appending (64) to the identified literal sequence a count value indicating the number of literals in the identified literal sequence. The apparatus (30A, 30B) according to claim 17, further comprising: means for appending (58) a literal flag to the encoded data stream adjacent each literal not forming part of a literal sequence; and means for appending (58) a literal flag to each literal sequence. A data transmission system (10), comprising: the apparatus (30A, 30B) according to claim 18; means (16, 20A, 20B, 22A, 22B, 24A, 24B, 26A, 26B) for transmitting (80) the encoded data stream to a remote decompression device (32A; 32B); and means (32A; 32B) for decompressing the encoded data stream into a decompressed stream identical to the input stream.

Inventors: DIMITRI THOMAS J, DIMITRI, THOMAS J.
Applicants: MICROSOFT CORP, MICROSOFT CORPORATION
Application year: 1994
Main classification: H03M7
IPC codes: G06F5, G06F3, H03M7, G06T9