Coding method and device, decoding method and device, equipment and storage medium
By introducing a reference threshold into the data set, the first data suitable for RLE is determined, and the problems of low RLE encoding efficiency and data degradation in the prior art are solved, and an efficient and low overhead encoding method is realized.
Patent Information
- Application Number
- CN202311421118.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-27
- Publication Date
- 2025-04-29
- Estimated Expiration
- 2043-10-27
AI Technical Summary
When performing RLE on data, it is difficult to effectively determine which data is suitable for RLE, resulting in excessive encoding overhead or data degradation.
By introducing a reference threshold, the first data suitable for RLE is determined based on the N data in the data set, the number of bits of the first element and the number of bits of the second element. The specific method includes calculating a reference threshold, and performing RLE if the frequency of the first data reaches or exceeds the threshold.
Reasonable RLE is realized, unnecessary coding overhead is avoided, computational complexity is reduced, encoding efficiency is improved, and data degradation after RLE is avoided.
Smart Images

Figure CN119906835A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of coding and decoding technology, and in particular to a coding method, a decoding method, a device, a equipment and a storage medium. Background Art
[0002] With the continuous development of coding and decoding technology, there are more and more ways to encode and decode data, and run-length encoding (RLE) and the corresponding decoding method are one of them. How to perform reasonable RLE and corresponding decoding on data has become an urgent problem to be solved. Summary of the invention
[0003] The present application provides an encoding method, a decoding method, an apparatus, a device and a storage medium to perform reasonable RLE and corresponding decoding on data. The technical solution provided by the present application includes the following aspects.
[0004] In a first aspect, a coding method is provided, in which a data set is obtained, the data set including N data, where N is greater than or equal to 2. If the frequency of occurrence of first data in the N data is greater than or equal to a reference threshold, RLE is performed on the first data. The reference threshold is determined based on N, the bits occupied by the first element, and the bits occupied by the second element, the first element is determined based on the first data, and the second element is the number of consecutive occurrences of the first data.
[0005] The method determines the first data suitable for RLE from N data based on the reference threshold. Therefore, RLE can be performed on the first data suitable for RLE, thereby achieving reasonable RLE and avoiding unnecessary coding overhead. In addition, since the reference threshold is determined based on N, the bits occupied by the first element and the bits occupied by the second element, and N, the bits occupied by the first element and the bits occupied by the second element are all constants that are easy to determine, the calculation complexity of determining the reference threshold is low, and the first data suitable for RLE can be quickly and accurately determined based on the reference threshold. Therefore, not only is degradation after RLE avoided, but also the calculation overhead is reduced and the coding efficiency is improved.
[0006] In a possible implementation, the reference threshold is determined based on a ratio of a first value to a second value, where the first value is the product of bits occupied by the second element and N, and the second value is the sum of bits occupied by the first element and bits occupied by the second element.
[0007] In this implementation, the reference threshold is determined by determining a ratio, a product, and a sum. This determination method is simple and easy, has low computational overhead, and is highly practical.
[0008] In a possible implementation, the method further includes: encoding the second data except the first data in the N data to obtain an encoding result. The encoding result includes a first element, a second element, a third element, and a fourth element, the third element is determined based on the second data, the arrangement of the third element and the first element in the encoding result is the same as the arrangement of the second data and the first data in the N data, and the fourth element is determined based on the first data.
[0009] Among them, the second data is data that is not suitable for RLE. If there is a second data in addition to the first data in the N data, it is necessary to encode the second data in a non-RLE manner to obtain the encoding result. Since the first element is determined based on the first data and the third element is determined based on the second data, the arrangement of the third element and the first element in the encoding result can naturally reflect the arrangement of the second data and the first data in the N data, which is convenient for subsequent decoding of the encoding result. However, it is precisely because the third element and the first element are arranged together in a certain arrangement, so it is difficult to distinguish the third element and the first element from the third element and the first element arranged together during decoding. Therefore, it is also necessary to determine the fourth element based on the first data to facilitate the distinction between the third element and the first element. When decoding, for any one of the third element and the first element arranged together, if the element also belongs to the fourth element, it means that the element is the first element determined based on the first data, and if the element does not belong to the fourth element, it means that the element is the third element determined based on the second data.
[0010] In a possible implementation, the method further includes: encoding the second data other than the first data in the N data to obtain an encoding result, wherein the encoding result includes a first element, a second element, a fifth element, and a sixth element, the fifth element is determined based on the second data, and the sixth element is used to indicate the arrangement of the second data and the first data in the N data.
[0011] As mentioned above, the second data is data that is not suitable for RLE. When there is the second data in addition to the first data in the N data, it is necessary to encode the second data in a non-RLE manner to obtain the encoding result. Among them, the first element determined based on the first data and the fifth element determined based on the second data are independent of each other, so there is no need to distinguish between the first element and the fifth element. However, it is precisely because the first element and the fifth element are independent of each other that it is difficult to determine the arrangement order of the first element and the fifth element during subsequent decoding. Although the first data and the second data can be decoded, it is difficult to arrange the decoded first data and the second data according to the arrangement of the first data and the second data in the N data, so it is difficult to restore the N data. Therefore, it is also necessary to indicate the arrangement of the second data and the first data in the N data through the sixth element to facilitate subsequent decoding.
[0012] In one possible implementation, the second element occupies 2 bits. M bits, M is greater than or equal to 1.
[0013] For example, the bits occupied by the second element may be 4 bits, 8 bits, etc. In the present application, it is preferred to make M have a smaller value so as to save more space after performing RLE on the first data.
[0014] In a second aspect, a decoding method is provided, in which after obtaining the encoding result, the encoding result is decoded. The encoding result is obtained by performing RLE on the first data of N data included in the data set, N is greater than or equal to 2, the frequency of occurrence of the first data in the N data is greater than or equal to a reference threshold, the reference threshold is determined based on N, the bits occupied by the first element, and the bits occupied by the second element, the first element is determined based on the first data, and the second element is the number of consecutive occurrences of the first data.
[0015] In a possible implementation, the reference threshold is determined based on a ratio of a first value to a second value, where the first value is the product of bits occupied by the second element and N, and the second value is the sum of bits occupied by the first element and bits occupied by the second element.
[0016] In a possible implementation, the encoding result is also obtained by encoding the second data other than the first data in the N first data, the encoding result includes a first element, a second element, a third element and a fourth element, the third element is determined based on the second data, the arrangement of the third element and the first element in the encoding result is the same as the arrangement of the second data and the first data in the N data, and the fourth element is determined based on the first data. Decoding the encoding result includes: decoding the first element and the third element according to the second element and the fourth element.
[0017] In a possible implementation, the encoding result is obtained by encoding the second data other than the first data in the N first data, and the encoding result includes a first element, a second element, a fifth element, and a sixth element, the fifth element is determined based on the second data, and the sixth element is used to indicate the arrangement of the second data and the first data in the N data. Decoding the encoding result includes: decoding the first element and the fifth element according to the second element and the sixth element.
[0018] In one possible implementation, the second element occupies 2 bits. M bits, M is greater than or equal to 1.
[0019] In a third aspect, a coding device is provided, the device comprising:
[0020] An acquisition module is used to acquire a data set, where the data set includes N data, where N is greater than or equal to 2;
[0021] an encoding module, configured to perform RLE on the first data among the N data if the frequency of occurrence of the first data among the N data is greater than or equal to a reference threshold;
[0022] The reference threshold is determined based on N, the bits occupied by the first element and the bits occupied by the second element, the first element is determined based on the first data, and the second element is the number of consecutive occurrences of the first data.
[0023] In a possible implementation, the reference threshold is determined based on a ratio of a first value to a second value, where the first value is the product of bits occupied by the second element and N, and the second value is the sum of bits occupied by the first element and bits occupied by the second element.
[0024] In a possible implementation, the encoding module is also used to encode the second data other than the first data in the N data to obtain an encoding result; wherein the encoding result includes a first element, a second element, a third element and a fourth element, the third element is determined based on the second data, the arrangement of the third element and the first element in the encoding result is the same as the arrangement of the second data and the first data in the N data, and the fourth element is determined based on the first data.
[0025] In one possible implementation, the encoding module is also used to encode the second data other than the first data in the N data to obtain an encoding result; wherein the encoding result includes a first element, a second element, a fifth element and a sixth element, the fifth element is determined based on the second data, and the sixth element is used to indicate the arrangement of the second data and the first data in the N data.
[0026] In one possible implementation, the second element occupies 2 bits. Mbits, M is greater than or equal to 1.
[0027] In a fourth aspect, a decoding device is provided, the device comprising:
[0028] an acquisition module, used to acquire an encoding result, where the encoding result is obtained by performing RLE on the first data among N data included in the data set, where N is greater than or equal to 2, and the frequency of occurrence of the first data in the N data is greater than or equal to a reference threshold, where the reference threshold is determined based on N, bits occupied by the first element, and bits occupied by the second element, where the first element is determined based on the first data, and the second element is the number of consecutive occurrences of the first data;
[0029] The decoding module is used to decode the encoding result.
[0030] In a possible implementation, the reference threshold is determined based on a ratio of a first value to a second value, where the first value is the product of bits occupied by the second element and N, and the second value is the sum of bits occupied by the first element and bits occupied by the second element.
[0031] In a possible implementation, the encoding result is also obtained by encoding the second data other than the first data in N first data, and the encoding result includes a first element, a second element, a third element and a fourth element, the third element is determined based on the second data, and the arrangement of the third element and the first element in the encoding result is the same as the arrangement of the second data and the first data in the N data, and the fourth element is determined based on the first data; a decoding module is used to decode the first element and the third element according to the second element and the fourth element.
[0032] In a possible implementation, the encoding result is also obtained by encoding the second data other than the first data in N first data, and the encoding result includes a first element, a second element, a fifth element and a sixth element, the fifth element is determined based on the second data, and the sixth element is used to indicate the arrangement of the second data and the first data in the N data; a decoding module is used to decode the first element and the fifth element according to the second element and the sixth element.
[0033] In one possible implementation, the second element occupies 2 bits. M bits, M is greater than or equal to 1.
[0034] In a fifth aspect, a computer device is provided, which includes a memory and a processor; at least one computer instruction is stored in the memory, and the at least one computer instruction is loaded and executed by the processor, so that the computer device implements the encoding method provided by the above-mentioned first aspect or any possible implementation of the first aspect, or implements the decoding method provided by the second aspect or any possible implementation of the second aspect.
[0035] Optionally, there are one or more processors and one or more memories.
[0036] Optionally, the memory may be integrated with the processor, or the memory may be provided separately from the processor.
[0037] In the sixth aspect, a coding and decoding system is provided, which includes an encoder and a decoder, the encoder is used to execute the encoding method provided by the above-mentioned first aspect or any possible implementation of the first aspect, and the decoder is used to execute the decoding method provided by the above-mentioned second aspect or any possible implementation of the second aspect.
[0038] In the seventh aspect, a computer program or a computer program product is provided, and the computer program or the computer program product includes: computer instructions, when the computer instructions are executed by a computer, the computer implements the encoding method provided by the above-mentioned first aspect or any possible implementation of the first aspect, or implements the decoding method provided by the second aspect or any possible implementation of the second aspect.
[0039] In an eighth aspect, a computer-readable storage medium is provided, which stores computer instructions. When the computer instructions are executed on a computer, the computer executes the encoding method provided by the first aspect or any possible implementation of the first aspect, or implements the decoding method provided by the second aspect or any possible implementation of the second aspect.
[0040] In the ninth aspect, a chip is provided, comprising a processor for calling and executing instructions stored in a memory from the memory, so that a computer equipped with the chip executes the encoding method provided by the first aspect or any possible implementation of the first aspect, or implements the decoding method provided by the second aspect or any possible implementation of the second aspect.
[0041] In the tenth aspect, another chip is provided, comprising: an input interface, an output interface, a processor and a memory, wherein the input interface, the output interface, the processor and the memory are connected via an internal connection path, and the processor is used to execute the code in the memory. When the code is executed, a computer equipped with the chip executes the encoding method provided by the first aspect or any possible implementation of the first aspect, or implements the decoding method provided by the second aspect or any possible implementation of the second aspect.
[0042] It should be understood that the technical effects achieved by the technical solutions provided by the second to tenth aspects of the present application and the corresponding possible implementation methods can be referred to the above description of the technical effects achieved by the technical solutions provided by the first aspect and the corresponding possible implementation methods, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] Figure 1 A schematic diagram of an implementation environment provided for an embodiment of the present application;
[0044] Figure 2 A flowchart of an encoding method provided in an embodiment of the present application;
[0045] Figure 3 A schematic diagram of a flow chart of an encoding method provided in an embodiment of the present application;
[0046] Figure 4 A flowchart of another encoding method provided in an embodiment of the present application;
[0047] Figure 5 A schematic diagram of a business scenario of image compression provided by an embodiment of the present application;
[0048] Figure 6 A schematic diagram of a business scenario of a database provided in an embodiment of the present application;
[0049] Figure 7 A schematic diagram of a communication service scenario provided in an embodiment of the present application;
[0050] Figure 8 A flowchart of a decoding method provided in an embodiment of the present application;
[0051] Fig. 9 A flowchart of a decoding method provided in an embodiment of the present application;
[0052] Fig.10 A schematic diagram of a reference sequence provided in an embodiment of the present application;
[0053] Fig.11 A schematic diagram of a convergence trend provided in an embodiment of the present application;
[0054] Fig.12 A schematic diagram of the influence caused by an error value provided in an embodiment of the present application;
[0055] Fig.13 A schematic diagram for comparing a measured result and a calculated result provided in an embodiment of the present application;
[0056] Fig.14 A schematic diagram of the structure of an encoding device provided in an embodiment of the present application;
[0057] Fig.15 A schematic diagram of the structure of a decoding device provided in an embodiment of the present application;
[0058] Fig.16 A schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0059] The terms used in the implementation section of this application are only used to explain the specific embodiments of this application and are not intended to limit this application.
[0060] Run-length encoding (RLE) is a coding method that can perform lossless compression on data. It is also called variable length coding. Its core idea is to use variable length codes to replace the data that appears continuously (or repeatedly) in the data sequence to be encoded. For example, if the data sequence to be encoded is [A, A, A, A, B, B, B, C, C, D, E, E, E, E, A, A], then the data sequence can be encoded as [A, B, C, D, E, A] and [4, 3, 2, 1, 4, 2], or as [A, 4, B, 3, C, 2, D, 1, E, 4, A, 2], which means: data A appears 4 times in a row, data B appears 3 times in a row, data C appears 2 times in a row, data D appears 1 time in a row, data E appears 4 times in a row, and data A appears 2 times in a row.
[0061] There are a variety of related technologies for the above-mentioned RLE, including but not limited to the following related technologies 1 to 3.
[0062] Related technology 1: Simple RLE solution.
[0063] Among them, the naive RLE scheme does not analyze the data sequence to be encoded, but performs RLE indiscriminately on all the data in the data sequence. However, when the number of consecutive occurrences of data in the data sequence is small, the naive RLE scheme will not only bring additional coding overhead, but may also cause the size of the data sequence to expand (i.e., degrade), that is, it may cause the amount of data of the variable-length code (used to replace the data sequence) to be greater than the amount of data in the data sequence itself. For example, when the data sequence to be encoded is [A, B, C, D, E], the data sequence will be encoded as [A, B, C, D, E] and [1, 1, 1, 1, 1], which adds [1, 1, 1, 1, 1] compared to the data sequence, and thus degrades.
[0064] Related technology 2: static series solution and static parallel solution.
[0065] In the static concatenation scheme, RLE is used as one of the links in the encoding process based on experience, that is, RLE is used as the upstream or downstream of other encoding methods. Other encoding methods include but are not limited to: Lempel ziv1977 (LZ77), simple 8byte (Simple8b) and GNU compression (GNU zip, GZIP), etc. GNU is a free operating system.
[0066] In the static parallel scheme, RLE is bound to a specific data part (which can be regarded as a data sequence to be encoded) based on experience, that is, RLE is performed only on the bound data part, and not on other unbound data parts. For example, a database (DB) stores data in a table, one column of which is the modification date of the file and the other column is the name of the file. RLE is bound to the modification date of the file, but not to the name of the file.
[0067] However, both the static series scheme and the static parallel scheme are based on experience. If the actual data sequence does not match the experience, it will not only bring additional coding overhead, but also may still cause degradation even if RLE is only performed locally on the bound data.
[0068] Related technology three, adaptive selection scheme.
[0069] In the adaptive selection scheme, a heuristic algorithm is designed based on experience and observation. The heuristic algorithm is used to determine which data in the data sequence to be encoded is suitable for RLE. RLE is performed only on the data that is suitable for RLE, and RLE is not performed on the data that is not suitable for RLE.
[0070] However, because the heuristic algorithm is designed based only on experience and observation and lacks theoretical support, the accuracy of judgment by the heuristic algorithm is low, and data that is actually not suitable for RLE may be judged as suitable for RLE, that is, there is misjudged data, which leads to degradation after RLE of the misjudged data, and poor stability. In addition, the computational complexity of the heuristic algorithm is high, which brings additional computational overhead on the basis of the coding overhead, affecting the coding efficiency.
[0071] In this regard, the embodiment of the present application proposes a coding method, which is used to improve or solve the problems existing in the above-mentioned related technologies. For example, Figure 1As shown, the encoding method is applied to software 101, and the software 101 to which the encoding method is applied is deployed in product 102. The functions of the product include but are not limited to encoding functions, or data compression functions. The product 102 for deploying software 101 can be in the form of software or hardware, which is not limited here. Figure 2 , the encoding method includes the following steps 201 and 202.
[0072] Step 201: Acquire a data set, where the data set includes N data, where N is greater than or equal to 2.
[0073] The N data included in the data set are data to be encoded, and different data in the N data may have the same value or different values. In the embodiment of the present application, data with the same value are regarded as the same type of data, and the N data may include at least one type of data.
[0074] In some embodiments, N data are all data to be encoded, and the embodiment of the present application can obtain N data by receiving, or by generating, which is not limited here. Or, in other embodiments, N data are part of all data to be encoded, then obtaining N data includes: obtaining multiple data, sampling from multiple data to obtain N data. The sampling process can reduce the amount of data, that is, the amount of data of N data is less than the amount of data of multiple data, then the subsequent calculation overhead required for calculation based on N data is small. Therefore, the embodiment of the present application can obtain N data by sampling when the computing power is relatively limited. For example, the quantity threshold is determined according to the computing power, so that the number of N data obtained by sampling is less than or equal to the quantity threshold. Accordingly, the embodiment of the present application can use all the data to be encoded as N data when the computing power is sufficient.
[0075] Exemplarily, the multiple data may be all the data to be encoded, and the multiple data may be obtained by receiving or generating. Alternatively, the multiple data may also be part of the data to be encoded. For example, all the data to be encoded obtained by receiving or generating is divided into at least two groups, and the multiple data is one group of the at least two groups of data.
[0076] In different business scenarios, the way to divide all the data to be encoded into at least two groups is also different, see the following three examples for details. In the business scenario of image compression, the image includes multiple pixels, each pixel corresponds to multiple color channels, and each pixel has a value on each color channel. Then, all the data to be encoded include the value of each pixel on each color channel. All the data to be encoded are divided according to the color channel to obtain multiple groups of data corresponding to multiple color channels one by one. Each group of data is the value of each pixel in the image on a color channel corresponding to the group of data, and the multiple data is a group of data in the multiple groups of data. Alternatively, in the business scenario of a database, the database stores data in the form of a table, and the table includes multiple rows and multiple columns. Then, all the data to be encoded include all the data stored in the table. All the data to be encoded are divided according to the column (or row), and multiple groups of data corresponding to each column (or each row) are obtained. Each group of data is the data stored in a column (or row) included in the table, and the multiple data is a group of data in the multiple groups of data. Alternatively, in a communication business scenario, a binary signal needs to be transmitted, and the binary signal includes multiple bits, and the value of each bit is 0 or 1, then all the data to be encoded is multiple bits, and all the data to be encoded is divided to obtain multiple groups of data, each group of data includes a certain number of bits, and the multiple data is a group of data in the multiple groups of data. Of course, the business scenarios applicable to the encoding method provided in the embodiment of the present application are not limited to the business scenarios exemplified above, but can also include other business scenarios that need to be encoded, which will not be repeated one by one here.
[0077] Regardless of the manner in which the multiple data are obtained, the embodiments of the present application can sample the multiple data after obtaining the multiple data, thereby obtaining N data. For example, the multiple data can be randomly sampled. For another example, one data can be collected every certain number of data in the multiple data. The embodiments of the present application do not limit the sampling method, and other sampling methods can also be applied to the embodiments of the present application according to actual needs. For example, other sampling methods can be flexibly adopted so that each type of data in the multiple data is sampled into N data.
[0078] Exemplarily, the embodiment of the present application can perform step 201 and step 202 when all the data to be encoded satisfy independent and identical distribution and the number of all the data to be encoded is sufficient. For example, when the number of all the data to be encoded is greater than 1000, it is considered that the number of all the data to be encoded is sufficient. In addition, for the case where all the data to be encoded satisfy other types of data distribution or have other quantities, it can also be applied to the encoding method provided in the embodiment of the present application, which is not limited here.
[0079] Step 202: If the frequency of occurrence of the first data among the N data is greater than or equal to the reference threshold, perform RLE on the first data.
[0080] According to the description in step 201 above, the data with the same value in the N data are the same type of data, and the reference threshold is a threshold used to determine whether the various data in the N data are suitable for RLE. For each type of data in the N data, if the frequency of occurrence of the data in the N data is greater than or equal to the reference threshold corresponding to the data, the data is the first data suitable for RLE, and if the frequency of occurrence of the data in the N data is less than the reference threshold corresponding to the data, the data is considered to be unsuitable for RLE. Since the first data is suitable for RLE, RLE can be performed on the first data. Among them, performing RLE on the first data can obtain an encoding result, and the first data is suitable for RLE can be quantitatively expressed as: the data amount of the encoding result is less than or equal to the data amount of the first data itself, thereby ensuring that no degradation occurs after performing RLE on the first data.
[0081] When N data are all the data to be encoded, performing RLE on the first data includes: performing RLE on the first data among the N data. Alternatively, when N data are part of the data to be encoded, that is, when N data are sampled from multiple data, performing RLE on the first data includes: performing RLE on the first data among the multiple data. The reason is that the multiple data also include other data in addition to the N data, and the other data may also include the first data suitable for RLE. Therefore, RLE is performed on the first data among the multiple data instead of only the first data among the N data, so as to avoid incomplete encoding of the first data and loss of the first data.
[0082] In some embodiments, each of the N data is first data suitable for RLE, and the encoding result may only include the corresponding first element and second element. The first element is determined based on the first data, and the second element is the number of consecutive occurrences of the first data.
[0083] Among them, each type of first data corresponds to at least one first element, and the first element can be determined in a variety of ways based on the first data. For example, when the bits occupied by data with different values in N data are the same (i.e., variable bit width storage), a separator is required between adjacent data, then a first element may include only one first data, or may include one first data and a separator. For another example, when the bits occupied by data with different values in N data are different (i.e., fixed bit width storage, if the data itself occupies fewer bits, the bits occupied by the data can be increased by padding with zeros), there may be no separator between adjacent data, then a first element may include one first data. For another example, a first element may include a first data and index information of the first data, and the index information is used to indicate the position of the first data in the N data. It can be seen that the first element determined based on the first data includes at least the first data.
[0084] In addition, each first element corresponds to a second element. The first element is determined based on which first data, and the second element corresponding to the first element is the number of consecutive occurrences of which first data. In other words, the second element is the number of consecutive occurrences of the first data, and the first element determined based on the first data corresponds to the second element. In an exemplary embodiment, the bits occupied by the second element are 2 M bits, M is greater than or equal to 1. For example, the bits occupied by the second element may be an integer multiple of 4 bits, including but not limited to 4 bits, 8 bits, 12 bits, etc., which are not limited here. Exemplarily, in the embodiment of the present application, when all the data to be encoded satisfy independent and identical distribution, the second element occupies 4 bits.
[0085] In the embodiment of the present application, all first elements may form a unique value (single_values) sequence, all second elements may form a repeated count (repeated_counts) sequence, and each second element in the repeated_counts sequence may occupy the same bit.
[0086] For example, if the N data are [AA, AA, AA, AA, B, B, B, AA, AA], and AA and B are both first data suitable for RLE, there may be but are not limited to the following situations.
[0087] In the case of variable bit width storage, AA and B occupy different bits, and the single_values sequence is [AA, B, AA]. The "," in the single_values sequence represents a separator, "AA" is the first element corresponding to the first data AA, and "B" is the first element corresponding to the first data B. Correspondingly, the repeated_counts sequence is
[432] , 4 is the second element corresponding to the first "AA" in the single_values sequence, 3 is the second element corresponding to "B" in the single_values sequence, and 2 is the second element corresponding to the second "AA" in the single_values sequence.
[0088] In the case of fixed bit width storage, AA and B occupy the same number of bits, and the single_values sequence is [AABAA], where "AA" is the first element corresponding to the first data AA, and "B" is the first element corresponding to the first data B. Accordingly, the repeated_counts sequence is
[432] , where 4 is the second element corresponding to the first "AA" in the single_values sequence, 3 is the second element corresponding to "B" in the single_values sequence, and 2 is the second element corresponding to the second "AA" in the single_values sequence.
[0089] In the case where a first element includes a first data and the index information of the first data, the single_values sequence is [AA:0:7, B], "," in the single_values sequence represents a separator, "AA:0:7" is the first element corresponding to the first data AA, ":0:7" is the index information of the first data AA, indicating that the offset of the first data AA relative to the first data in the N data when it first appears in the N data is 0, and the offset of the first data AA relative to the first data in the N data when it second appears in the N data is 7, and "B" is the first element corresponding to the first data B. Accordingly, the repeated_counts sequence is
[432] , 4 and 2 are the second elements corresponding to the first data AA, 4 represents the number of consecutive occurrences of the first data AA when it first appears in the N data, 2 represents the number of consecutive occurrences of the first data AA when it second appears in the N data, and 3 is the second element corresponding to the first data B, indicating the number of consecutive occurrences of the first data B when it appears in the N data.
[0090] In the above description, for ease of understanding, the second element is given in a decimal format, but the second element can be in a binary format when used. For example, when the second element occupies 4 bits, the value range of the second element is 0 to 15 (in binary form), and the number of consecutive occurrences that the second element can represent is 1 to 16.
[0091] In addition, because the second element occupies a certain number of bits, there is an upper limit to the value range of the second element. If the number of consecutive occurrences of a first data exceeds the upper limit, it is necessary to add a new first element to the single_values sequence and a new second element to the repeated_counts sequence. For example, the second element occupies 4 bits, the N data is [A...A (a total of 20 A) BBB], A and B are both first data suitable for RLE, then the single_values sequence is [AAB], "A" is the first element corresponding to the first data A, "B" is the first element corresponding to the first data B, and the repeated_counts sequence is
[1643] , 16 and 4 are the second elements corresponding to the first data A, representing that the consecutive occurrences of the first data A are 16 and 4, respectively, and 3 is the second element corresponding to the first data B, representing that the consecutive occurrences of the first data B are 3.
[0092] In other embodiments, the N data include at least one first data suitable for RLE and second data not suitable for RLE, and the second data is data other than the first data in the N data. In addition to performing RLE on the first data in the N data, the embodiment of the present application also needs to encode (non-RLE) the second data other than the first data in the N data to obtain an encoding result. Accordingly, the encoding result may include other elements in addition to the first element and the second element described above, as described below.
[0093] Exemplarily, the encoding result includes a third element and a fourth element on the basis of the first element and the second element, the third element is determined based on the second data, the arrangement of the third element and the first element in the encoding result is the same as the arrangement of the second data and the first data in N data, and the fourth element is determined based on the first data.
[0094] Among them, the method for determining the third element based on the second data can refer to the method for determining the first element based on the first data described above, and will not be repeated here. In an embodiment of the present application, the third element and the first element can be both located in the single_values sequence, and the arrangement of the third element and the first element is the same as the arrangement of the second data and the first data in N data. Thus, the arrangement of the second data and the first data in N data can be naturally reflected through the third element and the first element in single_values, without the need to additionally use other elements to indicate the arrangement of the second data and the first data in N data.
[0095] However, no matter how the third element and the first element are arranged in the encoding result, it is difficult to distinguish the third element from the first element in the single_values sequence, and it is also difficult to distinguish the second data that is not suitable for RLE from the first data that is suitable for RLE. Therefore, it is necessary to determine the fourth element based on the first data in order to distinguish the third element from the first element. The method of determining the fourth element based on the first data can refer to the method of determining the first element based on the first data described above, which will not be repeated here.
[0096] If the data included in an element in the single_values sequence is the same as the data included in the fourth element, then the element in the single_values sequence is the first element, and the data included in the element is the first data suitable for RLE. Of course, if the data included in an element in the single_values sequence is different from the data included in the fourth element, then the element in the single_values sequence is the third element, and the data indicated by the element is the second data not suitable for RLE.
[0097] In the embodiment of the present application, all fourth elements can constitute a target set (target_set). target_set is not limited to the case where the N data include both the first data and the second data. Even if each of the N data described above is the first data suitable for RLE, target_set can also exist. The reason is that the amount of data in target_set is small, generally much smaller than the amount of data in the single_values sequence and the amount of data in the repeated_counts sequence. Therefore, even if target_set is increased, it will not cause excessive and unacceptable impact on the total amount of data in the encoding result.
[0098] For example, the embodiment of the present application can make the third element in the single_values sequence correspond to the second data one by one, so that the third element can naturally reflect the number of consecutive occurrences of the second data, without adding other elements for representing the number of consecutive occurrences of the second data in the repeated_counts sequence. In other words, the repeated_counts sequence can only include the second element for representing the number of consecutive occurrences of the first data.
[0099] Next, combine Figure 3 and Figure 4 An example is given to illustrate the encoding process performed by the encoder.
[0100] like Figure 3As shown, after all the data to be encoded are input into the encoder, the encoder samples all the data to be encoded to obtain N data. Afterwards, each type of data in the N data is traversed, and the reference threshold corresponding to each data is used to determine whether the data is suitable for RLE. If the data is the first data suitable for RLE, the data is added to target_set to obtain the fourth element in target_set. If the data is the second data not suitable for RLE, the data is not added to target_set. Exemplarily, after the traversal is completed, the encoder can merge and deduplicate the fourth element in target_set to avoid redundant fourth elements in target_set.
[0101] Then, if Figure 4 As shown, the traversal is performed again starting from the first data of all the data to be encoded. For a data, if the data belongs to the target_set, or there is a fourth element determined based on the data in the target_set, RLE is performed on the data until other data with different values are traversed. In the process of performing RLE on the data, the single_values sequence and the repeated_counts sequence are updated according to the data to obtain the first element in the single_values sequence and the second element in the repeated_counts sequence. If the data does not belong to the target_set, or there is no fourth element determined based on the data in the target_set, the single_values sequence is updated only according to the data to obtain the third element in the single_values sequence, and the repeated_counts sequence is not updated according to the data. After the traversal is completed, the encoding result obtained by the encoder includes the target_set, the single_values sequence and the repeated_counts sequence.
[0102] For example, N data are [AAAABBBCCDEEEEAA], A and E are first data suitable for RLE, B, C, D and E are second data not suitable for RLE, then in the encoding result:
[0103] target_set includes {AE}, where “A” is the fourth element determined based on the first data A, and “E” is the fourth element determined based on the first data E;
[0104] The single_values sequence includes [ABBBCCDEA], where "A" is the first element determined based on the first data A, "B" is the third element determined based on the second data B, "C" is the third element determined based on the second data C, "D" is the third element determined based on the second data D, and "E" is the first element determined based on the first data E;
[0105] The repeated_counts sequence includes
[442] , the first 4 is the number of consecutive appearances of the first data A when it appears for the first time in N data, the second 4 is the number of consecutive appearances of the first data E when it appears in N data, and 2 is the number of consecutive appearances of the first data A when it appears for the second time in N data.
[0106] Alternatively, the encoding result may not include the third element and the fourth element mentioned above, but may also include the fifth element and the sixth element on the basis of including the first element and the second element, where the fifth element is determined based on the second data, and the sixth element is used to indicate the arrangement of the second data and the first data in the N data.
[0107] The method for determining the fifth element based on the second data can refer to the method for determining the third element based on the second data in the above description, which will not be repeated here. In addition, the fifth element and the first element can be independent of each other, and are not arranged according to the arrangement of the second data and the first data in the N data. Therefore, it is difficult for the fifth element and the first element to naturally reflect the arrangement of the second data and the first data in the N data, so it is necessary to additionally use the sixth element to indicate the arrangement of the second data and the first data in the N data.
[0108] This application does not limit the way in which the sixth element indicates the arrangement. For example, when the sixth element includes a first identifier, the second data included in the fifth element are all arranged after the first data included in the first element. For another example, when the sixth element includes a second identifier, the second data included in the fifth element are all arranged before the first data included in the first element. For another example, when the sixth element includes a third identifier, the arrangement of the second data included in the fifth element and the first data included in the first element is: interspersed with each other in a specified manner. The encoder can query the correspondence between the identifier and the arrangement according to the identifier included in the sixth element, thereby obtaining the arrangement of the second data and the first data corresponding to the identifier in N data.
[0109] In the encoding process performed by the encoder, after all the data to be encoded are input into the encoder, the encoder samples all the data to be encoded to obtain N data. After that, each of the N data is traversed to determine the first data suitable for RLE and the second data not suitable for RLE through the reference threshold corresponding to each data, and the sixth element is determined according to the arrangement of the second data and the first data in the N data. Then, the traversal is re-performed from the first data in the N data. For a data, if the data belongs to the first data suitable for RLE, the data is subjected to RLE until other data with different values are traversed. In the process of performing RLE on the data, the single_values sequence and the repeated_counts sequence are updated according to the data to obtain the first element in the single_values sequence and the second element in the repeated_counts sequence. If the data belongs to the third element not suitable for RLE, the data is not subjected to RLE, but the fifth element is obtained according to the data. After the traversal is completed, the encoder can obtain the encoding result, which includes the above-mentioned single_values sequence, the repeated_counts sequence, the sequence including all fifth elements, and the sixth element.
[0110] For example, N data is [AAAAAABBB], A is the first data suitable for RLE, and B is the second data not suitable for RLE. Then in the encoding result:
[0111] The single_values sequence includes [A], where “A” is a first element determined based on the first data A;
[0112] The repeated_counts sequence includes [6], where 6 is the number of consecutive occurrences of the first data A;
[0113] The sequence including all fifth elements is [BBB], where “B” is the fifth element determined based on the second data B;
[0114] The sixth element is a first identifier, indicating that the second data included in the fifth element are all arranged after the first data included in the first element.
[0115] The encoding process, the first element and the second element are described above. Next, the reference threshold used to determine whether the data is suitable for RLE is described. Among them, the reference threshold is determined based on N, the bits occupied by the first element and the bits occupied by the second element. The embodiment of the present application does not limit the method of determining the reference threshold based on N, the bits occupied by the first element and the bits occupied by the second element. Since N, the bits occupied by the first element and the bits occupied by the second element are all constants that can be directly determined, no matter how the reference threshold is determined based on these constants, the calculation complexity of the reference threshold can be low.
[0116] In some embodiments, the reference threshold is determined based on the ratio of the first value to the second value, the first value is the product of the bits occupied by the second element and N, and the second value is the sum of the bits occupied by the first element and the bits occupied by the second element. Wherein, the reference threshold is determined based on the ratio of the first value to the second value, which may refer to the ratio of the first value to the second value as the reference threshold, or may refer to the correction result obtained after the ratio of the first value to the second value is corrected as the reference threshold, and the correction is to improve the accuracy of the reference threshold. Exemplarily, when performing the correction, a correction coefficient may be obtained based on experience or other possible methods, and the ratio of the first value to the second value and the correction coefficient may be calculated to obtain the above correction result.
[0117] Taking the ratio of the first value to the second value as the reference threshold as an example, for each type of data in N data, if the frequency of occurrence of this type of data in the N data satisfies the following formula (1), then this type of data is considered to be the first data suitable for RLE; if the frequency of occurrence of this type of data in the N data does not satisfy the following formula (1), then this type of data is considered to be the second data not suitable for RLE:
[0118]
[0119] In formula (1), N i Represents a data V i The frequency of occurrence in N data, s i Indicates based on V i Determine the number of bits occupied by the first element, s r Indicates the bits occupied by the second element.
[0120] In other embodiments, the reference threshold is determined based on the ratio of the first value to the second value, and the determination method is described above and will not be repeated here. The first value is the product of the bits occupied by the second element and N, and the second value is the bits occupied by the first element. This method is applicable to the case where the bits occupied by the first element are much larger than the bits occupied by the second element, because in this case, the sum of the bits occupied by the first element and the bits occupied by the second element is approximately equal to the bits occupied by the first element, so the bits occupied by the second element can be directly ignored.
[0121] Taking the ratio of the first value to the second value as the reference threshold as an example, for each type of data in the N data, if the frequency of occurrence of the data in the N data satisfies the following formula (2), then the data is considered to be the first data suitable for RLE. If the frequency of occurrence of the data in the N data does not satisfy the following formula (2), then the data is considered to be the second data not suitable for RLE:
[0122]
[0123] It can be seen that formula (2) can be considered as a simplified form of formula (1). Simplification is conducive to reducing the computational complexity, thereby reducing the computational overhead in the encoding process and improving the encoding efficiency. Formula (1) is a formula with theoretical support and obtained through a rigorous derivation process. The derivation process is described in detail below and will not be repeated here.
[0124] According to formula (1), determine whether the data is suitable for RLE, s i =1 and s r = 4, the critical position of the data suitable for RLE is N i =0.8N. All the data to be encoded are regarded as sequences, and two sequences with a length of 10000 are defined, namely, sequence A and sequence B, where the value of N is 10000. The value of 8000 random positions in sequence A is 1, and the value of the remaining 2000 positions is 0. Then the data with a value of 1 in sequence A is just suitable for RLE, while the data with a value of 0 is not suitable for RLE. In addition, one or two data are randomly selected from the 8000 data with a value of 1 included in sequence A, and the values of the selected data are replaced from 1 to 0 to obtain sequence B. Then the data with a value of 1 in sequence B is just not suitable for RLE, and the data with a value of 0 is also not suitable for RLE. Therefore, if RLE is performed on the data suitable for RLE, the data amount of the encoding result corresponding to sequence A is smaller than the data amount of the encoding result corresponding to sequence B, and is also smaller than the data amount of sequence A itself.
[0125] As mentioned above, the data volume of target_set is much smaller than the data volume of single_values sequence and repeated_counts sequence, so the data volume of target_set is not considered when calculating the data volume of the encoding result in the following examples.
[0126] In Example 1, in the business scenario of image compression, RLE can be performed on images that comply with the standards of the International Telecommunication Union (ITU) or the International Organization for Standardization (ISO), thereby achieving image compression. The images that comply with the ITU or ISO standards include but are not limited to the following formats: Joint Photographic Experts Group (JPEG), Tag Image File Format (TIFF), Bitmap (BMP), and PC Paintbrush Exchange (PCX), where PC Paintbrush is a software.
[0127] like Figure 5 As shown, an image includes 10 pixels, each pixel corresponds to three color channels of red (red, R), green (green, G) and blue (blue, B), so decomposition can obtain a data sequence corresponding to R, a data sequence corresponding to G and a data sequence corresponding to B, each data sequence includes 10 data, and the encoding method provided in the embodiment of the present application is used to encode each data sequence separately. Among them, since the value of a pixel on a color channel is any value between 0 and 255, each data is stored with a fixed bit width, each data occupies 8 bits, and each data sequence occupies 80 bits, that is, s i =8, and set s r =8.
[0128] Each type of data in the data sequence corresponding to R is not suitable for RLE, so the target_set in the encoding result is an empty set {}, the single_values sequence is [25, 50, 75, 100, 125, 150, 175, 200, 225, 250], and the repeated_counts sequence is also empty []. Here, "," is added to the single_values sequence only to distinguish different data. Here, "," is not a separator that needs to occupy bits. Therefore, after compressing the data sequence corresponding to R, the encoding result occupies 80 bits, which is the same as the 80 bits occupied before compression, and there is no degradation.
[0129] In the data sequence corresponding to G, the data with a value of 255 is suitable for RLE, and the data with other values is not suitable for RLE. Therefore, in the encoding result, target_set is {255}, the single_values sequence is [0, 50, 255, 125, 150, 255], and the repeated_counts sequence is
[24] . The "," in the single_values sequence is not a separator that needs to occupy bits. Therefore, after compressing the data sequence corresponding to G, the encoding result occupies 64 (6*8+2*8) bits, which is less than the 80 bits occupied before compression.
[0130] Each value of the data sequence corresponding to B is suitable for RLE, so the target_set in the encoding result is {180, 60}, the single_values sequence is [180, 60], and the repeated_counts sequence is
[55] . The "," in the single_values sequence is not a separator that needs to occupy bits. Therefore, after compressing the data sequence corresponding to B, the encoding result occupies 32 (2*8+2*8) bits, which is less than the 80 bits occupied before compression.
[0131] It can be seen that in the fixed bit width storage s i =8 and s r =8, for the data sequence corresponding to each color channel, the bits occupied after compression do not exceed the bits occupied before compression.
[0132] In Example 2, in the database business scenario, RLE can be performed on the data stored in the database to achieve data compression. The databases include but are not limited to the following: MongoDB, InfluxDB, TimescaleDB (all are database names).
[0133] like Figure 6As shown, the database stores data in a tabular form and is divided by columns to obtain a data sequence corresponding to the source Internet Protocol (IP) address, a data sequence corresponding to the destination IP address, and a data sequence corresponding to the protocol type. The protocol types include the User Datagram Protocol (UDP) and the Transmission Control Protocol (TCP). Of course, the source IP address, the destination IP address, and the protocol type are only examples, and may also include data sequences corresponding to features such as port numbers and application types. Each data sequence includes 10 data, and each data is stored in a variable bit width. For example, in the data sequence corresponding to the source IP, the data "139.247.157.67" occupies 112 (14*8) bits, while "55.102.24.208" occupies 104 (13*8) bits, and there is a separator that occupies 8 bits between different data. In addition, set s r =4.
[0134] The data sequence corresponding to the source IP occupies 1152 (112*5+104*5+9*8) bits. Both "139.247.157.67" and "55.102.24.208" are suitable for RLE. The encoding result includes target_set {139.247.157.67, 55.102.24.208}, single_values sequence [139.247.157.67, 55.102.24.208], repeated_counts sequence
[55] . The "," in the single_values sequence is a separator that needs to occupy bits. Therefore, the encoding result after compression occupies 232 (112*1+104*1+1*8+2*4) bits, which is less than the 1152 bits occupied before compression.
[0135] The data sequence corresponding to the destination IP occupies 824 (9*8*8+11*8*2+9*8) bits. Both "10.0.5.22" and "10.255.8.13" are suitable for RLE. The encoding result includes target_set {10.0.5.22, 10.255.8.13}, single_values sequence [10.0.5.22, 10.255.8.13, 10.0.5.22], repeated_counts sequence
[352] , and "," in the single_values sequence is a separator that needs to occupy bits. Therefore, the encoding result after compression occupies 260 (9*8*1+11*8*1+9*8*1+2*8+3*4) bits, which is less than the 824 bits occupied before compression.
[0136] The data sequence corresponding to the protocol type occupies 312 (3*8*5+3*8*5+9*8) bits. Both "UDP" and "TCP" are suitable for RLE. The encoding result includes target_set {UDP, TCP}, single_values sequence [UDP, TCP], and repeated_counts sequence
[55] . The "," in the single_values sequence is a separator that needs to occupy bits. Therefore, the encoding result after compression occupies 64 (3*8*1+3*8*1+1*8+2*4) bits, which is less than the 312 bits before compression.
[0137] It can be seen that in s i Using variable bit width storage and s r =4, for the data sequence corresponding to each column, the bits occupied after compression are smaller than the bits occupied before compression.
[0138] In Example 3, in a communication business scenario, RLE can be performed on signals in various formats such as analog TV signals, fax signals, and digital signals to facilitate transmission during the communication process.
[0139] like Figure 7 As shown in the figure, the binary signal to be transmitted is: 00000000 00000000 00000000 0000010000000000 00000000 00000111 00000000 00010000 00000000 00000000, each data is stored with a fixed bit width, and each data occupies 1 bit, that is, s i =1, the binary signal is divided into three groups, each corresponding to a 32-bit data sequence. In addition, set s r = 8. In each corresponding data sequence, data 0 is suitable for RLE, and data 1 is not suitable for RLE.
[0140] In the data sequence corresponding to the first group, the encoding result includes target_set as {0}, single_values sequence as [0, 1, 0], and repeated_counts sequence as [29, 2]. The "," in the single_values sequence and repeated_counts sequence is not a separator that needs to occupy bits. Therefore, the encoding result obtained after compression occupies 19 (3*1+2*8) bits, which is less than the 32 bits occupied before compression.
[0141] In the data sequence corresponding to the second group, the encoding result includes target_set as {0}, single_values sequence as [0, 1, 1, 1], repeated_counts sequence as
[29] , and "," in the single_values sequence is not a separator that needs to occupy bits. Therefore, after compression, it occupies 12 (4*1+1*8) bits, which is less than the 32 bits occupied before compression.
[0142] In the data sequence corresponding to the third group, the encoding result includes target_set as {0}, single_values sequence as [0, 1, 0], and repeated_counts sequence as [11, 20]. The "," in the single_values sequence and repeated_counts sequence is not a separator that needs to occupy bits. Therefore, after compression, it occupies 19 (3*1+2*8) bits, which is less than the 32 bits occupied before compression.
[0143] It can be seen that in the fixed bit width storage s i =1 and s r =8, for the data sequences corresponding to each group, the bits occupied after compression are smaller than the bits occupied before compression.
[0144] In summary, the embodiment of the present application determines the first data suitable for RLE from N data based on the reference threshold. Therefore, RLE can be performed on the first data suitable for RLE, while RLE is not required for the data not suitable for RLE, thereby achieving reasonable and selective RLE and avoiding unnecessary coding overhead.
[0145] Furthermore, since the reference threshold is determined based on N, the bits occupied by the first element, and the bits occupied by the second element, the reference threshold has theoretical support and low computational complexity, and the first data suitable for performing RLE can be quickly and accurately determined based on the reference threshold. Thus, not only degradation after performing RLE is avoided, but also computational overhead is reduced and coding efficiency is improved.
[0146] In addition, through the above Figure 2 The encoding method shown in the figure is used to encode, and an encoding result can be obtained. In this regard, the embodiment of the present application also provides a Figure 8 The decoding method shown is used to decode the encoding result. The decoding method can be applied to Figure 1In the software 101 shown, the software 101 is deployed in the product 102. In the embodiment of the present application, the encoding method and the decoding method can be applied to the same software or to different software. In the case where the encoding method and the decoding method are applied to different software, the different software can be deployed in the same product or in different products. Figure 8 , the decoding method includes the following steps 801 and 802.
[0147] Step 801: Obtain a coding result, where the coding result is obtained by performing RLE on the first data among N data included in a data set, where N is greater than or equal to 2.
[0148] Among them, the frequency of occurrence of the first data in N data is greater than or equal to a reference threshold, the reference threshold is determined based on N, the bits occupied by the first element and the bits occupied by the second element, the first element is determined based on the first data, and the second element is the number of consecutive occurrences of the first data.
[0149] For example, the second element occupies 2 bits. M bits, M is greater than or equal to 1.
[0150] In an exemplary embodiment, the reference threshold is determined based on a ratio of a first value which is the product of bits occupied by the second element and N, and a second value which is the sum of bits occupied by the first element and bits occupied by the second element.
[0151] The contents involved in step 801 can be found in the descriptions of steps 201 and 202 above, and will not be repeated here.
[0152] Step 802: Decode the encoding result.
[0153] In some embodiments, each of the N data is first data suitable for RLE, and the encoding result includes only the corresponding first element and second element. Since the first element in the single_values sequence includes the first data, and the second element in the repeated_counts sequence is the number of consecutive occurrences of the first data, the single_values sequence can be traversed during the decoding process, and for the first data included in each first element, the first data is continuously output according to the number of consecutive occurrences represented by the second element corresponding to the first element in the repeated_counts sequence, for example, if the number of consecutive occurrences is 5, 5 first data are continuously output, thereby obtaining a decoding result.
[0154] In some other embodiments, the encoding result is also obtained by encoding the second data other than the first data in the N data, and the encoding result includes the first element, the second element, the third element and the fourth element, the third element is determined based on the second data, the arrangement of the third element and the first element in the encoding result is the same as the arrangement of the second data and the first data in the N data, and the fourth element is determined based on the first data. The third element and the first element are located in the single_values sequence, and the fourth element is located in the target_set. Accordingly, decoding the encoding result includes: decoding the first element and the third element according to the second element and the fourth element.
[0155] Next, combine Fig. 9 An example is given to illustrate the decoding process performed by the decoder.
[0156] like Fig. 9 As shown, after receiving the encoding result, the decoder scans the single_values sequence in the encoding result and traverses from the first element of the single_values sequence. If the data included in an element is the same as the data included in the fourth element in target_set, the element is confirmed to be the first element, and the data included in the first element is the first data suitable for RLE, so the first data is continuously output according to the number of consecutive occurrences represented by the first second element existing in the repeated_counts sequence, and then the first second element existing in the repeated_counts sequence is deleted. If the data included in an element is different from the data included in the fourth element in target_set, the element is confirmed to be the third element, and the data included in the third element is the second data not suitable for RLE, so the second data included in the third element is directly output. After the traversal is completed, the decoding result is obtained and output.
[0157] For example, in the encoding result, target_set includes {AE}, single_values sequence includes [ABBBCCDEA], and repeated_counts sequence includes
[442] . Then, during the decoding process:
[0158] Scan the single_values sequence. Since A is in target_set, A is output 4 times according to the first 4 in the repeated_counts sequence, and the sequence [AAAA] is obtained. The first 4 in the repeated_counts sequence is deleted, and the updated repeated_counts sequence is
[42] .
[0159] Continue to scan the single_values sequence. Since B, C, and D are not in the target_set, they are directly output to obtain the sequence [AAAABBBCCD];
[0160] Continue to scan the single_values sequence. Since E is in the target_set, E is output 4 times according to the first 4 in the updated repeated_counts sequence
[42] , and the sequence [AAAABBBCCDEEEE] is obtained. The first 4 in the updated repeated_counts sequence
[42] is deleted, and the second updated repeated_counts sequence is [2].
[0161] Continue to scan the single_values sequence. Since A is in the target_set, A is output twice according to the first 2 in the twice updated repeated_counts sequence [2], and the sequence [AAAABBBCCDEEEEAA] is obtained. The first 2 in the twice updated repeated_counts sequence [2] is deleted, and the sequence [AAAABBBCCDEEEEAA] is output as the decoding result.
[0162] In some other embodiments, the encoding result is obtained by encoding the second data other than the first data in the N data, and the encoding result includes a first element, a second element, a fifth element, and a sixth element, the fifth element is determined based on the second data, and the sixth element is used to indicate the arrangement of the second data and the first data in the N data. The first element is located in the single_values sequence, and the second element is located in the repeated_counts sequence. Accordingly, decoding the encoding result includes: decoding the first element and the fifth element according to the second element and the sixth element.
[0163] After receiving the encoding result, the decoder scans the single_values sequence in the encoding result, traverses from the first element of the single_values sequence, and continuously outputs the first data included in the first element according to the number of consecutive appearances represented by the first second element in the repeated_counts sequence, and then deletes the first second element in the repeated_counts sequence. After the traversal is completed, the first decoding result is obtained. In addition, the fifth element is scanned and the second data included in the fifth element is directly output to obtain the second decoding result. Then, according to the arrangement of the second data and the first data indicated by the sixth element in the N data, the first decoding result and the second decoding result are arranged to obtain the decoding result.
[0164] For example, in the encoding result, the single_values sequence includes [A], the repeated_counts sequence includes [6], the sequence including all fifth elements is [BBB], and the sixth element indicates that the second data is arranged after the first data. Then, in the decoding process:
[0165] Scan the single_values sequence, output A six times in succession according to the first 6 in the repeated_counts sequence, thereby obtaining the first decoding result [AAAAAA], and delete the first 6 in the repeated_counts sequence;
[0166] Scan the sequence including all fifth elements to obtain the second decoding result [BBB];
[0167] Since the sixth element indicates that the second data are all arranged after the first data, the decoder arranges [BBB] after [AAAAAA], and obtains and outputs the decoding result as [AAAAAABBB].
[0168] In summary, the decoding method provided in the embodiment of the present application can decode the encoding result and achieve lossless restoration of data. Figure 2 The encoding result is obtained by encoding using the encoding method shown. The technical effect of the encoding result can be found in the description of the encoding method and will not be repeated here.
[0169] In the above, the encoding method and the decoding method provided in the embodiments of the present application are respectively described. Next, the derivation process of the formula (1) proposed above is described.
[0170] Among them, there are i different values of data in N data, and the i-th data V i The frequency of occurrence in N data is N i , the i-th data V i The probability p of appearing in N data i =N i / N, or N i =Np i If the data V i Performing RLE will generate a single_values sequence, and RLE can make V i The frequency of occurrence decreases, and the decrease is recorded as the expected It is expressed as the following formula (3):
[0171] Frequency of occurrence in N data - V i Frequency formula in single_values sequence (3)
[0172] Of course, in addition to the single_values sequence, a repeated_counts sequence is also generated, and the single_values sequence and the repeated_counts sequence contain the same number of elements. i The bits occupied by the corresponding element are denoted as s i , the data V in the repeated_counts sequence i The bits occupied by the corresponding element are denoted as s r , then the data V i The condition for no degradation after RLE is expressed as the following formula (4):
[0173]
[0174] In formula (4), Np i ·s i For data V i The bits occupied in N data, is V described in the above formula (3) i The frequency of occurrence in the single_values sequence, then For data V i The number of bits occupied in the repeated_counts sequence, For data V i The number of bits occupied in the sequence of single_values.
[0175] If formula (4) is used directly, In the process of solving, complete RLE is performed on N data to obtain reference coding results, and then V is obtained for each data by combining the reference coding results. i of Reuse For each data V i Calculate once whether formula (4) is valid. If it is valid, confirm that the data V i Suitable for RLE, if not, confirm data V i If a data V i If the confirmation result indicates that it is suitable to perform RLE, then when re-performing RLE, the data V i Perform RLE, if a data V i If the confirmation result indicates that it is not suitable for RLE, the data V will not be used when RLE is repeated. i Perform RLE.
[0176] It can be seen that two rounds of RLE are required in the above solution process, the coding overhead is large, the coding efficiency is low, and the practicality is poor. Moreover, only the first complete RLE has a computational complexity of O(N), which is relatively high. Therefore, the embodiment of the present application simplifies formula (4) to obtain the above formula (1) with a computational complexity of O(1), thereby obtaining a coding method with low computational complexity, so that the coding method is suitable for fields such as information and communications technology (ICT), which require encoding of massive data with low overhead.
[0177] According to the pigeonhole principle, a lossless compression algorithm that never degrades on any data distribution may not exist, so it is necessary to make assumptions about the data distribution of the coded data according to the business scenario. After analysis, in business scenarios such as image compression, database, and communication, the coded data is relatively well in line with independent and identical distribution, so it can be assumed that the data distribution is independent and identically distributed. In addition, the data V i The probability p of appearing in N data i It may be an observed value. In order to avoid excessive deviation between the observed value and the true value caused by accidental errors, it can be further assumed that the number of data to be encoded is large enough.
[0178] On this basis, a reference sequence is defined, which includes exactly n data V i , or in other words, data V i The number of consecutive occurrences of is exactly n. When scanning N data from beginning to end, the expected number of occurrences of this reference sequence is recorded as E. Fig.10 As shown in the figure, in N data, the position of the reference sequence can be divided into three types: head, middle and tail. It is easy to understand that Fig.10 The example in which n is 4 is given, and the “single slash” indicates that the reference sequence includes data V i , and the "cross line" indicates that the data V i Other data with different values. Under the assumption of independent and identical distribution described above, p i Equal to data V i The probability of appearing at any position in the N data is expressed as the expected number of times E that the reference sequence appears at the head or tail is expressed as the following formula (5), and the expected number of times E that the reference sequence appears in the middle is expressed as the following formula (6):
[0179] E=(1-p i ) i n Formula (5)
[0180] E=(1-p i ) i n (1-p i )(Nn-1) Formula (6)
[0181] If n≤N-2, the reference sequence may appear in the head, middle and tail positions. If n=N-1, the reference sequence may appear in the head or tail, and the expected number of times E is (1-p i ) i N-1 , if n = N, then the N data are all of the same type V i , the expected number of times E is p i N .
[0182] For n data V i After RLE is performed on the reference sequence, the data V in the single_values sequence i The number of elements corresponding to Q, and the data V in the repeated_counts sequence i The number of corresponding elements Q is expressed as the following formula (7), where the symbol in formula (7) is the rounding symbol:
[0183]
[0184] Furthermore, among the Q elements in the repeated_counts sequence, one element has a value of (n mod )-1, mod is the modulus operator, (n mod ) means n divided by The remainder obtained, the values of the remaining elements are
[0185] Therefore, each time the reference sequence appears, The resulting contribution W is expressed as follows:
[0186]
[0187] Based on the above derivation, we can get the following formula (9):
[0188]
[0189] The error term ∈1 is defined according to the following formula (10):
[0190]
[0191] Then the above formula (9) can be simplified to the following formula (11):
[0192]
[0193] Next, we need to continue simplifying formula (11).
[0194] Combination Fig.11 It can be seen that -∈1 has shown an obvious convergence trend and a convergence value when N is small, so a function that approximates the convergence value can be found. Among them, two constants are defined according to the following formulas (12) and (13):
[0195] k α =(1-p i )(p i -1) Formula (12)
[0196] k β =(1-p i )((1-p i )(N-1)+2) Formula (13)
[0197] Then formula (11) can be expressed as the following formula (14):
[0198]
[0199] exist In the case of , there is the following formula (15):
[0200]
[0201] The error term ∈2 is defined according to the following formula (16):
[0202]
[0203] Then formula (14) can be expressed as the following formula (17):
[0204]
[0205] exist In the case of , the value of one term with a rounding-up sign in the above formula (15) is always 1, and there is no error, so no special processing is required.
[0206] In order to replace the summation symbol in formula (17), the following three lemmas are proved.
[0207] In Lemma 1, when a∈(0, 1), the following formula (18) is obtained according to the geometric sequence summation formula. Combining with formula (19), Lemma 1 can be obtained as formula (20), where the representation of st in formula (19) is subject to (subject to):
[0208]
[0209]
[0210]
[0211] In Lemma 2, when a∈(0, 1), by differentiating both sides of the equal sign of Lemma 1 on a, we can get the following formula (21). Therefore, Lemma 2 can be obtained from formula (21) as formula (22):
[0212]
[0213]
[0214] In Lemma 3, when a∈(0, 1), by differentiating both sides of the equal sign of Lemma 2 on a, we can obtain the following formula (23). By multiplying both sides of the equal sign of formula (23) by a, Lemma 3 is obtained as formula (24):
[0215]
[0216]
[0217] Since N is large enough, we can use Lemma 1, Lemma 2 and Lemma 3 (p i That is a) in these lemmas, replace the summation symbol in formula (17) with the convergence value of the infinite series, which (i.e. the substitution process) will introduce an error term ∈3, then formula (17) can be simplified to the following formula (25):
[0218]
[0219] Wherein, the error terms ∈1, ∈2 and ∈3 are ignored, and the above formulas (12) and (13) are substituted into formula (25), so that the following formula (26) can be obtained:
[0220]
[0221] In the embodiment of the present application, the error terms ∈1, ∈2 and ∈3 can be ignored because of the following reasons.
[0222] First, for the error term ∈1, when N>0 and p i<1 (because p i = 1, the N data are all of the same type, and RLE can be performed directly without analysis), and the following formula (27) is monotonically increasing:
[0223]
[0224] Therefore, there is the following formula (28):
[0225]
[0226] And, p i When Np is less than 1, i is always an integer, so N-Np i ≥1, then there exists the following formula (29):
[0227]
[0228] Then, we can conclude that ∈1∈(0,1]<<N, and thus ∈1 can be ignored.
[0229] Second, for the error term ∈2, based on formula (16), combined with the above Lemma 1, Lemma 2 and Lemma 3, we get the following formula (30):
[0230]
[0231] Therefore, formula (30) is a constant, is also a constant. The influence of ∈2 is mainly related to s r Related, r The larger is, the smaller is the impact of ∈2. Fig.12 From (1) in the above, we can see that when s r =8 (i.e., one byte), the effect of ∈2 almost completely disappears, because the overlap between the solid line and the dotted line in (1) is very high. Fig.12 From (2) in the above, we can see that when s r =4 (i.e. half a byte), the impact of ∈2 is also very small (can be found in p i >0.8), because the coincidence degree between the solid line and the dashed line in (2) is also relatively high. r The impact is very small, so ∈2 can be ignored directly.
[0232] Third, for the error term ∈3 which is more difficult to quantize, due to When N is small, there is an obvious convergence trend, but N is often large, so the ∈3 brought by replacing the summation sign with the convergence value of the infinite series can also be ignored.
[0233] In the embodiment of the present application, in order to further prove that the above three error terms can be ignored, an experiment was conducted. In the experiment, when the values of N are 1024, 2048 and 4096 (N has 3 values), p i The values are 0%, 5%, ..., 95% (p i There are 20 values in total), and randomly select data from N data to replace the occupied s i bits of data V i (Data V i The value of is different from the value of the data included in the N data). Next, set s r , and RLE is used for encoding, then for each group s i and r , a total of 60 (3*20) data points are obtained. For each data point, the pre-compression data V i The occupied bits (i.e., NP in formula (4) i ·s i ) and the compressed data V i The occupied bits (i.e., the bits in formula (4) Compare and calculate the data V i The space that can be saved by performing RLE, that is, the data before compression V i Occupied bits - compressed data V i When the occupied bits are positive, RLE can be used so that RLE will not be degraded.
[0234] like Fig.13 As shown, Fig.13 Each group of s i and r The corresponding measured results and the results calculated according to formula (26). Fig.13 Among the 8 coordinate systems, the coordinate system s in the first column r =4, the coordinate system s in the second column r =8, the coordinate system s in the first row i = 1, the coordinate system s in the second row i =2, the coordinate system s located in the third row i =3, the coordinate system s located in the fourth row i =4. And, in Fig.13 In each coordinate system, the vertical axis is the saved space, and the horizontal axis is the data V before compression. iThe bits occupied by the vertical and horizontal axes of different coordinate systems may have slightly different magnitudes. The discrete points are all measured results, and the continuous lines are all calculated according to formula (26). The three lines in each coordinate system correspond to the cases where N is 1024, 2048, and 4096 from left to right. It is easy to see that in each group s i and r In the figure, the measured results are consistent with the results calculated according to formula (26), which verifies the correctness and applicability of formula (26).
[0235] Furthermore, compared with the related art, s r Set to a larger value such as 8 bits or 24 bits. The opposite choice of the embodiment of the present application is to set s r Set it to a smaller value, such as 4 bits, to ensure that more space is saved when performing RLE on the data, because the saved space is equal to s r The value of is negatively correlated, the reason is as follows.
[0236] Substituting formula (26) into formula (4), we can obtain the following formula (31):
[0237] Np i ·s i ≥(Np i -E(p i ,N))·(s r +s i )→Np i ·s i ≥(Np i -(N-1)p i 2 )·(s r +s i )→Np i ·s i ≥(N-1)p i 2 s i -(Np i -(N-1)p i 2 )s r Formula (31)
[0238] Since Np i is always an integer, so Np i -(N-1)p i 2 ≥0, so we can conclude that within the allowable error range, the space saved is equal to s r The value of is negatively correlated.
[0239] In addition, formula (31) is further transformed to the following formula (32):
[0240]
[0241] Since N is large enough, N-1≈N≈N+1, and formula (32) can be further simplified to the following formula (33):
[0242]
[0243] At this point, the derivation process is completed and the above formula (1) is obtained.
[0244] The above describes the encoding method provided by the embodiment of the present application. Corresponding to the above method, the embodiment of the present application also provides an encoding device. The device is used to Fig.14 The modules shown above perform the Figure 2 The encoding method shown in Fig.14 As shown, the encoding device provided in the embodiment of the present application includes the following modules.
[0245] An acquisition module 1401 is used to acquire a data set, where the data set includes N data, where N is greater than or equal to 2;
[0246] An encoding module 1402 is configured to perform RLE on the first data among the N data if the frequency of occurrence of the first data among the N data is greater than or equal to a reference threshold;
[0247] The reference threshold is determined based on N, the bits occupied by the first element and the bits occupied by the second element, the first element is determined based on the first data, and the second element is the number of consecutive occurrences of the first data.
[0248] In a possible implementation, the reference threshold is determined based on a ratio of a first value to a second value, where the first value is the product of bits occupied by the second element and N, and the second value is the sum of bits occupied by the first element and bits occupied by the second element.
[0249] In a possible implementation, the encoding module 1402 is also used to encode the second data other than the first data in the N data to obtain an encoding result; wherein the encoding result includes a first element, a second element, a third element and a fourth element, the third element is determined based on the second data, the arrangement of the third element and the first element in the encoding result is the same as the arrangement of the second data and the first data in the N data, and the fourth element is determined based on the first data.
[0250] In one possible implementation, the encoding module 1402 is also used to encode the second data other than the first data in the N data to obtain an encoding result; wherein the encoding result includes a first element, a second element, a fifth element and a sixth element, the fifth element is determined based on the second data, and the sixth element is used to indicate the arrangement of the second data and the first data in the N data.
[0251] In one possible implementation, the second element occupies 2 bits. M bits, M is greater than or equal to 1.
[0252] The present application also provides a decoding device, which is used to Fig.15 The modules shown above perform the Figure 8 The decoding method shown in Fig.15 As shown, the decoding device provided in the embodiment of the present application includes the following modules.
[0253] An acquisition module 1501 is used to acquire an encoding result, where the encoding result is obtained by performing RLE on the first data among N data included in the data set, where N is greater than or equal to 2, and the frequency of occurrence of the first data in the N data is greater than or equal to a reference threshold, where the reference threshold is determined based on N, bits occupied by the first element, and bits occupied by the second element, where the first element is determined based on the first data, and the second element is the number of consecutive occurrences of the first data;
[0254] The decoding module 1502 is used to decode the encoding result.
[0255] In a possible implementation, the reference threshold is determined based on a ratio of a first value to a second value, where the first value is the product of bits occupied by the second element and N, and the second value is the sum of bits occupied by the first element and bits occupied by the second element.
[0256] In a possible implementation, the encoding result is also obtained by encoding the second data other than the first data in N first data, and the encoding result includes a first element, a second element, a third element and a fourth element, the third element is determined based on the second data, and the arrangement of the third element and the first element in the encoding result is the same as the arrangement of the second data and the first data in the N data, and the fourth element is determined based on the first data; the decoding module 1502 is used to decode the first element and the third element according to the second element and the fourth element.
[0257] In a possible implementation, the encoding result is also obtained by encoding the second data other than the first data in N first data, and the encoding result includes a first element, a second element, a fifth element and a sixth element, the fifth element is determined based on the second data, and the sixth element is used to indicate the arrangement of the second data and the first data in the N data; the decoding module 1502 is used to decode the first element and the fifth element according to the second element and the sixth element.
[0258] In one possible implementation, the second element occupies 2 bits. M bits, M is greater than or equal to 1.
[0259] Above Fig.14 The device shown in the figure has the following beneficial effects when realizing its function: Figure 2 The encoding method shown in the figure has the same beneficial effects. Fig.15 The device shown in the figure has the following beneficial effects when realizing its function: Figure 8 The decoding method shown has the same beneficial effects. Fig.14 and Fig.15 When the device provided realizes its functions, only the division of the above-mentioned functional modules is used as an example for illustration. In practical applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the device and method embodiments provided in the above embodiments belong to the same concept, and their specific implementation process is detailed in the method embodiment, which will not be repeated here.
[0260] See also Fig.16 , Fig.16 A schematic structural diagram of an exemplary computer device 1600 of the present application is shown. The computer device 1600 includes at least one processor 1601 , a memory 1603 , and at least one network interface 1604 .
[0261] Processor 1601 is, for example, a general-purpose central processing unit (CPU), a digital signal processor (DSP), a network processor (NP), a graphics processing unit (GPU), a neural-network processing units (NPU), a data processing unit (DPU), a microprocessor or one or more integrated circuits or application-specific integrated circuits (ASICs) for implementing the solution of the present application, a programmable logic device (PLD), other general-purpose processors or other programmable logic devices, discrete gates, transistor logic devices, discrete hardware components or any combination thereof. PLD is, for example, a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL) or any combination thereof. A general-purpose processor may be a microprocessor or any conventional processor, etc. It is worth noting that the processor may be a processor supporting an advanced RISC machines (ARM) architecture. It can implement or execute various logic blocks, modules and circuits described in conjunction with the disclosure of this application. The processor can also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, and the like.
[0262] Optionally, the computer device 1600 further includes a bus 1602. The bus 1602 is used to transmit information between the components of the computer device 1600. The bus 1602 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The bus 1602 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Fig.16 The fact that only one line is used in the diagram does not mean that there is only one bus or only one type of bus.
[0263] The memory 1603 is, for example, a volatile memory or a nonvolatile memory, or may include both volatile and nonvolatile memories. Among them, the nonvolatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), which is used as an external cache.
[0264] By way of example but not limitation, many forms of ROM and RAM are available. For example, ROM is a compact disc read-only memory (CD-ROM). RAM includes, but is not limited to, static RAM (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM) and direct rambus RAM (DR RAM).
[0265] The memory 1603 may also be other types of storage devices that can store static information and instructions. Or it may be other types of dynamic storage devices that can store information and instructions. Or it may be other optical disk storage, optical disk storage (including compressed optical disk, laser disk, optical disk, digital versatile disk, blue-ray disk, etc.), magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by the computer, but is not limited to this. The memory 1603, for example, exists independently and is connected to the processor 1601 through the bus 1602. The memory 1603 may also be integrated with the processor 1601.
[0266] The network interface 1604 uses any transceiver-like device to communicate with other devices or communication networks, and the communication network can be Ethernet, radio access network (RAN) or wireless local area network (WLAN), etc. The network interface 1604 may include a wired network interface and may also include a wireless network interface. Specifically, the network interface 1604 may be an Ethernet interface, such as a fast Ethernet (FE) interface, a gigabit Ethernet (GE) interface, an asynchronous transfer mode (ATM) interface, a WLAN interface, a cellular network interface or a combination thereof. The Ethernet interface may be an optical interface, an electrical interface or a combination thereof. In some embodiments of the present application, the network interface 1604 may be used for the computer device 1600 to communicate with other devices.
[0267] In a specific implementation, as some embodiments, the processor 1601 may include one or more CPUs, such as Fig.16 0 and CPU1 shown in FIG. Each of these processors may be a single-core processor or a multi-core processor. A processor herein may refer to one or more devices, circuits, and / or processing cores for processing data (e.g., computer program instructions).
[0268] In a specific implementation, as some embodiments, the computer device 1600 may include multiple processors, such as Fig.16 1 and 1605. Each of these processors may be a single-core processor or a multi-core processor. A processor herein may refer to one or more devices, circuits, and / or processing cores for processing data (such as computer program instructions).
[0269] In some implementations, the memory 1603 is used to store program instructions 1610 for executing the solution of the present application, and the processor 1601 can execute the program instructions 1610 stored in the memory 1603. That is, the computer device 1600 can implement the method provided in the method embodiment through the processor 1601 and the program instructions 1610 in the memory 1603, that is, Figure 2 The encoding method shown or Figure 8 The decoding method shown. The program instruction 1610 may include one or more software modules. Optionally, the processor 1601 itself may also store program instructions for executing the solution of the present application.
[0270] In a specific implementation process, the computer device 1600 of the present application may correspond to a product for executing the above method, such as an encoder or a decoder. The processor 1601 in the computer device 1600 reads the instructions in the memory 1603, and uses Fig.16 The computer device 1600 shown is capable of executing all or part of the steps in the method embodiment.
[0271] The computer device 1600 may also correspond to the above Fig.14 or Fig.15 The device shown, Fig.14 or Fig.15 Each functional module in the apparatus shown is implemented using software of the computer device 1600. In other words, Fig.14 or Fig.15 The functional modules included in the illustrated apparatus are generated after the processor 1601 of the computer device 1600 reads the program instructions 1610 stored in the memory 1603 .
[0272] in, Figure 2 or Figure 8 Each step of the method shown is completed by an integrated logic circuit of hardware or software instructions in the processor of the computer device 1600. The steps of the method embodiment disclosed in the present application can be directly embodied as being executed by a hardware processor, or can be executed by a combination of hardware and software modules in the processor. The software module can be located in a mature storage medium in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory, and the processor reads the information in the memory and completes the steps of the above method embodiment in combination with its hardware. To avoid repetition, it is not described in detail here.
[0273] The present application provides a computer device, which includes a memory and a processor; the memory stores at least one computer instruction, and the at least one computer instruction is loaded and executed by the processor, so that the computer device implements the above Figure 2 The encoding method shown or Figure 8 The decoding method shown.
[0274] The embodiment of the present application provides a coding and decoding system, which includes an encoder and a decoder, wherein the encoder is used to perform the above Figure 2 The encoding method shown in the figure is used to perform the above Figure 8 The decoding method shown.
[0275] Exemplarily, an embodiment of the present application provides a computer program or a computer program product, the computer program or the computer program product comprising: computer instructions, when the computer instructions are executed by a computer, the computer implements the above Figure 2The encoding method shown or Figure 8 The decoding method shown.
[0276] The present application embodiment provides a computer-readable storage medium, which stores computer instructions. When the computer instructions are executed on a computer, the computer executes the above Figure 2 The encoding method shown or Figure 8 The decoding method shown.
[0277] In an exemplary embodiment, the present application provides a chip, including a processor, for calling and executing instructions stored in a memory, so that a computer equipped with the chip executes the above-mentioned Figure 2 The encoding method shown or Figure 8 The decoding method shown.
[0278] The embodiment of the present application also provides another chip, including: an input interface, an output interface, a processor and a memory, wherein the input interface, the output interface, the processor and the memory are connected through an internal connection path, and the processor is used to execute the code in the memory. When the code is executed, the computer equipped with the chip executes the above Figure 2 The encoding method shown or Figure 8 The decoding method shown.
[0279] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) mode. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid state disk), etc.
[0280] In this application, the terms "first", "second", etc. are used to distinguish between identical or similar items with substantially the same effects and functions. There is no logical or temporal dependency between "first", "second", and "nth", nor is there a limit on the quantity and execution order. It should also be understood that although the following description uses the terms first, second, etc. to describe various elements, these elements should not be limited by the terms. These terms are only used to distinguish one element from another element.
[0281] It should also be understood that in the various embodiments of the present application, the size of the serial number of each process does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0282] The term "at least one" in this application means one or more, and the term "multiple" in this application means two or more, for example, multiple data means two or more data. The terms "system" and "network" are often used interchangeably herein.
[0283] It should be understood that the terms used in the description of the various examples herein are only for describing specific examples and are not intended to be limiting. As used in the description of the various examples and the appended claims, the singular forms "a", "an", and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
[0284] It should also be understood that the term "and / or" used herein refers to and encompasses any and all possible combinations of one or more of the associated listed items. The term "and / or" is a description of the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this application generally indicates that the associated objects before and after are in an "or" relationship.
[0285] It should also be understood that the terms "if" and "if" may be interpreted to mean "when" or "upon" or "in response to determining" or "in response to detecting." Similarly, the phrases "if it is determined that ..." or "if [a stated condition or event] is detected" may be interpreted to mean "upon determining that ..." or "in response to determining that ..." or "upon detecting [a stated condition or event]" or "in response to detecting [a stated condition or event]," depending on the context.
[0286] The above description is only an embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the principles of the present application shall be included in the protection scope of the present application.
Claims
1. A coding method, characterized in that: The method comprises: Acquire a data set, the data set including N data, where N is greater than or equal to 2; If the frequency of occurrence of the first data among the N data is greater than or equal to the reference threshold, run-length encoding RLE is performed on the first data; The reference threshold is determined based on N, bits occupied by a first element and bits occupied by a second element, the first element is determined based on the first data, and the second element is the number of consecutive occurrences of the first data.
2. The method according to claim 1, characterized in that The reference threshold is determined based on a ratio of a first value to a second value, wherein the first value is the product of bits occupied by the second element and N, and the second value is the sum of bits occupied by the first element and bits occupied by the second element.
3. The method according to claim 1 or 2, characterized in that: The method further comprises: Encode the second data except the first data among the N data to obtain an encoding result; Among them, the encoding result includes the first element, the second element, the third element and the fourth element, the third element is determined based on the second data, the arrangement of the third element and the first element in the encoding result is the same as the arrangement of the second data and the first data in the N data, and the fourth element is determined based on the first data.
4. The method according to claim 1 or 2, characterized in that: The method further comprises: Encode the second data except the first data among the N data to obtain an encoding result; The encoding result includes the first element, the second element, the fifth element and the sixth element, the fifth element is determined based on the second data, and the sixth element is used to indicate the arrangement of the second data and the first data in the N data.
5. The method according to any one of claims 1 to 4, characterized in that: The second element occupies 2 bits. M bits, where M is greater than or equal to 1.
6. A decoding method, characterized in that: The method comprises: Obtaining an encoding result, where the encoding result is obtained by performing run-length encoding (RLE) on first data among N data included in a data set, where N is greater than or equal to 2, and a frequency of occurrence of the first data in the N data is greater than or equal to a reference threshold, where the reference threshold is determined based on N, bits occupied by the first element, and bits occupied by the second element, where the first element is determined based on the first data, and where the second element is the number of consecutive occurrences of the first data; The encoding result is decoded.
7. The method according to claim 6, characterized in that The reference threshold is determined based on a ratio of a first value to a second value, wherein the first value is the product of bits occupied by the second element and N, and the second value is the sum of bits occupied by the first element and bits occupied by the second element.
8. The method according to claim 6 or 7, characterized in that: The encoding result is also obtained by encoding second data other than the first data in the N first data, the encoding result includes the first element, the second element, the third element and the fourth element, the third element is determined based on the second data, the arrangement of the third element and the first element in the encoding result is the same as the arrangement of the second data and the first data in the N data, and the fourth element is determined based on the first data; The decoding of the encoding result comprises: The first element and the third element are decoded according to the second element and the fourth element.
9. The method according to claim 6 or 7, characterized in that: The encoding result is also obtained by encoding the second data other than the first data in the N first data, the encoding result includes the first element, the second element, the fifth element and the sixth element, the fifth element is determined based on the second data, and the sixth element is used to indicate the arrangement of the second data and the first data in the N data; The decoding of the encoding result comprises: The first element and the fifth element are decoded according to the second element and the sixth element.
10. The method according to any one of claims 6 to 9, characterized in that: The second element occupies 2 bits. M bits, where M is greater than or equal to 1.
11. A coding device, characterized in that: The device comprises: An acquisition module, used to acquire a data set, wherein the data set includes N data, where N is greater than or equal to 2; An encoding module, configured to perform run-length encoding (RLE) on the first data among the N data if the frequency of occurrence of the first data among the N data is greater than or equal to a reference threshold; The reference threshold is determined based on N, bits occupied by a first element and bits occupied by a second element, the first element is determined based on the first data, and the second element is the number of consecutive occurrences of the first data.
12. The device according to claim 11, characterized in that The reference threshold is determined based on a ratio of a first value to a second value, wherein the first value is the product of bits occupied by the second element and N, and the second value is the sum of bits occupied by the first element and bits occupied by the second element.
13. The device according to claim 11 or 12, characterized in that The encoding module is further used to encode second data other than the first data in the N data to obtain an encoding result; Among them, the encoding result includes the first element, the second element, the third element and the fourth element, the third element is determined based on the second data, the arrangement of the third element and the first element in the encoding result is the same as the arrangement of the second data and the first data in the N data, and the fourth element is determined based on the first data.
14. The device according to claim 11 or 12, characterized in that The encoding module is further used to encode second data other than the first data in the N data to obtain an encoding result; The encoding result includes the first element, the second element, the fifth element and the sixth element, the fifth element is determined based on the second data, and the sixth element is used to indicate the arrangement of the second data and the first data in the N data.
15. The device according to any one of claims 11 to 14, characterized in that: The second element occupies 2 bits. M bits, where M is greater than or equal to 1.
16. A decoding device, characterized in that: The device comprises: an acquisition module, used to acquire an encoding result, wherein the encoding result is obtained by performing run-length encoding (RLE) on first data among N data included in a data set, wherein N is greater than or equal to 2, and the frequency of occurrence of the first data in the N data is greater than or equal to a reference threshold, wherein the reference threshold is determined based on N, bits occupied by the first element, and bits occupied by the second element, wherein the first element is determined based on the first data, and the second element is the number of consecutive occurrences of the first data; A decoding module is used to decode the encoding result.
17. The device according to claim 16, characterized in that The reference threshold is determined based on a ratio of a first value to a second value, wherein the first value is the product of bits occupied by the second element and N, and the second value is the sum of bits occupied by the first element and bits occupied by the second element.
18. The device according to claim 16 or 17, characterized in that The encoding result is also obtained by encoding second data other than the first data in the N first data, the encoding result includes the first element, the second element, the third element and the fourth element, the third element is determined based on the second data, the arrangement of the third element and the first element in the encoding result is the same as the arrangement of the second data and the first data in the N data, and the fourth element is determined based on the first data; The decoding module is used to decode the first element and the third element according to the second element and the fourth element.
19. The device according to claim 16 or 17, characterized in that The encoding result is also obtained by encoding the second data other than the first data in the N first data, the encoding result includes the first element, the second element, the fifth element and the sixth element, the fifth element is determined based on the second data, and the sixth element is used to indicate the arrangement of the second data and the first data in the N data; The decoding module is used to decode the first element and the fifth element according to the second element and the sixth element.
20. The device according to any one of claims 16 to 19, characterized in that: The second element occupies 2 bits. M bits, where M is greater than or equal to 1.
21. A computer device, characterized in that: The computer device includes a memory and a processor; the memory stores at least one computer instruction, and the at least one computer instruction is loaded and executed by the processor so that the computer device implements the encoding method described in any one of claims 1-5 or the decoding method described in any one of claims 6-10.
22. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores at least one computer instruction, and the at least one computer instruction is loaded and executed by the processor so that the computer device implements the encoding method described in any one of claims 1-5 or the decoding method described in any one of claims 6-10.
23. A computer program product, characterized in that The computer program product comprises computer instructions, which are executed by a processor to enable a computer device to implement the encoding method described in any one of claims 1 to 5 or the decoding method described in any one of claims 6 to 10.
Citation Information
Patent Citations
Coding method and related equipment
CN112398484A
Data compression method and device, equipment and storage medium
CN116418348A
Encoding method and related device
WO2021027487A1
Cited By
Encoding method and apparatus, decoding method and apparatus, device and storage medium
EP4791004A1
Encoding method and apparatus, decoding method and apparatus, device and storage medium
WO2025087079A1