CN106788451B - Huffman decoding method and device - Google Patents

Huffman decoding method and device Download PDF

Info

Publication number
CN106788451B
CN106788451B CN201611080671.9A CN201611080671A CN106788451B CN 106788451 B CN106788451 B CN 106788451B CN 201611080671 A CN201611080671 A CN 201611080671A CN 106788451 B CN106788451 B CN 106788451B
Authority
CN
China
Prior art keywords
decoding
binary code
reading
bit
huffman
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201611080671.9A
Other languages
Chinese (zh)
Other versions
CN106788451A (en
Inventor
赵雅倩
李一韩
李磊
史宏志
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Suzhou Inspur Intelligent Technology Co Ltd
Original Assignee
Suzhou Inspur Intelligent Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Suzhou Inspur Intelligent Technology Co Ltd filed Critical Suzhou Inspur Intelligent Technology Co Ltd
Priority to CN201611080671.9A priority Critical patent/CN106788451B/en
Publication of CN106788451A publication Critical patent/CN106788451A/en
Application granted granted Critical
Publication of CN106788451B publication Critical patent/CN106788451B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H03ELECTRONIC CIRCUITRY
    • H03MCODING; DECODING; CODE CONVERSION IN GENERAL
    • H03M7/00Conversion of a code where information is represented by a given sequence or number of digits to a code where the same, similar or subset of information is represented by a different sequence or number of digits
    • H03M7/30Compression; Expansion; Suppression of unnecessary data, e.g. redundancy reduction
    • H03M7/40Conversion to or from variable length codes, e.g. Shannon-Fano code, Huffman code, Morse code
    • H03M7/4006Conversion to or from arithmetic code
    • H03M7/4012Binary arithmetic codes

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Compression, Expansion, Code Conversion, And Decoders (AREA)

Abstract

The invention discloses a Huffman decoding method and a device thereof, comprising reading a plurality of groups of binary code groups from a bit stream to be decoded in sequence; the number of binary codes contained in each group of binary code groups is more than 1; respectively and sequentially carrying out Huffman decoding on each group of binary code groups to obtain a decoding result corresponding to the binary code on the bit stream to be decoded, wherein the decoding result comprises decoding characters and a decoding length, and the decoding length is the bit number of the binary code corresponding to the decoding characters in a preset Huffman code table; after reading the decoding character corresponding to the decoding position, sequentially shifting the decoding position backwards by corresponding digits according to the decoding length corresponding to the decoding position, taking the position corresponding to the backward shift as the decoding position, and repeating the operation; and until the decoding is finished, the initial decoding position is the initial binary code of the bit stream to be decoded. The invention reads the multi-bit binary code by taking the group as a unit for decoding, and has high decoding efficiency. And the reading process and the decoding process do not interfere with each other, and the decoding speed is high.

Description

Huffman decoding method and device
Technical Field
The invention relates to the technical field of coding and decoding, in particular to a Huffman decoding method and a device thereof.
Background
At present, with the rapid development of the internet and the internet of things, the data file scale is larger and larger. In order to save the storage cost, each data center compresses the data. A large amount of data compression occupies higher CPU resources, so that the performance of the server is reduced, the power consumption of the server is improved, and the energy cost is increased.
Currently, a huffman decoding method is often adopted in data compression. Huffman coding is a method of uniform coding (also known as entropy coding) used for lossless compression of data. The method establishes a coding table according to the occurrence probability of each character, characters with high occurrence probability use shorter codes, otherwise characters with low occurrence probability use longer codes, so that the average expected length of coded character strings is reduced, and the aim of lossless data compression is fulfilled. The Huffman coding is a variable length coding, the coding length of each character is not fixed, so the Huffman decoding can only be executed in series, the bit stream to be decoded can not be divided into binary code strings with specific length in advance and then processed, and in the decoding process, one bit of binary code is read first, compared with a Huffman code table, and then the next bit of binary code is read until the matching with the Huffman code table is successful, the efficiency is low, and the decoding speed is slow.
Therefore, how to provide an efficient huffman decoding method and device thereof is a problem that needs to be solved by those skilled in the art.
Disclosure of Invention
The invention aims to provide a Huffman decoding method and a device thereof, which read a multi-bit binary code by taking a group as a unit for decoding and have high decoding efficiency; and the reading process and the decoding process do not interfere with each other, the flow process can be realized, and the Huffman decoding speed is high.
In order to solve the above technical problem, the present invention provides a huffman decoding method, comprising:
step s 1: reading a plurality of groups of binary code groups from a bit stream to be decoded in sequence; the number of binary codes contained in each binary code group is more than 1;
step s 2: respectively and sequentially carrying out Huffman decoding on each group of binary code groups to obtain a decoding result corresponding to the binary code on the bit stream to be decoded, wherein the decoding result comprises a decoding character and a decoding length, and the decoding length is the bit number of the binary code corresponding to the decoding character in a preset Huffman code table;
step s 3: reading the decoding character corresponding to the decoding position, sequentially shifting the decoding position backwards by corresponding digits according to the decoding length corresponding to the decoding position, taking the position corresponding to the backward shift as the decoding position, and repeating the step s 3; until decoding is completed; and the initial decoding position is a starting binary code of the bit stream to be decoded.
Preferably, the process of step s1 is specifically:
sequentially reading L-bit binary codes from the reading initial position on the bit stream to be decoded to obtain a binary code group; l is more than or equal to m + n-1; m is the number of decoders, and n is the longest coding length of the Huffman code table; shifting the reading initial position by m bits to be used as a new reading initial position, and repeating the reading operation;
correspondingly, the process of step s2 is specifically as follows:
m decoders respectively and sequentially carry out Huffman decoding on each binary code group; the ith decoder performs Huffman decoding from the ith bit of the binary code group to obtain a decoding result at the ith bit of the binary code group; i is more than or equal to 1 and less than or equal to m, and i is a positive integer.
Preferably, the process of step s1 is specifically:
and taking each binary code on the bit stream to be decoded as a reading initial position to sequentially read the n binary codes to obtain a plurality of groups of binary code groups.
Preferably, the process of step s2 is specifically:
and respectively carrying out Huffman decoding from the first binary code of each binary code group to obtain a decoding result corresponding to the first binary code of the binary code group.
Preferably, the huffman code table is a normal huffman code table, and the process of step s2 specifically includes:
filling zero to the right side of the binary code group with less than n bits, and expanding the binary code group into an n-bit binary code group;
zero padding the right side of the code corresponding to each character in the Huffman code table, and expanding the code into n-bit code;
calculating each expanded coded value, and respectively recording the minimum value of the coded values of a plurality of codes with the same original coding length to obtain k minimum values serving as threshold values, wherein k is less than or equal to n;
calculating the numerical value D of each binary code group; respectively comparing the D with the k threshold values in the descending order, if the D is smaller than the current comparison threshold value, recording the comparison result as 0, otherwise, recording the comparison result as 1, and sequencing the comparison results from left to right according to the sequence of the comparison order to obtain a k-bit mask; if k is less than n, adjusting the k to be n-bit mask according to a preset rule;
performing bitwise AND operation on the binary code group and the n-bit mask to obtain an n-bit result code, and calculating a numerical value I of the n-bit result code; and obtaining a decoding result corresponding to the first binary code of the binary code group according to the I.
Preferably, the decoding result further includes a valid identifier, and after the decoded character is obtained, the valid identifier corresponding to the decoding result is true, otherwise, the valid identifier is false.
In order to solve the above technical problem, the present invention further provides a huffman decoding apparatus, comprising:
the reading module is used for sequentially reading a plurality of groups of binary code groups from the bit stream to be decoded; the number of binary codes contained in each binary code group is more than 1;
the decoding module is used for respectively and sequentially carrying out Huffman decoding on each group of binary code groups to obtain a decoding result corresponding to the binary code on the bit stream to be decoded, wherein the decoding result comprises a decoding character and a decoding length, and the decoding length is the bit number of the binary code corresponding to the decoding character in a preset Huffman code table;
the merging module is used for sequentially shifting the decoding positions backwards by corresponding digits according to the decoding lengths corresponding to the decoding positions after reading the decoding characters corresponding to the decoding positions, taking the positions corresponding to the positions after shifting backwards as the decoding positions, and repeating the operation of the merging module; until decoding is completed; and the initial decoding position is a starting binary code of the bit stream to be decoded.
Preferably, the decoding module comprises m decoders;
the reading module is specifically configured to:
sequentially reading L-bit binary codes from the reading initial position on the bit stream to be decoded to obtain a binary code group; l is more than or equal to m + n-1; m is the number of decoders, and n is the longest coding length of the Huffman code table; shifting the reading initial position by m bits to be used as a new reading initial position, and repeating the reading operation;
the m decoders are used for respectively and sequentially carrying out Huffman decoding on each binary code group; the ith decoder performs Huffman decoding from the ith bit of the binary code group to obtain a decoding result at the ith bit of the binary code group; i is more than or equal to 1 and less than or equal to m, and i is a positive integer; and after the m decoders finish decoding the binary code group, sending the obtained binary code group to the merging module for processing.
Preferably, the reading module is specifically configured to:
and respectively taking each binary code on the bit stream to be decoded as a reading initial position to sequentially read the m binary codes to obtain a plurality of groups of binary code groups.
The invention provides a Huffman decoding method and a device thereof, wherein a group of binary code groups are read from a bit stream to be decoded each time, and then the read groups of binary code groups are respectively subjected to Huffman decoding to obtain a decoding result corresponding to the binary code on the bit stream to be decoded, so as to obtain a decoded character. It can be seen that the invention reads the multi-bit binary code in parallel as a group for decoding instead of reading one bit of binary code each time, thereby greatly improving the speed of Huffman decoding and having high decoding efficiency. In the reading process, the binary code groups are sequentially read from the bit stream to be decoded, namely, the next group is continuously read after each group is read; and in the decoding process, all groups of binary code groups are respectively and sequentially decoded, and then merging operation is carried out according to the decoding result to obtain the final decoding result. Therefore, the invention realizes the flow process, the reading process and the decoding process are not interfered with each other, the reading process and the decoding process can be carried out simultaneously and in parallel, and the decoding speed of the invention is greatly improved compared with the prior serial operation that the next reading is carried out after the decoding is finished.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed in the prior art and the embodiments will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings without creative efforts.
FIG. 1 is a flow chart of a process of a Huffman decoding method provided by the present invention;
FIG. 2 is a flow chart of the process of another Huffman decoding method provided by the present invention;
FIG. 3 is a flow chart of the process of another Huffman decoding method provided by the present invention;
fig. 4 is a schematic structural diagram of a huffman decoding apparatus provided in the present invention.
Detailed Description
The core of the invention is to provide a Huffman decoding method and a device thereof, which read the multi-bit binary code by taking a group as a unit for decoding and have high decoding efficiency; and the reading process and the decoding process do not interfere with each other, the flow process can be realized, and the Huffman decoding speed is high.
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Example one
The invention provides a huffman decoding method, and as shown in fig. 1, fig. 1 is a flow chart of the process of the huffman decoding method provided by the invention; the method comprises the following steps:
step s 1: reading a plurality of groups of binary code groups from a bit stream to be decoded in sequence; the number of binary codes contained in each group of binary code groups is more than 1;
step s 2: respectively and sequentially carrying out Huffman decoding on each group of binary code groups to obtain a decoding result corresponding to the binary code on the bit stream to be decoded, wherein the decoding result comprises decoding characters and a decoding length, and the decoding length is the bit number of the binary code corresponding to the decoding characters in a preset Huffman code table;
step s 3: after reading the decoding character corresponding to the decoding position, sequentially shifting the decoding position backwards by corresponding digits according to the decoding length corresponding to the decoding position, taking the position corresponding to the backward shift as the decoding position, and repeating the step s 3; until decoding is completed; and the initial decoding position is a starting binary code of the bit stream to be decoded.
It can be understood that each character in the huffman code table corresponds to a string of binary code strings, and the number of bits of the binary code included in a binary code string is the decoding length corresponding to the character. Because the invention can obtain the decoding result corresponding to each binary code in the bit stream to be decoded (here, the decoding result corresponding to the binary code refers to the decoding result obtained after decoding by taking the binary code as the decoding initial position), and the bit stream to be decoded contains the condition that the multi-bit binary code corresponds to one character, the obtained decoding result contains invalid decoding results, and the specific decoding results corresponding to which binary codes are invalid are identified through the step s 4.
For example, if the bit stream to be decoded is 10, the code of b in the huffman code table is 10, and the code of e is 0, the corresponding result obtained after the step s2 should be the first 1 corresponding to b, and the decoding length is 2; the second 0 corresponds to e, the decoding length is 1; in practice 10 should represent a character b so only the first 1 position is the decoded position and the second 0 should be skipped as the invalid decoded position.
The invention provides a Huffman decoding method, which reads a group of binary code groups from a bit stream to be decoded each time, and then respectively performs Huffman decoding on each group of read binary code groups to obtain a decoding result corresponding to a binary code on the bit stream to be decoded, thereby obtaining a decoded character. It can be seen that the invention reads the multi-bit binary code in parallel as a group for decoding instead of reading one bit of binary code each time, thereby greatly improving the speed of Huffman decoding and having high decoding efficiency. In the reading process, the binary code groups are sequentially read from the bit stream to be decoded, namely, the next group is continuously read after each group is read; and in the decoding process, all groups of binary code groups are respectively and sequentially decoded, and then merging operation is carried out according to the decoding result to obtain the final decoding result. Therefore, the invention realizes the flow process, the reading process and the decoding process are not interfered with each other, the reading process and the decoding process can be carried out simultaneously and in parallel, and the decoding speed of the invention is greatly improved compared with the prior serial operation that the next reading is carried out after the decoding is finished.
Example two
Based on the first embodiment, the invention also provides another Huffman decoding method.
Referring to fig. 2, fig. 2 is a flowchart of a process of another huffman decoding method provided by the present invention. The process of step s1 specifically includes:
sequentially reading L-bit binary codes from a reading initial position on a bit stream to be decoded to obtain a binary code group; l is more than or equal to m + n-1; m is the number of decoders, and n is the longest coding length of a Huffman code table; shifting the reading initial position by m bits to be used as a new reading initial position, and repeating the reading operation;
correspondingly, the process of step s2 is specifically as follows:
m decoders respectively and sequentially carry out Huffman decoding on each group of binary code groups; the ith decoder starts to carry out Huffman decoding from the ith bit of the binary code group to obtain a decoding result at the ith bit of the binary code group; i is more than or equal to 1 and less than or equal to m, and i is a positive integer.
It can be understood that due to the characteristic of huffman decoding serial decoding, the next position to start decoding can be determined only by completing decoding first each time, so that only one character can be decoded at a time, and the efficiency is low; the m decoders decode the first m binary codes in each binary code group respectively to obtain the decoding result obtained after decoding each binary code on the bit stream to be decoded with the initial position, and then the invalid decoding result is removed in step s4 to obtain the final decoded character. That is, the embodiment adopts a parallel decoding mode, and can decode the m-bit binary code each time to obtain a plurality of decoded characters, thereby greatly improving the decoding speed and efficiency.
In step s4, each time a group of binary code groups is decoded, the process starts, and at this time, m decoders can decode the next group of binary code groups. It can be seen that, at this time, the reading process, the decoding process and the character merging process in the step s4 are performed simultaneously without mutual interference, so that the streamlined processing of the whole process is realized, and the decoding speed is greatly increased.
In addition, since m decoders need to decode the first m-bit binary codes in each group of binary codes, in order to ensure that the last decoder can also work normally, each group of binary codes cannot only contain m bits, but n-1 bits are added, because the longest coding length required for decoding is n, the last decoder can have n-bit binary codes for decoding operation by adding the binary codes at the decoding start position of the last decoder. Wherein m should be not less than 1, and the size of m and n is determined according to the specific situation.
For convenience of understanding, the above embodiment is explained below with respect to a specific example.
Assuming that the bit stream to be decoded is "1000111011111000110", 8(m) decoders are used, and the used huffman code table is shown in table 1; table 1 is a huffman code table in this example;
TABLE 1 Huffman code Table
Figure BDA0001166875710000071
Each time 12 bits (m + n-8 + 4-12) are read from the bitstream to be decoded, each subsequent read is shifted to the right by 8 bits until the end bit. In this embodiment, the result of reading the binary code three times is shown in table 2.
TABLE 2 result of each reading of binary code
Figure BDA0001166875710000072
The 8 decoders start decoding from the ith bit of the current group read-in binary code group (i is the decoder number). The decoding results corresponding to the binary code groups read at each time are shown in table 3.
TABLE 3 results of decoding at a time
Figure BDA0001166875710000081
The result of table 1 is subjected to effective decoded character reading according to step s4, and the decoded character string "beepbeer" is obtained. As shown in table 4, table 4 shows the decoding end result.
TABLE 4 Final results of decoding
Bit stream 1 0 0 0 1 1 1 0 1 1 1 1 1 0 0 0 1 1 0
Decoding characters b e e p Blank space b e e r
Decoding length 2 1 1 4 4 2 1 1 3
Decoding position 0 2 3 4 8 12 14 15 16
Decoder 0 2 3 4 0 4 6 7 0
In another embodiment, the process of step s1 is specifically as follows:
and respectively taking each binary code on the bit stream to be decoded as a reading initial position to sequentially read the n binary codes to obtain a plurality of groups of binary code groups.
It is further understood that, referring to fig. 3, fig. 3 is a flow chart of a process of another huffman decoding method provided by the present invention. The process of step s2 specifically includes:
and respectively carrying out Huffman decoding from the first binary code of each binary code group to obtain a decoding result corresponding to the first binary code of the binary code group.
It can be understood that, since the longest code length in the huffman code table is n, if each group includes n-bit binary codes, except the start position, the decoding result obtained by using the first bit of the binary code group as the decoding start position can be obtained by decoding, so as to obtain the decoding result corresponding to each bit binary code in the bitstream to be decoded.
In this step, a plurality of decoders can simultaneously and respectively perform decoding operation on the one-bit binary code group, thereby achieving the purpose of parallel decoding.
It is further known that the huffman code table is a canonical huffman code table, and the process of step s2 specifically includes:
step s 201: filling zero to the right side of the binary code group with less than n bits, and expanding the binary code group into an n-bit binary code group;
it can be understood that, taking each binary code on the bit stream to be decoded as the reading start position to read n binary codes in sequence, the number of binary codes included in the last n-1 binary code groups is less than n, so that 0 needs to be complemented.
Step s 202: zero padding the right side of the code corresponding to each character in the Huffman code table, and expanding the code into n-bit code;
thus, each character in the huffman code table corresponds to an n-bit code, and since the codes with the same length in the normal huffman code are binary descriptions of continuous integers, that is, if the codes with the same length corresponding to two characters are the same, the calculated values of the binary codes corresponding to the two characters are continuous, for example, 0011,0100. Therefore, in the normal huffman coding, the n-bit coded values obtained after zero padding of the codes corresponding to the characters are arranged in the order from small to large.
Step s 203: calculating each expanded coded value, and respectively recording the minimum value of the coded values of a plurality of codes with the same original coding length to obtain k minimum values serving as threshold values, wherein k is less than or equal to n;
the original encoding length here refers to the encoding length corresponding to the character before zero padding, for example, b and e both correspond to 2-bit encoding, and after zero padding, both are padded to 4-bit encoding 1100 and 0100, whose values are 12 and 4, respectively, so that record 4 is recorded.
Step s 204: calculating the numerical value D of each binary code group; respectively comparing the D with k thresholds in a descending order, if the D is smaller than the current comparison threshold, recording the comparison result as 0, otherwise, recording the comparison result as 1, and sequencing the comparison results from left to right according to the sequence of the comparison order to obtain a k-bit mask; if k is less than n, adjusting the k to be n-bit mask according to a preset rule;
wherein, if there are several lengths of original codes in the huffman code table, several thresholds will be obtained, where k is not necessarily equal to n, and if k < n, the obtained k is the foremost 1 of the mask.
Step s 205: performing bitwise AND operation on the binary code group and the n-bit mask to obtain an n-bit result code, and calculating the numerical value I of the n-bit result code; and obtaining a decoding result corresponding to the first binary code of the binary code group according to the I.
And comparing the value of the result code with the value of the n-bit code corresponding to each character after zero padding, wherein if the value of the result code is equal to the value of the n-bit code corresponding to each character after zero padding, the decoded character corresponding to the first bit of the binary code group is the character corresponding to the equal n-bit code, and further obtaining the decoding length (the original coding length corresponding to the decoded character).
Preferably, the decoding result further includes a valid identifier, and after the decoded character is obtained, the valid identifier corresponding to the decoding result is true, and otherwise, the valid identifier is false.
It is to be understood that, in step s4, when no decoding result is obtained at the decoding position, it generally indicates that the decoding at the position is not completed yet, and needs to wait; however, even if there is a decoding result at the decoding position, the decoding result is generated by a system error operation or the decoding result does not include a decoding character, so that the skipping of the decoding position can be judged by the valid identifier being false. If the starting position of the current decoding position is not correct, the valid identifier in the decoding result is false, and certainly, if the system is wrong, the valid identifier is false.
In addition, in each of the above embodiments, the steps s3 and s4 may be performed after the decoding results corresponding to all binary codes in the bitstream to be decoded are obtained, or may be performed after the decoding results corresponding to a group of binary codes are obtained, or performed each time the decoding result corresponding to one bit of binary code is obtained. By adopting the second mode, the characters of the previous group of binary codes can be screened and read simultaneously in the process of decoding the next group of binary codes, and the aim of improving the decoding speed is fulfilled. Of course, the present invention is not limited to the specific manner in which the present invention is employed.
Compared with the first embodiment, the embodiment can realize the parallel decoding of a plurality of decoders, improve the Huffman decoding speed and have high efficiency; in addition, the invention also adds the effective identifier in the decoding result, avoids reading the error decoding character at the decoding position when the system has errors, and improves the accuracy of decoding.
The invention also provides a huffman decoding device, which is shown in fig. 4, and fig. 4 is a schematic structural diagram of the huffman decoding device provided by the invention. The device includes:
the reading module 1 is used for sequentially reading a plurality of groups of binary code groups from a bit stream to be decoded; the number of binary codes contained in each group of binary code groups is more than 1;
the decoding module 2 is configured to perform huffman decoding on each group of binary code groups in sequence to obtain a decoding result corresponding to the binary code on the bitstream to be decoded, where the decoding result includes a decoding character and a decoding length, and the decoding length is a bit number of the binary code corresponding to the decoding character in a preset huffman code table;
the merging module 3 is used for sequentially shifting the decoding positions backwards by corresponding digits according to the decoding lengths corresponding to the decoding positions after reading the decoding characters corresponding to the decoding positions, taking the positions corresponding to the positions after shifting backwards as the decoding positions, and repeating the self operation; until decoding is completed; and the initial decoding position is a starting binary code of the bit stream to be decoded.
Preferably, the decoding module 2 comprises m decoders;
the reading module 1 is specifically configured to:
sequentially reading L-bit binary codes from a reading initial position on a bit stream to be decoded to obtain a binary code group; l is more than or equal to m + n-1; m is the number of decoders, and n is the longest coding length of a Huffman code table; shifting the reading initial position by m bits to be used as a new reading initial position, and repeating the reading operation;
m decoders for performing huffman decoding on each group of binary code groups in sequence; the ith decoder starts to carry out Huffman decoding from the ith bit of the binary code group to obtain a decoding result at the ith bit of the binary code group; i is more than or equal to 1 and less than or equal to m, and i is a positive integer; and sends the obtained group of binary codes to the merging module 3 for processing.
It can be understood that, each group of decoding results is obtained and sent to the merging module 3 for processing, and the reading process, the decoding process and the merging process can be simultaneously performed, that is, the pipelining processing is realized, and the decoding speed is greatly improved.
In another embodiment, the reading module 1 is specifically configured to:
and respectively taking each binary code on the bit stream to be decoded as a reading initial position to sequentially read the m binary codes to obtain a plurality of groups of binary code groups.
The invention provides a Huffman decoding device, which reads a group of binary code groups from a bit stream to be decoded each time, and then respectively performs Huffman decoding on each group of read binary code groups to obtain a decoding result corresponding to a binary code on the bit stream to be decoded, thereby obtaining a decoded character. It can be seen that the invention reads the multi-bit binary code in parallel as a group for decoding instead of reading one bit of binary code each time, thereby greatly improving the speed of Huffman decoding and having high decoding efficiency. In the reading process, the binary code groups are sequentially read from the bit stream to be decoded, namely, the next group is continuously read after each group is read; and in the decoding process, all groups of binary code groups are respectively and sequentially decoded, and then merging operation is carried out according to the decoding result to obtain the final decoding result. Therefore, the invention realizes the flow process, the reading process and the decoding process are not interfered with each other, the reading process and the decoding process can be carried out simultaneously and in parallel, and the decoding speed of the invention is greatly improved compared with the prior serial operation that the next reading is carried out after the decoding is finished.
The embodiments in the present description are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other. The device disclosed by the embodiment corresponds to the method disclosed by the embodiment, so that the description is simple, and the relevant points can be referred to the method part for description.
It is further noted that, in the present specification, relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims (5)

1. A huffman decoding method, comprising:
step s 1: reading a plurality of groups of binary code groups from a bit stream to be decoded in sequence; the number of binary codes contained in each binary code group is more than 1;
step s 2: respectively and sequentially carrying out Huffman decoding on each group of binary code groups to obtain a decoding result corresponding to the binary code on the bit stream to be decoded, wherein the decoding result comprises a decoding character and a decoding length, and the decoding length is the bit number of the binary code corresponding to the decoding character in a preset Huffman code table;
step s 3: reading the decoding character corresponding to the decoding position, sequentially shifting the decoding position backwards by corresponding digits according to the decoding length corresponding to the decoding position, taking the position corresponding to the backward shift as the decoding position, and repeating the step s 3; until decoding is completed; wherein, the initial decoding position is a starting binary code of the bit stream to be decoded;
the process of step s1 specifically includes:
sequentially reading L-bit binary codes from the reading initial position on the bit stream to be decoded to obtain a binary code group; l is more than or equal to m + n-1; m is the number of decoders, and n is the longest coding length of the Huffman code table; shifting the reading initial position by m bits to be used as a new reading initial position, and repeating the reading operation; correspondingly, the process of step s2 is specifically as follows:
m decoders respectively and sequentially carry out Huffman decoding on each binary code group; the ith decoder performs Huffman decoding from the ith bit of the binary code group to obtain a decoding result at the ith bit of the binary code group; i is more than or equal to 1 and less than or equal to m, and i is a positive integer;
or, the process of step s1 specifically includes:
and taking each binary code on the bit stream to be decoded as a reading initial position to sequentially read the n binary codes to obtain a plurality of groups of binary code groups.
2. The method according to claim 1, wherein when the process of step s1 is to read n binary codes sequentially with each binary code on the bitstream to be decoded as a reading start position, respectively, to obtain a plurality of groups of binary code groups;
the process of step s2 specifically includes:
and respectively carrying out Huffman decoding from the first binary code of each binary code group to obtain a decoding result corresponding to the first binary code of the binary code group.
3. The method according to claim 2, wherein when the process of step s1 is to read n binary codes sequentially with each binary code on the bitstream to be decoded as a reading start position, respectively, to obtain a plurality of groups of binary code groups;
the huffman code table is a normal huffman code table, and the step s2 specifically includes:
filling zero to the right side of the binary code group with less than n bits, and expanding the binary code group into an n-bit binary code group;
zero padding the right side of the code corresponding to each character in the Huffman code table, and expanding the code into n-bit code;
calculating each expanded coded value, and respectively recording the minimum value of the coded values of a plurality of codes with the same original coding length to obtain k minimum values serving as threshold values, wherein k is less than or equal to n;
calculating the numerical value D of each binary code group; respectively comparing the D with the k threshold values in the descending order, if the D is smaller than the current comparison threshold value, recording the comparison result as 0, otherwise, recording the comparison result as 1, and sequencing the comparison results from left to right according to the sequence of the comparison order to obtain a k-bit mask; if k is less than n, adjusting the k to be n-bit mask according to a preset rule;
performing bitwise AND operation on the binary code group and the n-bit mask to obtain an n-bit result code, and calculating a numerical value I of the n-bit result code; and obtaining a decoding result corresponding to the first binary code of the binary code group according to the I.
4. The method according to any one of claims 1-3, wherein the decoding result further comprises a valid identifier, and after obtaining the decoded character, the valid identifier corresponding to the decoding result is true, otherwise, the valid identifier is false.
5. A huffman decoding apparatus, comprising:
the reading module is used for sequentially reading a plurality of groups of binary code groups from the bit stream to be decoded; the number of binary codes contained in each binary code group is more than 1;
the decoding module is used for respectively and sequentially carrying out Huffman decoding on each group of binary code groups to obtain a decoding result corresponding to the binary code on the bit stream to be decoded, wherein the decoding result comprises a decoding character and a decoding length, and the decoding length is the bit number of the binary code corresponding to the decoding character in a preset Huffman code table;
the merging module is used for sequentially shifting the decoding positions backwards by corresponding digits according to the decoding lengths corresponding to the decoding positions after reading the decoding characters corresponding to the decoding positions, taking the positions corresponding to the positions after shifting backwards as the decoding positions, and repeating the operation of the merging module; until decoding is completed; wherein, the initial decoding position is a starting binary code of the bit stream to be decoded;
the decoding module comprises m decoders;
the reading module is specifically configured to:
sequentially reading L-bit binary codes from the reading initial position on the bit stream to be decoded to obtain a binary code group; l is more than or equal to m + n-1; m is the number of decoders, and n is the longest coding length of the Huffman code table; shifting the reading initial position by m bits to be used as a new reading initial position, and repeating the reading operation;
the m decoders are used for respectively and sequentially carrying out Huffman decoding on each binary code group; the ith decoder performs Huffman decoding from the ith bit of the binary code group to obtain a decoding result at the ith bit of the binary code group; i is more than or equal to 1 and less than or equal to m, and i is a positive integer; after the m decoders finish decoding the binary code group, sending the obtained binary code group to the merging module for processing;
or, the reading module is specifically configured to:
and taking each binary code on the bit stream to be decoded as a reading initial position to sequentially read the n binary codes to obtain a plurality of groups of binary code groups.
CN201611080671.9A 2016-11-30 2016-11-30 Huffman decoding method and device Active CN106788451B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201611080671.9A CN106788451B (en) 2016-11-30 2016-11-30 Huffman decoding method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201611080671.9A CN106788451B (en) 2016-11-30 2016-11-30 Huffman decoding method and device

Publications (2)

Publication Number Publication Date
CN106788451A CN106788451A (en) 2017-05-31
CN106788451B true CN106788451B (en) 2021-03-09

Family

ID=58901436

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201611080671.9A Active CN106788451B (en) 2016-11-30 2016-11-30 Huffman decoding method and device

Country Status (1)

Country Link
CN (1) CN106788451B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111970007B (en) * 2020-08-13 2022-03-22 山东云海国创云计算装备产业创新中心有限公司 Decoding method, decoder, device and medium

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CA1156764A (en) * 1979-02-22 1983-11-08 Amitabh Saran Circuit for compacting variable length into fixed word length data
JPH0410716A (en) * 1990-04-27 1992-01-14 Ricoh Co Ltd Decoding circuit for huffman code
CN1124889A (en) * 1993-12-23 1996-06-19 株式会社理光 Method and apparatus for parallel encoding and decoding of data
CN1889366A (en) * 2006-07-13 2007-01-03 浙江大学 Hafman decoding method
CN101017574A (en) * 2007-02-16 2007-08-15 上海广电集成电路有限公司 Huffman decoding method suitable for JPEG code stream
CN101060337A (en) * 2007-05-22 2007-10-24 北京中星微电子有限公司 An optimized Huffman decoding method and device
CN104300990A (en) * 2013-03-15 2015-01-21 英特尔公司 Parallel apparatus for high-speed, highly compressed LZ77 tokenization and Huffman encoding for deflate compression
CN104980161A (en) * 2015-04-02 2015-10-14 深圳市腾讯计算机***有限公司 Huffman decoding method and device
CN106027066A (en) * 2015-03-28 2016-10-12 国际商业机器公司 Parallel huffman decoder for decoding, design structure and method

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7283591B2 (en) * 2003-03-28 2007-10-16 Tarari, Inc. Parallelized dynamic Huffman decoder
US7433519B2 (en) * 2003-04-04 2008-10-07 Avid Technology, Inc. Bitstream format for compressed image data
CN103326730B (en) * 2013-06-06 2016-05-18 清华大学 Data parallel compression method
CN106100641A (en) * 2016-06-12 2016-11-09 深圳大学 Multithreading quick storage lossless compression method and system thereof for FASTQ data

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CA1156764A (en) * 1979-02-22 1983-11-08 Amitabh Saran Circuit for compacting variable length into fixed word length data
JPH0410716A (en) * 1990-04-27 1992-01-14 Ricoh Co Ltd Decoding circuit for huffman code
CN1124889A (en) * 1993-12-23 1996-06-19 株式会社理光 Method and apparatus for parallel encoding and decoding of data
CN1889366A (en) * 2006-07-13 2007-01-03 浙江大学 Hafman decoding method
CN101017574A (en) * 2007-02-16 2007-08-15 上海广电集成电路有限公司 Huffman decoding method suitable for JPEG code stream
CN101060337A (en) * 2007-05-22 2007-10-24 北京中星微电子有限公司 An optimized Huffman decoding method and device
CN104300990A (en) * 2013-03-15 2015-01-21 英特尔公司 Parallel apparatus for high-speed, highly compressed LZ77 tokenization and Huffman encoding for deflate compression
CN106027066A (en) * 2015-03-28 2016-10-12 国际商业机器公司 Parallel huffman decoder for decoding, design structure and method
CN104980161A (en) * 2015-04-02 2015-10-14 深圳市腾讯计算机***有限公司 Huffman decoding method and device

Also Published As

Publication number Publication date
CN106788451A (en) 2017-05-31

Similar Documents

Publication Publication Date Title
US11595055B2 (en) Methods and apparatus to parallelize data decompression
CN108768403B (en) LZW-based lossless data compression and decompression method, LZW encoder and decoder
JP6025923B2 (en) System and method for compressing a stream of integer data
US8089379B2 (en) Variable length decoding apparatus and method
KR101678223B1 (en) Multimedia signature coding and decoding
US12010352B2 (en) Coding method and related device
CN109495211B (en) Channel coding and decoding method
CN113630125A (en) Data compression method, data encoding method, data decompression method, data encoding device, data decompression device, electronic equipment and storage medium
CN106788451B (en) Huffman decoding method and device
JP5815113B2 (en) Techniques for CABAC decoding
CN1741614A (en) Method and system for decoding video, voice, and speech data using redundancy
US20070186139A1 (en) Interleaving method for low density parity check encoding
CN115549698A (en) Encoding method and encoder, decoding method and decoder, communication system
CN110958025B (en) Short frame length coding and decoding method based on superposition
CN114614832A (en) Test data compression and decompression method based on front and back run length coding
CN112534724B (en) Decoder and method for decoding polarization code and product code
CN109802690B (en) Decoding method, device and computer readable storage medium
CN107565980B (en) Decoding method and decoder
US20100013679A1 (en) Decoder and method for decoding a message using an arbitrary-side growing huffman tree
CN107592958B (en) Multi-rate LDPC encoding and decoding using one multi-rate exponential table and one spreading factor at different code lengths
US20240235576A9 (en) Noniterative entropy coding
US20160323603A1 (en) Method and apparatus for performing an arithmetic coding for data symbols
WO2005043765A2 (en) Resilient parameterized prefix codes for adaptive coding
CN114499751A (en) List enhancement decoding method and device based on polarization ALOHA
Bharti et al. Construction algorithms for RVLCs: A survey

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
TA01 Transfer of patent application right
TA01 Transfer of patent application right

Effective date of registration: 20210203

Address after: Building 9, No.1, guanpu Road, Guoxiang street, Wuzhong Economic Development Zone, Wuzhong District, Suzhou City, Jiangsu Province

Applicant after: SUZHOU LANGCHAO INTELLIGENT TECHNOLOGY Co.,Ltd.

Address before: Room 1601, floor 16, 278 Xinyi Road, Zhengdong New District, Zhengzhou City, Henan Province

Applicant before: ZHENGZHOU YUNHAI INFORMATION TECHNOLOGY Co.,Ltd.

GR01 Patent grant
GR01 Patent grant