A data encoding method, system, device and computer readable storage medium
By using a preset encoding table to encode data when the Huffman tree depth exceeds a preset value, the problem of low efficiency of Huffman coding is solved, achieving a fast and efficient data encoding process while maintaining the compression ratio.
Patent Information
- Application Number
- CN202111032573.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-03
- Publication Date
- 2025-11-18
- Estimated Expiration
- 2041-09-03
AI Technical Summary
In existing technologies, dynamic Huffman coding requires processing leaf nodes one by one when the depth of the Huffman tree exceeds the maximum depth, resulting in a lengthy, cumbersome, and inefficient coding process.
When the initial Huffman tree depth exceeds the preset depth, the data to be encoded is directly encoded using the preset encoding table and encapsulated according to the encoding format of dynamic Huffman coding, avoiding the need to process each leaf node in the Huffman tree that exceeds the length one by one.
It improves encoding efficiency, reduces encoding time, maintains compression ratio, and enables decoding according to dynamic Huffman coding.
Smart Images

Figure CN113852379B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of information processing technology, and more specifically, to a data encoding method, system, device, and computer-readable storage medium. Background Technology
[0002] In recent years, with the continuous development of science and technology, data information has experienced explosive growth. The rise of cloud computing, the advancement of artificial intelligence, and the arrival of the big data era have led to a continuous increase in workload, and the problems of massive data transmission and storage have attracted increasing attention. How to efficiently transmit massive amounts of data without placing an excessive burden on the processor urgently needs to be solved. Compressing files can not only save data bandwidth but also reduce transmission time; in other words, data can be compressed for processing. For example, dynamic Huffman coding can be used to compress data. However, dynamic Huffman coding sets a maximum code length, which in turn sets a maximum depth for the Huffman tree. When the actual depth of the Huffman tree exceeds this maximum depth, the leaf nodes exceeding the length need to be processed one by one to bring the depth of the Huffman tree within the required range. This entire process is lengthy, cumbersome, and inefficient.
[0003] In conclusion, how to quickly perform Huffman coding is a problem that urgently needs to be solved by those skilled in the art. Summary of the Invention
[0004] The purpose of this application is to provide a data encoding method that can, to some extent, solve the technical problem of how to perform Huffman coding quickly. This application also provides a data encoding system, device, and computer-readable storage medium.
[0005] To achieve the above objectives, this application provides the following technical solution:
[0006] A data encoding method, comprising:
[0007] Obtain the data to be encoded;
[0008] Statistically analyze the characters to be encoded in the data to be encoded and the frequency of occurrence of each character;
[0009] An initial Huffman tree is generated based on the character to be encoded and its frequency of occurrence.
[0010] Determine whether the depth of the initial Huffman tree is greater than a preset depth;
[0011] If the depth of the initial Huffman tree is greater than the preset depth, the data to be encoded is encoded based on the preset encoding table to obtain initial encoded data. The initial encoded data is then encapsulated according to the encoding format of dynamic Huffman coding to obtain target encoded data.
[0012] Preferably, the step of encoding the data to be encoded based on a preset encoding table to obtain initial encoded data includes:
[0013] Identify the first type of characters that appear repeatedly in the data to be encoded and have a length greater than or equal to 3;
[0014] Calculate the length of each character of the first type;
[0015] Identify the second type of character that appears alone in the data to be encoded;
[0016] The first type of characters, the length, and the second type of characters are encoded based on the preset encoding table to obtain the initial encoded data.
[0017] Preferably, the step of encoding the first type of characters, the length, and the second type of characters based on the preset encoding table to obtain the initial encoded data includes:
[0018] The first type of characters and the second type of characters are encoded based on the ASCII code table to obtain the first encoding result;
[0019] The length is encoded based on the Huffman length encoding table to obtain a second encoding result;
[0020] The first encoding result and the second encoding result are encoded based on the preset encoding table to obtain the initial encoding result.
[0021] Preferably, the encoding result of the ASCII code table is an integer between 0 and 255; the encoding result of the Huffman length encoding table is an integer between 257 and 285.
[0022] Preferably, the preset encoding table encodes integers between 0 and 143 and integers between 280 and 285 as 8-bit data; integers between 144 and 255 as 9-bit data; and integers between 256 and 279 as 7-bit data.
[0023] Preferably, after encapsulating the initial encoded data according to the encoding format of dynamic Huffman coding to obtain the target encoded data, the method further includes:
[0024] The preset encoding table is stored using a Huffman tree storage method.
[0025] Preferably, the preset depth value includes 15.
[0026] A data encoding system, comprising:
[0027] The first acquisition module is used to acquire the data to be encoded.
[0028] The first statistics module is used to count the characters to be encoded in the data to be encoded and the frequency of occurrence of each character to be encoded;
[0029] The first generation module is used to generate an initial Huffman tree based on the character to be encoded and its frequency of occurrence.
[0030] The first judgment module is used to determine whether the depth of the initial Huffman tree is greater than a preset depth; if the depth of the initial Huffman tree is greater than the preset depth, the data to be encoded is encoded based on the preset encoding table to obtain initial encoded data, and the initial encoded data is encapsulated according to the encoding format of dynamic Huffman coding to obtain target encoded data.
[0031] A data encoding device, comprising:
[0032] Memory, used to store computer programs;
[0033] A processor for implementing the steps of the data encoding method as described in any of the preceding claims when executing the computer program.
[0034] A computer-readable storage medium storing a computer program that is executed by a processor to implement the steps of the data encoding method described in any of the preceding claims.
[0035] This application provides a data encoding method that involves: acquiring data to be encoded; statistically analyzing the characters to be encoded and their frequency of occurrence in the data; generating an initial Huffman tree based on the characters and their frequencies; determining whether the depth of the initial Huffman tree is greater than a preset depth; if the depth of the initial Huffman tree is greater than the preset depth, encoding the data to be encoded using a preset encoding table to obtain initial encoded data; and encapsulating the initial encoded data according to the encoding format of dynamic Huffman coding to obtain target encoded data. In this application, after the initial Huffman tree depth of the data to be encoded exceeds the preset depth, the preset encoding table is directly used to encode the data, eliminating the need to process each leaf node exceeding the length in the Huffman tree individually, thus improving encoding efficiency. This application also provides a data encoding system, device, and computer-readable storage medium that solves the corresponding technical problems. Attached Figure Description
[0036] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0037] Figure 1 A flowchart illustrating a data encoding method provided in an embodiment of this application;
[0038] Figure 2 This is a schematic diagram of the structure of a data encoding system provided in an embodiment of this application;
[0039] Figure 3 This is a schematic diagram of the structure of a data encoding device provided in an embodiment of this application;
[0040] Figure 4 This is another structural schematic diagram of a data encoding device provided in an embodiment of this application. Detailed Implementation
[0041] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0042] Please see Figure 1 , Figure 1 This is a flowchart illustrating a data encoding method provided in an embodiment of this application.
[0043] This application provides a data encoding method that may include the following steps:
[0044] Step S101: Obtain the data to be encoded.
[0045] In practical applications, the data to be encoded can be obtained first. The type, content, and size of the data to be encoded can be determined according to actual needs, and this application does not make specific limitations here.
[0046] Step S102: Count the characters to be encoded and the frequency of each character in the data to be encoded.
[0047] In practical applications, after obtaining the data to be encoded, we can first try to encode the data based on the dynamic Huffman coding method. That is, we can first count the characters to be encoded in the data and the frequency of each character.
[0048] Step S103: Generate an initial Huffman tree based on the character to be encoded and its frequency of occurrence.
[0049] In practical applications, after statistically analyzing the characters to be encoded and the frequency of each character in the data to be encoded, an initial Huffman tree can be generated based on the characters to be encoded and their frequencies. The generation process of the Huffman tree can be found in existing technologies, and will not be elaborated here.
[0050] Step S104: Determine whether the depth of the initial Huffman tree is greater than the preset depth; if the depth of the initial Huffman tree is greater than the preset depth, then proceed to step S105.
[0051] Step S105: Encode the data to be encoded based on the preset encoding table to obtain the initial encoded data, and encapsulate the initial encoded data according to the encoding format of dynamic Huffman coding to obtain the target encoded data.
[0052] In practical applications, if the depth of the initial Huffman tree is greater than the preset depth, the leaf nodes that exceed the length in the initial Huffman tree need to be processed one by one so that the depth of the final Huffman tree is less than or equal to the preset depth. This will reduce the data encoding efficiency. To solve this problem, this method does not perform Huffman encoding based on the initial Huffman tree when the depth of the initial Huffman tree is greater than the preset depth. Instead, it directly encodes the data to be encoded based on the preset encoding table to obtain the initial encoded data. Then, it encapsulates the initial encoded data according to the encoding format of dynamic Huffman encoding to obtain the target encoded data, thereby quickly obtaining the target encoded data.
[0053] It should be noted that the preset depth value can be determined according to actual needs. For example, the preset depth can be directly the maximum depth of the Huffman tree during Huffman coding, that is, the preset depth value can be directly 15. Of course, the preset depth can also be determined according to specific application scenarios. For example, when the initial Huffman tree depth is close to 15, such as 16 or 18, and processing the leaf nodes of the initial Huffman tree will not significantly reduce the coding efficiency, the preset depth value can also be 16 or 18, etc. This application does not make specific limitations here. Furthermore, after obtaining the target encoded data, the target encoded data can be transmitted, stored, and performed other operations, which are not specifically limited here.
[0054] This application provides a data encoding method that involves: acquiring data to be encoded; statistically analyzing the characters to be encoded and their frequency of occurrence in the data; generating an initial Huffman tree based on the characters and their frequencies; determining whether the depth of the initial Huffman tree is greater than a preset depth; if the depth of the initial Huffman tree is greater than the preset depth, encoding the data to be encoded using a preset encoding table to obtain initial encoded data; and encapsulating the initial encoded data according to the encoding format of dynamic Huffman coding to obtain target encoded data. In this application, after the initial Huffman tree depth of the data to be encoded exceeds the preset depth, the preset encoding table is directly used to encode the data, eliminating the need to process each leaf node exceeding the length in the Huffman tree individually, thus improving encoding efficiency.
[0055] In a data encoding method provided in this application embodiment, in the process of encoding the data to be encoded based on a preset encoding table to obtain initial encoded data, in order to quickly encode the data, the first type of characters that appear repeatedly in the data to be encoded and have a length greater than or equal to 3 can be identified; the length of each first type of character can be counted; the second type of characters that appear alone in the data to be encoded can be identified; and the first type of characters, the length, and the second type of characters can be encoded based on the preset encoding table to obtain the initial encoded data.
[0056] In specific application scenarios, considering that the characters to be encoded may contain numbers, symbols, letters, etc., and the ASCII code table can quickly encode these characters, in order to further improve the data encoding efficiency, in the process of encoding the first type of characters, length, and second type of characters based on the preset encoding table to obtain the initial encoded data, the first type of characters and the second type of characters can be encoded based on the ASCII code table to obtain the first encoding result; the length can be encoded based on the Huffman length encoding table to obtain the second encoding result; and the first encoding result and the second encoding result can be encoded based on the preset encoding table to obtain the initial encoding result.
[0057] In specific application scenarios, to facilitate the distinction between the first and second encoding results, and to facilitate the recording of the first and second encoding results, the encoding result of the ASCII code table can be set to an integer between 0 and 255 during the encoding process; the encoding result of the Huffman length encoding table can be set to an integer between 257 and 285. Descriptions of the ASCII code table and the Huffman length encoding table can be found in existing technologies.
[0058] In specific application scenarios, considering that the encoding results of ASCII code 0-143 appear more frequently in text compared to the encoding results of 144-255, it is advisable to use 8 bits to describe the encoding results of 0-143, and 9 bits to describe the encoding results of 144-255; 256-279 is the length allocation range. Since data pairs containing distance and length information frequently appear in deflate format, 7 bits can be used to describe the length information; and the final range of 280-285 represents a longer matching length range. Compared to the previous length range, this range has a lower probability of occurrence, so it is reasonable to assign it 8 bits. Therefore, this application can set the preset encoding table to encode integers between 0 and 143 and integers between 280 and 285 as 8 bits; integers between 144 and 255 as 9 bits; and integers between 256 and 279 as 7 bits. Its format can be as shown in Table 1, where LitValue represents the data before encoding, Bits represents the data size, and Codes represents the encoding result.
[0059] Table 1. Encoding Results of the Preset Encoding Table
[0060]
[0061]
[0062] In practical applications, to facilitate understanding of the effectiveness of this method, the coding time and compression ratio of this method are compared with those of existing dynamic Huffman coding. The comparison results can be found in Tables 2 and 3. Table 2 compares the time taken by tree iteration for processing very long dynamic Huffman coding with that of this method, with the time unit being clock cycles. As shown in Table 2, the very long code compression scheme based on lookup tables in this method is about 1 / 3 more efficient than existing very long dynamic Huffman coding. Table 3 compares the compression ratio of tree iteration for processing very long dynamic Huffman coding with that of this method. As shown in Table 3, the difference in compression ratio between the two methods is very small, with no significant loss. Therefore, this method can improve efficiency while maintaining the compression ratio.
[0063] Table 2 compares the processing time of tree iteration for processing VLTHuffman codes with that of the proposed method.
[0064] Number of test rounds Dynamic Huffman Coding This method 1 2589 1842 2 2713 1935 3 2272 1508 4 2044 1323 5 2437 1756
[0065] Table 3 Comparison of compression rates between tree-based iterative compression and the proposed method for processing ultra-long dynamic Huffman codes.
[0066]
[0067] In the data encoding method provided in this application embodiment, considering the subsequent decoding requirements, and the decoding can be performed according to the dynamic Huffman encoding decoding method, after the initial encoded data is encapsulated according to the dynamic Huffman encoding encoding format to obtain the target encoded data, the preset encoding table can also be stored according to the Huffman tree storage method.
[0068] Please see Figure 2 , Figure 2 This is a schematic diagram of the structure of a data encoding system provided in an embodiment of this application.
[0069] This application provides a data encoding system that may include:
[0070] The first acquisition module 101 is used to acquire the data to be encoded.
[0071] The first statistics module 102 is used to count the characters to be encoded in the data to be encoded and the frequency of occurrence of each character to be encoded;
[0072] The first generation module 103 is used to generate an initial Huffman tree based on the character to be encoded and its frequency of occurrence.
[0073] The first judgment module 104 is used to determine whether the depth of the initial Huffman tree is greater than the preset depth. If the depth of the initial Huffman tree is greater than the preset depth, the data to be encoded is encoded based on the preset encoding table to obtain the initial encoded data. The initial encoded data is then encapsulated according to the encoding format of dynamic Huffman coding to obtain the target encoded data.
[0074] This application provides a data encoding system, wherein the first judgment module may include:
[0075] The first determination submodule is used to determine the first type of characters that appear repeatedly in the data to be encoded and have a length greater than or equal to 3.
[0076] The first statistics submodule is used to count the length of each first-category character;
[0077] The second determination submodule is used to determine the second type of character that appears alone in the data to be encoded;
[0078] The first encoding submodule is used to encode the first type of characters, length, and second type of characters based on a preset encoding table to obtain initial encoded data.
[0079] This application provides a data encoding system, wherein the first encoding submodule may include:
[0080] The first encoding unit is used to encode the first type of characters and the second type of characters based on the ASCII code table to obtain the first encoding result;
[0081] The second encoding unit is used to encode the length based on the Huffman length encoding table to obtain the second encoding result;
[0082] The third encoding unit is used to encode the first encoding result and the second encoding result based on a preset encoding table to obtain the initial encoding result.
[0083] The data encoding system provided in this application embodiment has ASCII code table encoding results in integers between 0 and 255; and Huffman length encoding table encoding results in integers between 257 and 285.
[0084] The data encoding system provided in this application embodiment has a preset encoding table that encodes integers between 0 and 143 and integers between 280 and 285 as 8-bit data; integers between 144 and 255 as 9-bit data; and integers between 256 and 279 as 7-bit data.
[0085] The data encoding system provided in this application embodiment may further include:
[0086] The first storage module is used by the first judgment module to encapsulate the initial encoded data according to the encoding format of dynamic Huffman coding, and after obtaining the target encoded data, to store the preset encoding table according to the Huffman tree storage method.
[0087] This application provides a data encoding system in which the preset depth value includes 15.
[0088] This application also provides a data encoding device and a computer-readable storage medium, both of which have the corresponding effects of the data encoding method provided in the embodiments of this application. Please refer to... Figure 3 , Figure 3 This is a schematic diagram of the structure of a data encoding device provided in an embodiment of this application.
[0089] This application provides a data encoding device, including a memory 201 and a processor 202. The memory 201 stores a computer program, and the processor 202 executes the computer program to perform the following steps:
[0090] Obtain the data to be encoded;
[0091] Statistically analyze the characters to be encoded in the data to be encoded and the frequency of each character.
[0092] Generate an initial Huffman tree based on the characters to be encoded and their frequency of occurrence;
[0093] Determine if the depth of the initial Huffman tree is greater than the preset depth; if the depth of the initial Huffman tree is greater than the preset depth, then encode the data to be encoded based on the preset encoding table to obtain the initial encoded data, and encapsulate the initial encoded data according to the encoding format of dynamic Huffman coding to obtain the target encoded data.
[0094] This application provides a data encoding device, including a memory 201 and a processor 202. The memory 201 stores a computer program. When the processor 202 executes the computer program, it performs the following steps: determining a first type of character that appears repeatedly in the data to be encoded and has a length greater than or equal to 3; counting the length of each first type of character; determining a second type of character that appears alone in the data to be encoded; and encoding the first type of character, the length, and the second type of character based on a preset encoding table to obtain initial encoded data.
[0095] This application provides a data encoding device, including a memory 201 and a processor 202. The memory 201 stores a computer program. When the processor 202 executes the computer program, it performs the following steps: encoding a first type of character and a second type of character based on the ASCII code table to obtain a first encoding result; encoding a length based on the Huffman length encoding table to obtain a second encoding result; and encoding the first encoding result and the second encoding result based on a preset encoding table to obtain an initial encoding result.
[0096] This application provides a data encoding device, including a memory 201 and a processor 202. The memory 201 stores a computer program. When the processor 202 executes the computer program, it performs the following steps: the encoding result of the ASCII code table is an integer between 0 and 255; the encoding result of the Huffman length encoding table is an integer between 257 and 285.
[0097] This application provides a data encoding device, including a memory 201 and a processor 202. The memory 201 stores a computer program. When the processor 202 executes the computer program, it performs the following steps: the preset encoding table encodes integers between 0 and 143 and integers between 280 and 285 as 8-bit data; the encoding result for integers between 144 and 255 is 9-bit data; and the encoding result for integers between 256 and 279 is 7-bit data.
[0098] This application provides a data encoding device, including a memory 201 and a processor 202. The memory 201 stores a computer program. When the processor 202 executes the computer program, it performs the following steps: encapsulates the initial encoded data according to the encoding format of dynamic Huffman coding, obtains the target encoded data, and then stores the preset encoding table according to the Huffman tree storage method.
[0099] This application provides a data encoding device, including a memory 201 and a processor 202. The memory 201 stores a computer program, and when the processor 202 executes the computer program, it performs the following steps: the preset depth value includes 15.
[0100] Please see Figure 4 Another data encoding device provided in this application embodiment may further include: an input port 203 connected to the processor 202 for transmitting commands input from the outside to the processor 202; a display unit 204 connected to the processor 202 for displaying the processing results of the processor 202 to the outside; and a communication module 205 connected to the processor 202 for enabling communication between the data encoding device and the outside. The display unit 204 may be a display panel, a laser scanner, or the like; the communication method used by the communication module 205 includes, but is not limited to, Mobile High Definition Link (HML), Universal Serial Bus (USB), High Definition Multimedia Interface (HDMI), wireless connection: Wireless Fidelity (WiFi), Bluetooth communication technology, Bluetooth Low Energy communication technology, and IEEE 802.11s-based communication technology.
[0101] This application provides a computer-readable storage medium storing a computer program, which, when executed by a processor, performs the following steps:
[0102] Obtain the data to be encoded;
[0103] Statistically analyze the characters to be encoded in the data to be encoded and the frequency of each character.
[0104] Generate an initial Huffman tree based on the characters to be encoded and their frequency of occurrence;
[0105] Determine if the depth of the initial Huffman tree is greater than the preset depth; if the depth of the initial Huffman tree is greater than the preset depth, then encode the data to be encoded based on the preset encoding table to obtain the initial encoded data, and encapsulate the initial encoded data according to the encoding format of dynamic Huffman coding to obtain the target encoded data.
[0106] This application provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it performs the following steps: determining a first type of character that appears repeatedly in the data to be encoded and has a length greater than or equal to 3; counting the length of each first type of character; determining a second type of character that appears alone in the data to be encoded; and encoding the first type of character, the length, and the second type of character based on a preset encoding table to obtain initial encoded data.
[0107] This application provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it performs the following steps: encoding a first type of character and a second type of character based on the ASCII code table to obtain a first encoding result; encoding the length based on the Huffman length encoding table to obtain a second encoding result; and encoding the first encoding result and the second encoding result based on a preset encoding table to obtain an initial encoding result.
[0108] This application provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it performs the following steps: the encoding result of the ASCII code table is an integer between 0 and 255; the encoding result of the Huffman length encoding table is an integer between 257 and 285.
[0109] This application provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it performs the following steps: the preset encoding table encodes integers between 0 and 143 and integers between 280 and 285 as 8-bit data; the encoding result for integers between 144 and 255 is 9-bit data; and the encoding result for integers between 256 and 279 is 7-bit data.
[0110] This application provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it performs the following steps: encapsulating initial encoded data according to the encoding format of dynamic Huffman coding to obtain target encoded data, and then storing a preset encoding table according to the Huffman tree storage method.
[0111] This application provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it performs the following steps: the preset depth value includes 15.
[0112] The computer-readable storage media involved in this application include random access memory (RAM), memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disks, removable disks, CD-ROMs, or any other form of storage media known in the art.
[0113] For descriptions of relevant parts in the data encoding system, device, and computer-readable storage medium provided in this application's embodiments, please refer to the detailed description of the corresponding parts in the data encoding method provided in this application's embodiments; they will not be repeated here. Furthermore, parts of the technical solutions provided in this application that are consistent with the implementation principles of corresponding technical solutions in the prior art have not been described in detail to avoid excessive elaboration.
[0114] It should also be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0115] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not 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
1. A method for massive data transmission based on data encoding, characterized in that, include: Obtain the data to be encoded; The data to be encoded is obtained after determining the type, content, and size of the data based on the actual needs of the target application scenario. The data to be encoded is statistically analyzed, including the characters to be encoded and the frequency of each character. The characters to be encoded are those corresponding to the target application scenario, and the content types of the characters to be encoded include numeric, symbol, and alphabetic types. An initial Huffman tree is generated based on the character to be encoded and its frequency of occurrence. Determine whether the depth of the initial Huffman tree is greater than a preset depth; If the depth of the initial Huffman tree is greater than the preset depth, the data to be encoded is encoded based on the preset encoding table to obtain initial encoded data. The initial encoded data is then encapsulated according to the encoding format of dynamic Huffman coding to obtain target encoded data. The target encoded data is transmitted. The step of encoding the data to be encoded based on a preset encoding table to obtain initial encoded data includes: Identify the first type of characters that appear repeatedly in the data to be encoded and have a length greater than or equal to 3; Calculate the length of each character of the first type; Identify the second type of character that appears alone in the data to be encoded; The first type of characters, the length, and the second type of characters are encoded based on the preset encoding table to obtain the initial encoded data; The initial encoded data is obtained by encoding the first type of characters, the length, and the second type of characters based on the preset encoding table, including: The first type of characters and the second type of characters are encoded based on the ASCII code table to obtain the first encoding result; The length is encoded based on the Huffman length encoding table to obtain a second encoding result; The first encoding result and the second encoding result are encoded based on the preset encoding table to obtain the initial encoded data; The preset encoding table encodes integers between 0 and 143 and integers between 280 and 285 as 8-bit data; integers between 144 and 255 as 9-bit data; and integers between 256 and 279 as 7-bit data.
2. The method according to claim 1, characterized in that, The encoding result of the ASCII code table is an integer between 0 and 255; the encoding result of the Huffman length encoding table is an integer between 257 and 285.
3. The method according to claim 1 or 2, characterized in that, After encapsulating the initial encoded data according to the encoding format of dynamic Huffman coding to obtain the target encoded data, the process further includes: The preset encoding table is stored using a Huffman tree storage method.
4. The method according to claim 3, characterized in that, The preset depth value includes 15.
5. A massive data transmission system based on data encoding, characterized in that, include: The first acquisition module is used to acquire the data to be encoded. The data to be encoded is obtained after determining the type, content, and size of the data based on the actual needs of the target application scenario. The first statistics module is used to count the characters to be encoded in the data to be encoded and the frequency of occurrence of each character to be encoded; the characters to be encoded are characters corresponding to the target application scenario, and the content types of the characters to be encoded include numeric, symbol, and alphabetic types; The first generation module is used to generate an initial Huffman tree based on the character to be encoded and its frequency of occurrence. The first judgment module is used to determine whether the depth of the initial Huffman tree is greater than a preset depth; If the depth of the initial Huffman tree is greater than the preset depth, the data to be encoded is encoded based on the preset encoding table to obtain initial encoded data. The initial encoded data is then encapsulated according to the encoding format of dynamic Huffman coding to obtain target encoded data. The target encoded data is transmitted. The step of encoding the data to be encoded based on a preset encoding table to obtain initial encoded data includes: Identify the first type of characters that appear repeatedly in the data to be encoded and have a length greater than or equal to 3; Calculate the length of each character of the first type; Identify the second type of character that appears alone in the data to be encoded; The first type of characters, the length, and the second type of characters are encoded based on the preset encoding table to obtain the initial encoded data; The initial encoded data is obtained by encoding the first type of characters, the length, and the second type of characters based on the preset encoding table, including: The first type of characters and the second type of characters are encoded based on the ASCII code table to obtain the first encoding result; The length is encoded based on the Huffman length encoding table to obtain a second encoding result; The first encoding result and the second encoding result are encoded based on the preset encoding table to obtain the initial encoded data; The preset encoding table encodes integers between 0 and 143 and integers between 280 and 285 as 8-bit data; integers between 144 and 255 as 9-bit data; and integers between 256 and 279 as 7-bit data.
6. A data encoding device, characterized in that, include: Memory, used to store computer programs; A processor for executing the computer program to implement the data encoding process steps in the method as described in any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that is executed by a processor to implement the steps of the data encoding process in the method as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Quasi dynamic Huffman hardware encoder and encoding method
CN107294539A
Huffman coding method, system and equipment
CN112003625A