Encoding method, decoding method, apparatus, device, and storage medium

By setting a reference threshold and bit occupancy in the dataset to calculate suitable run-length encoded data, the problems of encoding overhead and degradation in existing methods are solved, and an efficient and accurate encoding and decoding process is achieved.

CN119906835BActive Publication Date: 2026-01-09HUAWEI TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311421118.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-10-27
Publication Date
2026-01-09
Estimated Expiration
2043-10-27

AI Technical Summary

Technical Problem

Existing run-length encoding methods tend to increase encoding overhead and data bloat when the number of consecutive occurrences in the data sequence is small. Static concatenation and static parallel methods rely on experience, which may lead to additional overhead and degradation. Adaptive selection methods have high computational complexity and low accuracy.

Method used

By obtaining the frequency of each data type in the dataset, a reference threshold is set to determine the data suitable for run-length encoding. The encoding method is determined based on the data frequency and bit occupancy. The threshold is calculated using a simple ratio and summation method. Suitable and unsuitable data are distinguished for encoding. An extra element is used to indicate the arrangement to facilitate decoding.

Benefits of technology

It achieves the avoidance of data degradation without increasing encoding overhead, improves encoding efficiency and accuracy, reduces computational complexity, and ensures the validity and decodeability of the encoding results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119906835B_ABST
    Figure CN119906835B_ABST
Patent Text Reader

Abstract

The application discloses an encoding method, a decoding method, a device, equipment and a storage medium, and belongs to the technical field of coding and decoding. In the encoding method, a data set is obtained, the data set including N data, N being greater than or equal to 2. If the frequency of a first data in the N data in the N data is greater than or equal to a reference threshold, the first data is subjected to RLE. The reference threshold is determined based on N, bits occupied by a first element and bits occupied by a second element, the first element being determined based on the first data, and the second element being the number of continuous occurrences of the first data. The application determines the first data suitable for RLE from the N data quickly and accurately based on the reference threshold with low calculation complexity. Thus, the first data suitable for RLE in the N data is subjected to RLE, the RLE is reasonable, unnecessary calculation overhead and encoding overhead are avoided, and the encoding efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of coding and decoding technology, in particular to an encoding method, a decoding method, a device, an apparatus and a storage medium. BACKGROUND

[0002] With the continuous development of coding and decoding technology, there are more and more ways for encoding and decoding data. Run-length encoding (RLE) and the corresponding decoding method are one of them. How to reasonably perform RLE and corresponding decoding on data has become a problem to be solved. SUMMARY

[0003] The present application provides an encoding method, a decoding method, a device, an apparatus and a storage medium to reasonably perform RLE and corresponding decoding on data. The technical solution provided by the present application includes the following aspects.

[0004] In a first aspect, an encoding method is provided. In the method, a data set is obtained, the data set including N data, N being greater than or equal to 2. If the frequency of occurrence of a first data in the N data is greater than or equal to a reference threshold, the first data is subjected to RLE. The reference threshold is determined based on N, the bits occupied by a first element and the bits occupied by a second element, the first element being determined based on the first data, and the second element being the number of consecutive occurrences of the first data.

[0005] The method determines the first data suitable for RLE from the N data based on the reference threshold. Thus, RLE is performed on the first data suitable for RLE, thereby achieving reasonable RLE and avoiding unnecessary encoding overhead. Moreover, 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. Thus, not only is degradation avoided after RLE, but also the calculation overhead is reduced and the encoding 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, the first value being the product of the bits occupied by the second element and N, and the second value being the sum of the bits occupied by the first element and the bits occupied by the second element.

[0007] In this implementation, the reference threshold is determined by determining the ratio, the product and the sum, which is simple and easy to implement, has low calculation overhead and is highly practical.

[0008] In a possible implementation, the method further includes: encoding the second data in the N data other than the first 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. The fourth element is determined based on the first data.

[0009] The second data is data that is not suitable for RLE. If there is second data in the N data other than the first data, the second data needs to be encoded 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 facilitates subsequent decoding of the encoding result. However, since the third element and the first element are arranged together in a certain arrangement, it is difficult to distinguish the third element and the first element from the arranged third element and first element during decoding. Therefore, the fourth element needs to be determined based on the first data to facilitate the distinction between the third element and the first element. During decoding, for any one of the arranged third element and first element, 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 in the N data other than the first data to obtain an encoding result. 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. The sixth element is used to indicate the arrangement of the second data and the first data in the N data.

[0011] As described above, the second data is data that is not suitable for RLE, and in the case where the second data exists in addition to the first data among the N data, the second data needs to be encoded in a non-RLE manner to obtain the encoding result. The first element determined based on the first data and the fifth element determined based on the second data are independent of each other, and thus the first element and the fifth element do not need to be distinguished. However, because the first element and the fifth element are independent of each other, it is difficult to determine the arrangement order of the first element and the fifth element during subsequent decoding, and thus 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 among the N data, and thus it is difficult to restore the N data. Therefore, the sixth element is needed to indicate the arrangement of the second data and the first data among the N data, so as to subsequently complete decoding.

[0012] In a possible implementation, the second element occupies 2 bits, and M is greater than or equal to 1. M

[0013] For example, the second element can occupy 4 bits, 8 bits, or the like. In this application, it is inclined to make M have a smaller value, so as to save more space after RLE of the first data.

[0014] In the second aspect, a decoding method is provided. In the method, after obtaining an encoding result, the encoding result is decoded. The encoding result is obtained by RLE of first data in a data set including N data, N is greater than or equal to 2, and 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, 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 continuous occurrences of the first data.

[0015] In a possible implementation, the reference threshold is determined based on the ratio of a first value to a 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.

[0016] In a possible implementation, the encoding result is also obtained by encoding second data in addition to the first data among the N data. The encoding result includes the first element, the 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 among 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 further encoded by a second data in the N data other than the first data, the encoding result comprises the first element, the 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 an arrangement manner of the second data and the first data in the N data. Decoding the encoding result comprises: decoding the first element and the fifth element according to the second element and the sixth element.

[0018] In a possible implementation, the second element occupies 2 bits, and M is greater than or equal to 1. M

[0019] In a third aspect, an encoding apparatus is provided, and the apparatus comprises:

[0020] An obtaining module is configured to obtain a data set, the data set comprising N data, and N is greater than or equal to 2;

[0021] An encoding module is configured to perform RLE on a first data in the N data if a frequency of occurrence of the first data in the N data is greater than or equal to a reference threshold.

[0022] The reference threshold is determined based on N, bits occupied by the first element and bits occupied by the second element, the first element is determined based on the first data, and the second element is a continuous occurrence number 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, the first value is a product of bits occupied by the second element and N, and the second value is a sum of bits occupied by the first element and bits occupied by the second element.

[0024] In a possible implementation, the encoding module is further configured to encode a second data in the N data other than the first data to obtain an encoding result, wherein the encoding result comprises the first element, the second element, a third element and a fourth element, the third element is determined based on the second data, an arrangement manner of the third element and the first element in the encoding result is same as an arrangement manner 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 a possible implementation, the encoding module is further configured to encode a second data in the N data other than the first data to obtain an encoding result, wherein the encoding result comprises the first element, the 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 an arrangement manner of the second data and the first data in the N data.

[0026] In a possible implementation, the second element occupies 2 bits, and M is greater than or equal to 1. M ​M is greater than or equal to 1.

[0027] In a fourth aspect, a decoding apparatus is provided, which comprises:

[0028] The obtaining module is configured to obtain an encoding result, the encoding result being obtained by performing RLE on a first data in N data included in the data set, N being greater than or equal to 2, the first data appearing in the N data with a frequency greater than or equal to a reference threshold, the reference threshold being determined based on N, bits occupied by a first element and bits occupied by a second element, the first element being determined based on the first data, and the second element being a number of consecutive appearances of the first data;

[0029] The decoding module is configured 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, the first value being a product of the bits occupied by the second element and N, and the second value being a sum of the bits occupied by the first element and the bits occupied by the second element.

[0031] In a possible implementation, the encoding result is further obtained by encoding a second data in the N first data other than the first data, the encoding result comprising the first element, the second element, a third element and a fourth element, the third element being determined based on the second data, an arrangement manner of the third element and the first element in the encoding result being same as an arrangement manner of the second data and the first data in the N data, and the fourth element being determined based on the first data; and the decoding module is configured 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 further obtained by encoding a second data in the N first data other than the first data, the encoding result comprising the first element, the second element, a fifth element and a sixth element, the fifth element being determined based on the second data, and the sixth element being used to indicate the arrangement manner of the second data and the first data in the N data; and the decoding module is configured to decode the first element and the fifth element according to the second element and the sixth element.

[0033] In a possible implementation, the bits occupied by the second element are 2 M M is greater than or equal to 1.

[0034] In a fifth aspect, a computer device is provided, which comprises a memory and a processor; the memory stores at least one computer instruction, the at least one computer instruction being loaded and executed by the processor, so that the computer device implements the encoding method provided in the first aspect or any possible implementation manner of the first aspect, or implements the decoding method provided in the second aspect or any possible implementation manner of the second aspect.

[0035] Optionally, the processor is one or more, and the memory is one or more.

[0036] Optionally, the memory can be integrated with the processor, or the memory is arranged separately from the processor.

[0037] In a sixth aspect, a coding system is provided, which includes an encoder and a decoder, the encoder is configured to implement the encoding method provided in the first aspect or any possible implementation manner of the first aspect, and the decoder is configured to implement the decoding method provided in the second aspect or any possible implementation manner of the second aspect.

[0038] In a seventh aspect, a computer program or a computer program product is provided, which includes computer instructions, when the computer instructions are run on a computer, the computer instructions make the computer implement the encoding method provided in the first aspect or any possible implementation manner of the first aspect, or implement the decoding method provided in the second aspect or any possible implementation manner 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 run on a computer, the computer executes the encoding method provided in the first aspect or any possible implementation manner of the first aspect, or implements the decoding method provided in the second aspect or any possible implementation manner of the second aspect.

[0040] In a ninth aspect, a chip is provided, which includes a processor, and is configured to call and run instructions stored in a memory, so that a computer installed with the chip executes the encoding method provided in the first aspect or any possible implementation manner of the first aspect, or implements the decoding method provided in the second aspect or any possible implementation manner of the second aspect.

[0041] In a tenth aspect, another chip is provided, which includes an input interface, an output interface, a processor and a memory, the input interface, the output interface, the processor and the memory are connected through internal connection paths, and the processor is configured to execute code in the memory, when the code is executed, a computer installed with the chip executes the encoding method provided in the first aspect or any possible implementation manner of the first aspect, or implements the decoding method provided in the second aspect or any possible implementation manner of the second aspect.

[0042] It should be understood that the technical effects achieved by the technical solutions provided in the second aspect to the tenth aspect and the corresponding possible implementation manners of the present application can be referred to the description of the technical effects achieved by the technical solutions provided in the first aspect and the corresponding possible implementation manners, which will not be repeated here. BRIEF DESCRIPTION OF DRAWINGS

[0043] Figure 1 A schematic diagram of an implementation environment for embodiments of the application;

[0044] Figure 2 A flowchart of an encoding method for embodiments of the application;

[0045] Figure 3 A flowchart of an encoding method for embodiments of the application;

[0046] Figure 4 A flowchart of an encoding method for embodiments of the application;

[0047] Figure 5 A schematic diagram of a service scenario of image compression for embodiments of the application;

[0048] Figure 6 A schematic diagram of a service scenario of a database for embodiments of the application;

[0049] Figure 7 A schematic diagram of a service scenario of communication for embodiments of the application;

[0050] Figure 8 A flowchart of a decoding method for embodiments of the application;

[0051] Figure 9 A flowchart of a decoding method for embodiments of the application;

[0052] Figure 10 A schematic diagram of a reference sequence for embodiments of the application;

[0053] Figure 11 A schematic diagram of a convergence trend for embodiments of the application;

[0054] Figure 12 A schematic diagram of an impact caused by an error value for embodiments of the application;

[0055] Figure 13 A comparison diagram of a measured result and a calculated result for embodiments of the application;

[0056] Figure 14 A structural schematic diagram of an encoding apparatus for embodiments of the application;

[0057] Figure 15 A structural schematic diagram of a decoding apparatus for embodiments of the application;

[0058] Figure 16 A structural schematic diagram of a computer device for embodiments of the application. DETAILED DESCRIPTION

[0059] The terms used in the implementation part of the present application are only used to explain the specific embodiments of the present application, and are not intended to limit the present application.

[0060] Run-length encoding (RLE) is an encoding method that can losslessly compress data, also known as variable-length encoding, the core idea of which is to use variable-length codes to replace data that continuously appears (or repeatedly appears) in a 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], 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], thereby representing that data A appears 4 times, data B appears 3 times, data C appears 2 times, data D appears 1 time, data E appears 4 times, and data A appears 2 times.

[0061] There are various related technologies for the above-mentioned RLE, including but not limited to the following related technology one to related technology three.

[0062] Related technology one, naive RLE scheme.

[0063] In the naive RLE scheme, the data sequence to be encoded is not analyzed, but all data in the data sequence is subjected to RLE without distinction. However, when the number of times of continuous appearance of data in the data sequence is small, the naive RLE scheme not only brings additional encoding overhead, but also may cause the size of the data sequence to be inflated (i.e., deteriorated), that is, the data amount of the variable-length code (used to replace the data sequence) may be greater than the data amount of 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 increases [1, 1, 1, 1, 1] compared to the data sequence, and thus is deteriorated.

[0064] Related technology two, static series scheme and static parallel scheme.

[0065] In the static series scheme, RLE is empirically taken as one of the encoding processes, i.e., RLE is taken as upstream or downstream of other encoding methods, including but not limited to lempel ziv 1977 (LZ77), simple 8 byte (Simple8b), GNU zip (GZIP), and the like, and GNU is a free operating system.

[0066] In the static parallel scheme, RLE is empirically bound to a specific data local part (which can be regarded as a data sequence to be encoded), i.e., RLE is only performed on the bound data local part, and RLE is not performed on other unbound data local parts. For example, a data base (DB) stores data in a table form, one column of the table is the modification date of a file, and the other column is the name of the file. RLE is bound to the modification date of the file, and RLE is not bound to the name of the file.

[0067] However, whether it is the static series scheme or the static parallel scheme, it is based on experience. If the actual data sequence does not match the experience, not only will it bring additional encoding overhead, but even if RLE is only performed on the bound data local part, it may still cause degradation.

[0068] Related technology three, adaptive selection scheme.

[0069] In the adaptive selection scheme, a heuristic algorithm is designed based on experience and observation, and the heuristic algorithm is used to determine which data in the data sequence to be encoded is suitable for RLE. Only the data suitable for RLE is subjected to RLE, and the data unsuitable for RLE is not subjected to RLE.

[0070] However, since the heuristic algorithm is only designed based on experience and observation and lacks theoretical support, the accuracy of the determination by the heuristic algorithm is low, and the actual data unsuitable for RLE may be determined as suitable for RLE, i.e., there is erroneous data, which leads to degradation after RLE is performed on the erroneous data and poor stability. Moreover, the heuristic algorithm has high computational complexity, which brings additional computational overhead on the basis of the encoding overhead, affecting the encoding efficiency.

[0071] To this end, an encoding method is provided in the embodiments of the present application to improve or solve the problems in the above related technologies. Exemplarily, as shown in Figure 1As shown, the encoding method is applied in software 101, and the software 101 to which the encoding method is applied is deployed in a product 102, which has functions including but not limited to encoding functions or data compression functions. The product 102 for deploying the software 101 can be in the form of software or hardware, which is not limited here. See Figure 2 The encoding method includes steps 201 and 202 as follows.

[0072] Step 201, obtaining a data set, the data set including N data, N being greater than or equal to 2.

[0073] Among them, the N data included in the data set are data to be encoded, and different data in the N data can have the same value or different values. In the embodiments of the present application, data with the same value is regarded as the same kind of data, and the N data can include at least one kind of data.

[0074] In some embodiments, the N data is all the data to be encoded, and the N data can be obtained by receiving or generated, which is not limited here. Alternatively, in other embodiments, the N data is part of the data to be encoded, and obtaining the N data includes: obtaining a plurality of data, and sampling N data from the plurality of data. The sampling process can reduce the amount of data, that is, the amount of data of the N data is less than the amount of data of the plurality of data, and the subsequent calculation required for calculation based on the N data is less. Therefore, the embodiments of the present application can obtain N data by sampling in the case of limited computing power. For example, a quantity threshold is determined according to the computing power, so that the quantity of the N data obtained by sampling is less than or equal to the quantity threshold. Correspondingly, the embodiments of the present application can take all the data to be encoded as the N data in the case of sufficient computing power.

[0075] Exemplarily, the plurality of data can be all the data to be encoded, which can be obtained by receiving or generating. Alternatively, the plurality of data can 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 plurality of data is one group of data in the at least two groups.

[0076] In different service scenarios, the manner of dividing the entire data to be encoded into at least two groups is also different, which will be described in detail in the following three examples. In the service scenario of image compression, the image includes a plurality of pixels, each pixel corresponds to a plurality of color channels, and each pixel has a value on each color channel. The entire data to be encoded includes the value of each pixel on each color channel. The entire data to be encoded is divided according to the color channel to obtain a plurality of groups of data corresponding to the plurality of color channels one by one. Each group of data is the value of each pixel in the image on the color channel corresponding to the group of data. The plurality of data is a group of data in the plurality of groups of data. Alternatively, in the service scenario of a database, the database stores data in the form of a table, and the table includes a plurality of rows and a plurality of columns. The entire data to be encoded includes all the data stored in the table. The entire data to be encoded is divided according to the column (or row) to obtain a plurality of groups of data corresponding to each column (or row) one by one. Each group of data is the data stored in a column (or a row) included in the table. The plurality of data is a group of data in the plurality of groups of data. Alternatively, in the service scenario of communication, binary signals need to be transmitted, the binary signals include a plurality of bits, and each bit has a value of 0 or 1. The entire data to be encoded is the plurality of bits. The entire data to be encoded is divided to obtain a plurality of groups of data. Each group of data includes a certain number of bits. The plurality of data is a group of data in the plurality of groups of data. Of course, the service scenarios to which the encoding method provided by the embodiments of the present application are applicable are not limited to the service scenarios exemplified above, but can also include other service scenarios that need to be encoded, which will not be exemplified and described herein.

[0077] Regardless of the manner of obtaining the plurality of data, the embodiments of the present application can sample the plurality of data after obtaining the plurality of data, thereby obtaining N data. For example, the plurality of data can be randomly sampled. For another example, a data can be collected every certain number of data in the plurality of data. The embodiments of the present application do not limit the sampling manner, and other sampling manners can also be applied to the embodiments of the present application according to actual needs. For example, other sampling manners can be flexibly used so that each data in the plurality of data is sampled into the N data.

[0078] Exemplarily, the embodiments of the present application can execute step 201 and step 202 when the entire data to be encoded satisfies the independent and identical distribution and the number of the entire data to be encoded is sufficient. For example, when the number of the entire data to be encoded is greater than 1000, it is considered that the number of the entire data to be encoded is sufficient. In addition, for other types of data distribution or other quantities of the entire data to be encoded, the encoding method provided by the embodiments of the present application can also be applied, which is not limited herein.

[0079] In step 202, if the frequency of the first data in the N data is greater than or equal to the reference threshold, the first data is subjected to RLE.

[0080] According to the description in step 201, the data with the same value in the N data is the same kind of data, and the reference threshold is a threshold for determining whether the various data in the N data is suitable for RLE. For each kind of data in the N data, if the frequency of the kind of data in the N data is greater than or equal to the reference threshold corresponding to the kind of data, the kind of data is the first data suitable for RLE, and if the frequency of the kind of data in the N data is less than the reference threshold corresponding to the kind of data, the kind of data is considered to be data unsuitable for RLE. Since the first data is suitable for RLE, the first data can be subjected to RLE. Wherein, the RLE of the first data can obtain an encoding result, and the first data suitable for RLE can be quantified as: the data amount of the encoding result is less than or equal to the data amount of the first data itself, so as to ensure that there is no degradation after the first data is subjected to RLE.

[0081] When the N data is all the data to be encoded, the RLE of the first data includes: the RLE of the first data in the N data. Or, when the N data is part of the data to be encoded, that is, the N data is sampled from a plurality of data, the RLE of the first data includes: the RLE of the first data in the plurality of data. The reason is that the plurality of data also includes other data in addition to the N data, and the other data may also include the first data suitable for RLE. Therefore, instead of only RLE of the first data in the N data, the RLE of the first data in the plurality of data is performed to avoid incomplete encoding of the first data and loss of the first data.

[0082] In some embodiments, each kind of data in the N data is the first data suitable for RLE, and the encoding result can only include the corresponding first element and 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.

[0083] Each first data corresponds to at least one first element, and the first element can be determined based on the first data in multiple ways. For example, in a case where the data with different values in the N data occupies the same bits (i.e., variable bit width storage), and a separator needs to exist between adjacent data, one first element can include only one first data, or one first data and one separator. For another example, in a case where the data with different values in the N data occupies different bits (i.e., fixed bit width storage, and if the data itself occupies fewer bits, the bits occupied by the data can be increased by zero padding), and no separator needs to exist between adjacent data, one first element can include only one first data. For yet another example, one first element can include one 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 second element corresponding to the first element is the number of consecutive occurrences of the first data based on which the first element is determined. 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 second element occupies 2 M bits, and M is greater than or equal to 1. For example, the second element can occupy an integer multiple of 4 bits, including but not limited to 4 bits, 8 bits, 12 bits, and the like, which is not limited herein. Exemplarily, in a case where all the data to be encoded satisfies independent and identically distributed, the embodiment of the present application makes the second element occupy 4 bits.

[0085] In the embodiment of the present application, all the first elements can form a single_values sequence, and all the second elements can form a repeated_counts sequence, and each second element in the repeated_counts sequence occupies the same bits.

[0086] For example, the N data is [AA, AA, AA, AA, B, B, B, AA, AA], and AA and B are both first data suitable for RLE, and there can be but not limited to the following several cases.

[0087] In the case of variable bit-width storage, AA and B occupy different bits, 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 bits, the single_values sequence is [AABAA], “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.

[0089] In the case where a first element includes a first data and index information of the first data, the single_values sequence is [AA:0:7, B], the “,” 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, representing that the offset of the first data AA relative to the first data in the N data is 0 when the first data AA appears for the first time in the N data, and the offset of the first data AA relative to the first data in the N data is 7 when the first data AA appears for the second time in the N data, and “B” is the first element corresponding to the first data B. Correspondingly, 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 the first data AA appears for the first time in the N data, 2 represents the number of consecutive occurrences of the first data AA when the first data AA appears for the second time in the N data, and 3 is the second element corresponding to the first data B, representing the number of consecutive occurrences of the first data B when the first data B appears in the N data.

[0090] In the above description, the second element is in decimal form for ease of understanding, and the second element can be in binary form in application. 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, since the second element occupies a certain bit, the value range of the second element has an upper limit. If the number of consecutive occurrences of a first data exceeds the upper limit, a new first element needs to be added in the single_values sequence and a new second element needs to be added in the repeated_counts sequence. For example, the second element occupies 4 bits, and the N data are [A……A (20 As in total) BBB], and A and B are both first data suitable for RLE. The single_values sequence is [AAB], A is a first element corresponding to the first data A, and B is a first element corresponding to the first data B. The repeated_counts sequence is

[1643] , 16 and 4 are second elements corresponding to the first data A, and represent the number of consecutive occurrences of the first data A as 16 and 4, and 3 is a second element corresponding to the first data B, and represents the number of consecutive occurrences of the first data B as 3.

[0092] In some other embodiments, the N data include at least one first data suitable for RLE and a second data unsuitable for RLE. 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. Correspondingly, the encoding result can include other elements in addition to the first element and the second element described above. Details are described below.

[0093] For example, the encoding result includes a third element and a fourth element in addition to 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 the N data, and the fourth element is determined based on the first data.

[0094] The manner of determining the third element based on the second data can refer to the manner of determining the first element based on the first data described above, and details are not described herein. In the embodiment of the present application, the third element and the first element can be 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 the N data. In this way, the arrangement of the second data and the first data in the N data can be naturally reflected by the third element and the first element in the single_values sequence, without the need for additional elements to indicate the arrangement of the second data and the first data in the N data.

[0095] However, it is difficult to distinguish the third element from the first element from the single_values sequence, and thus to distinguish the second data not suitable for RLE from the first data suitable for RLE, regardless of the arrangement of the third element and the first element in the encoding result. Therefore, it is further needed to determine a fourth element based on the first data, so as to distinguish the third element from the first element. The manner of determining the fourth element based on the first data can refer to the manner of determining the first element based on the first data as described above, and will not be repeated here.

[0096] If one element in the single_values sequence includes the same data as the fourth element, the element in the single_values sequence is the first element, and the data included by the element is the first data suitable for RLE. Of course, if one element in the single_values sequence includes different data from the fourth element, 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 the fourth elements can form a target set (target_set). The target_set is not limited to be used in the case that the N data includes both the first data and the second data, and can exist even in the case that each of the N data is the first data suitable for RLE as described above. The reason is that the data amount of the target_set is small, and generally far less than the data amount of the single_values sequence and the data amount of the repeated_counts sequence, so that even if the target_set is added, it will not cause too large and unacceptable impact on the total data amount of the encoding result.

[0098] Exemplarily, 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 continuous occurrence number of the second data, without the need to add other elements in the repeated_counts sequence to represent the continuous occurrence number of the second data. That is, the repeated_counts sequence can only include the second element representing the continuous occurrence number of the first data.

[0099] Next, the encoding process performed by the encoder will be described in combination with the following Figure 3 and Figure 4 The encoding process performed by the encoder will be described in combination with the following

[0100] As Figure 3As shown, after all the data to be encoded is input into the encoder, the encoder samples all the data to be encoded to obtain N data. Then, each data in the N data is traversed, and whether the data is suitable for RLE is determined by the reference threshold corresponding to the data. If the data is the first data suitable for RLE, the data is added to the target_set to obtain the fourth element in the target_set. If the data is the second data unsuitable for RLE, the data is not added to the target_set. Exemplarily, after the traversal ends, the encoder can perform merging and deduplication on the fourth elements in the target_set to avoid redundant fourth elements in the target_set.

[0101] Next, as shown in FIG. 3, the traversal is performed again from the first data in all the data to be encoded. For a data, if the data belongs to the target_set, or the target_set has the fourth element determined based on the data, the data is subjected to RLE until another data with a different value is traversed. In the process of 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 the target_set does not have the fourth element determined based on the data, only the single_values sequence is updated 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 ends, the encoder obtains an encoding result including the target_set, the single_values sequence, and the repeated_counts sequence. Figure 4 For example, the N data is [AAAABBBCCDEEEEAA], A and E are the first data suitable for RLE, B, C, D, and E are the second data unsuitable for RLE, and the encoding result includes:

[0102] The target_set includes {AE}, “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.

[0103]

[0104] ​The single_values sequence includes [ABBBCCDEA], "A" is a first element determined based on the first data A, "B" is a third element determined based on the second data B, "C" is a third element determined based on the second data C, "D" is a third element determined based on the second data D, and "E" is a first element determined based on the first data E;

[0105] The repeated_counts sequence includes

[442] , the first 4 is the number of consecutive occurrences of the first data A when the first data A appears for the first time in the N data, the second 4 is the number of consecutive occurrences of the first data E when the first data E appears in the N data, and 2 is the number of consecutive occurrences of the first data A when the first data A appears for the second time in the N data.

[0106] Alternatively, the encoding result can not include the third element and the fourth element based on the first element and the second element, but also includes 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 manner of the second data and the first data in the N data.

[0107] The manner of determining the fifth element based on the second data can refer to the manner of determining the third element based on the second data in the foregoing description, which will not be repeated here. Moreover, the fifth element and the first element can be independent of each other, and are not arranged according to the arrangement manner of the second data and the first data in the N data, so that the fifth element and the first element cannot naturally reflect the arrangement manner of the second data and the first data in the N data, and thus the sixth element needs to be additionally used to indicate the arrangement manner of the second data and the first data in the N data.

[0108] The application does not limit the indication manner of the sixth element to the arrangement manner. For example, when the sixth element includes a first identifier, it represents that 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, it represents that 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, it represents that the arrangement manner of the second data included in the fifth element and the first data included in the first element is that they are interlaced according to a specified manner. The encoder can query the correspondence between the identifier and the arrangement manner according to the identifier included in the sixth element, so as to obtain the arrangement manner of the second data and the first data in the N data corresponding to the identifier.

[0109] In the encoding process performed by the encoder, after all the data to be encoded is input into the encoder, the encoder samples all the data to be encoded to obtain N data. Then, each of the N data is traversed to determine, by a reference threshold corresponding to each data, first data suitable for RLE and second data unsuitable for RLE, and to determine a sixth element according to an arrangement of the second data and the first data in the N data. Subsequently, the traversal is performed again 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 another data with a different value is traversed. In the process of RLE on the data, the single_values sequence and the repeated_counts sequence are updated according to the data to obtain a first element in the single_values sequence and a second element in the repeated_counts sequence. If the data belongs to the third element unsuitable for RLE, the data is not subjected to RLE, but a fifth element is obtained according to the data. After the traversal is completed, the encoder can obtain an encoding result, which includes the single_values sequence, the repeated_counts sequence, a sequence including all the fifth elements, and the sixth element.

[0110] For example, the N data is [AAAAAABBB], A is the first data suitable for RLE, and B is the second data unsuitable for RLE. In the encoding result, the single_values sequence includes [A], A is the first element determined based on the first data A; the repeated_counts sequence includes [6], 6 is the number of consecutive occurrences of the first data A; the sequence including all the fifth elements is [BBB], B is the fifth element determined based on the second data B; and the sixth element is the first identifier, representing that the second data included in the fifth element are all arranged after the first data included in the first element.

[0111] The single_values sequence includes [A], A is the first element determined based on the first data A;

[0112] The repeated_counts sequence includes [6], 6 is the number of consecutive occurrences of the first data A;

[0113] The sequence including all the fifth elements is [BBB], B is the fifth element determined based on the second data B;

[0114] The sixth element is the first identifier, representing 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 for determining whether the data is suitable for RLE is described. The reference threshold is determined based on N, the bits occupied by the first element, and the bits occupied by the second element. The embodiments of the present application do not limit the manner 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, the calculation complexity of the reference threshold is low regardless of how the reference threshold is determined based on these constants.

[0116] In some embodiments, the reference threshold is determined based on the ratio of a first value to a second value, the first value being the product of the bits occupied by the second element and N, and the second value being the sum of the bits occupied by the first element and the bits occupied by the second element. The reference threshold determined based on the ratio of the first value to the second value can mean that the ratio of the first value to the second value is taken as the reference threshold, or that a modified result obtained by modifying the ratio of the first value to the second value is taken as the reference threshold. The modification is to improve the accuracy of the reference threshold. For example, when modifying, a modification coefficient can be obtained according to experience or other possible ways, and the ratio of the first value to the second value and the modification coefficient are calculated to obtain the modified result.

[0117] Taking the ratio of the first value to the second value as the reference threshold as an example, for each kind of data in the N data, if the frequency of the kind of data in the N data satisfies the following formula (1), the kind of data is considered to be the first data suitable for RLE, and if the frequency of the kind of data in the N data does not satisfy the following formula (1), the kind of data is considered to be the second data unsuitable for RLE:

[0118]

[0119] In formula (1), N i represents the frequency of a kind of data V i in the N data, s i represents the bits occupied by the first element determined based on V i , and s r represents the bits occupied by the second element.

[0120] In some other embodiments, the reference threshold is determined based on a ratio of a first value and a second value, and the determination manner is described above and will not be repeated here. The first value is a product of the bits occupied by the second element and N, and the second value is the bits occupied by the first element. This manner is suitable for the case that the bits occupied by the first element is 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, and thus the bits occupied by the second element can be directly ignored.

[0121] Taking the ratio of the first value and the second value as the reference threshold as an example, for each data in the N data, if the frequency of the data in the N data satisfies the following formula (2), the data is considered to be the first data suitable for RLE, and if the frequency of the data in the N data does not satisfy the following formula (2), the data is considered to be the second data unsuitable for RLE:

[0122]

[0123] It can be seen that formula (2) can be considered as a simplified form of formula (1), and the simplification is beneficial to reduce the calculation complexity, thereby reducing the calculation overhead in the encoding process and improving the encoding efficiency. The formula (1) is a formula with theoretical support and obtained through a strict derivation process, and the derivation process will be described below and will not be repeated here.

[0124] Taking the determination of whether the data is suitable for RLE according to formula (1) as an example, if N 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 is regarded as a sequence, and two sequences with a length of 10000 are defined, i.e. sequence A and sequence B with N being 10000. In sequence A, the values of 8000 random positions are 1, and the values of the remaining 2000 positions are 0, so the data with a value of 1 in sequence A is exactly suitable for RLE and 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 in sequence A, and the value of the selected data is replaced by 0 to obtain sequence B, so the data with a value of 1 in sequence B is exactly not suitable for RLE and the data with a value of 0 is also not suitable for RLE. Therefore, if the data suitable for RLE is subjected to RLE, the data amount of the encoding result corresponding to sequence A is less than the data amount of the encoding result corresponding to sequence B, and also less than the data amount of sequence A itself.

[0125] Next, the process of applying the encoding method provided by the embodiments of the present application to various service scenarios is illustrated by examples. As mentioned above, the data amount of target_set is much smaller than the data amount of single_values sequence and the data amount of repeated_counts sequence, thus in the following examples, the data amount of the encoding result is calculated without considering the data amount of target_set.

[0126] In example one, in the service scenario of image compression, the image conforming to the international telecommunication union (ITU) or international organization for standardization (ISO) standard can be encoded by RLE, so as to realize image compression. The image conforming to the ITU or ISO standard includes but is not limited to the following formats: joint photographic experts group (JPEG), tag image file format (TIFF), bitmap (BMP) and PC paintbrush exchange (PCX), and PC paintbrush is a kind of software.

[0127] As shown in Figure 5 , an image includes 10 pixels, each pixel corresponds to three color channels of red (R), green (G) and blue (B), thus the 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 each data sequence is encoded by the encoding method provided by the embodiments of the present application. Since a pixel has any value from 0 to 255 in a color channel, each data is stored by fixed bit width, each data occupies 8 bits, each data sequence occupies 80 bits, that is, s i = 8, and s r = 8 is set.

[0128] The data in the data sequence corresponding to R is not suitable for RLE, and thus 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, only the single_values sequence is added with a comma for the convenience of distinguishing different data, and the comma is not a separator that needs to occupy bits. Therefore, after compression of the data sequence corresponding to R, the encoding result occupies 80 bits, which is the same as the 80 bits occupied before compression, and no degradation occurs.

[0129] The data with a value of 255 in the data sequence corresponding to G is suitable for RLE, and the data with other values is not suitable for RLE, and thus the target_set in the encoding result is {255}, the single_values sequence is [0, 50, 255, 125, 150, 255], and the repeated_counts sequence is

[24] . The comma in the single_values sequence is not a separator that needs to occupy bits. Therefore, after compression of 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] The data with each value in the data sequence corresponding to B is suitable for RLE, and thus 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 comma in the single_values sequence is not a separator that needs to occupy bits. Therefore, after compression of 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] As can be seen, in the case of fixed bit width storage s i = 8 and s r = 8, the bits occupied after compression are not more than the bits occupied before compression for each data sequence corresponding to a color channel.

[0132] In Example Two, in the business scenario of a database, the data stored in the database can be subjected to RLE to achieve data compression. The database includes, but is not limited to, the following several types: MongoDB, InfluxDB, and TimescaleDB (all are names of databases).

[0133] As Figure 6As shown, the database stores data in the form of a table, which is divided by columns to obtain data sequences corresponding to source internet protocol (IP) addresses, data sequences corresponding to destination IP addresses, and data sequences corresponding to protocol types, including user datagram protocol (UDP) and transmission control protocol (TCP). Of course, the source IP addresses, the destination IP addresses, and the protocol types are merely examples, and data sequences corresponding to features such as port numbers and application types can also be included. Each data sequence includes 10 data, each of which is stored using 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 the different data have a separator occupying 8 bits therebetween. In addition, s r = 4.

[0134] The data sequence corresponding to the source IP occupies 1152 (112*5+104*5+9*8) bits, and both "139.247.157.67" and "55.102.24.208" are suitable for RLE. The encoding result includes a target_set of {139.247.157.67, 55.102.24.208}, a single_values sequence of [139.247.157.67, 55.102.24.208], and a repeated_counts sequence of

[55] . The "," in the single_values sequence is a separator that needs to occupy bits. Therefore, the encoding result obtained 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, and both "10.0.5.22" and "10.255.8.13" are suitable for RLE. The encoding result includes a target_set of {10.0.5.22, 10.255.8.13}, a single_values sequence of [10.0.5.22, 10.255.8.13, 10.0.5.22], and a repeated_counts sequence of

[352] . The "," in the single_values sequence is a separator that needs to occupy bits. Therefore, the encoding result obtained 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 encoded result includes target_set of {UDP, TCP}, single_values ​​sequence of [UDP, TCP], and repeated_counts sequence of

[55] . The comma in the single_values ​​sequence is a separator that requires bits. Therefore, the encoded result after compression occupies 64 (3*8*1+3*8*1+1*8+2*4) bits, which is less than the 312 bits occupied before compression.

[0137] Therefore, it can be seen that in s i Uses variable bit width storage and s r When the value is 4, for the data sequence corresponding to each column, the number of bits occupied after compression is less than the number of bits occupied before compression.

[0138] In Example 3, in a communication service scenario, RLE can be applied to signals of various formats, such as analog television signals, fax signals, and digital signals, to facilitate transmission during communication.

[0139] like Figure 7 As shown, the binary signal to be transmitted is: 00000000 00000000 00000000 000001000000000 00000000 00000000 00000111 00000000 00010000 00000000 00000000. Each data point is stored with a fixed bit width, occupying 1 bit, i.e., s i =1, dividing the binary signal into three groups, each group corresponding to a data sequence occupying 32 bits. Additionally, s is set... r =8. In each corresponding data sequence, data 0 is suitable for RLE, while data 1 is not suitable for RLE.

[0140] In the first set of corresponding data sequences, the encoded result includes a target_set of {0}, a single_values ​​sequence of [0, 1, 0], and a repeated_counts sequence of [29, 2]. The commas in both the single_values ​​and repeated_counts sequences are not delimiters that require bits. Therefore, the compressed encoded result occupies 19 (3*1 + 2*8) bits, less than the 32 bits occupied before compression.

[0141] In the data sequence corresponding to the third group, the target_set included in the encoding result is {0}, the single_values sequence is [0, 1, 0], and the repeated_counts sequence is [11, 20]. Neither of the "," in the single_values sequence and the repeated_counts sequence is a separator that needs to occupy bits. Therefore, after compression, 19 (3*1+2*8) bits are occupied, which is less than the 32 bits occupied before compression.

[0142] In the data sequence corresponding to the third group, the target_set included in the encoding result is {0}, the single_values sequence is [0, 1, 0], and the repeated_counts sequence is [11, 20]. Neither of the "," in the single_values sequence and the repeated_counts sequence is a separator that needs to occupy bits. Therefore, after compression, 19 (3*1+2*8) bits are occupied, which is less than the 32 bits occupied before compression.

[0143] As can be seen, in the fixed bit-width storage s i = 1 and s r = 8, for the data sequence corresponding to each group, the bits occupied after compression are less than the bits occupied before compression.

[0144] In summary, the embodiments of the present application determine the first data suitable for RLE from N data based on the reference threshold. Thus, RLE is performed on the first data suitable for RLE, and RLE is not performed on the data unsuitable for RLE, thereby realizing reasonable and selective RLE and avoiding unnecessary encoding overhead.

[0145] 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, the reference threshold has theoretical support and low computational complexity, and the first data suitable for RLE can be quickly and accurately determined based on the reference threshold. Thus, not only is degradation avoided after RLE, but computational overhead is also reduced, and encoding efficiency is improved.

[0146] In addition, by using the encoding method shown in the above Figure 2 , an encoding result can be obtained. In this regard, the embodiments of the present application also provide a decoding method shown in the above Figure 8 , which is used to decode the encoding result. The decoding method can be applied to the encoding method shown in the above Figure 1The software 101 is deployed in the product 102. In the embodiments of the present application, the encoding method and the decoding method can be applied to the same software or different software. In the case of applying to different software, the different software can be deployed in the same product or different products. See Figure 8 The decoding method includes the following steps 801 and 802.

[0147] Step 801, obtaining an encoding result, the encoding result being obtained by performing RLE on a first data in N data included in a data set, N being greater than or equal to 2.

[0148] The first data appears in the N data with a frequency greater than or equal to a reference threshold, the reference threshold being determined based on N, bits occupied by a first element and bits occupied by a second element, the first element being determined based on the first data, and the second element being a number of consecutive appearances of the first data.

[0149] For example, the bits occupied by the second element are 2 bits, and M is greater than or equal to 1. M

[0150] In the exemplary embodiments, the reference threshold is determined based on a ratio of a first value to a second value, the first value being a product of the bits occupied by the second element and N, and the second value being a sum of the bits occupied by the first element and the bits occupied by the second element.

[0151] The content involved in step 801 can refer to the description in steps 201 and 202 above, which will not be repeated here.

[0152] Step 802, decoding the encoding result.

[0153] In some embodiments, each data in the N data is the first data suitable for RLE, and the encoding result only includes the corresponding first element and the 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 appearances of the first data, in the decoding process, the single_values sequence can be traversed, and for each first data included in the first element, the first data is continuously output according to the number of consecutive appearances represented by the second element corresponding to the first element in the repeated_counts sequence, such as 5 consecutive appearances, then 5 first data are continuously output, so as to obtain the decoding result.

[0154] ​In some embodiments, the encoding result is further obtained by encoding second data of the N data other than the first data, the encoding result comprises a first element, a second element, a third element and a fourth element, the third element is determined based on the second data, the third element and the first element are arranged in the same way as 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 in the single_values sequence, and the fourth element is in the target_set. Accordingly, decoding the encoding result comprises decoding the first element and the third element according to the second element and the fourth element.

[0155] In the following, the decoding process performed by the decoder will be illustrated with reference to the following examples. Figure 9 The decoding process performed by the decoder will be illustrated with reference to the following examples.

[0156] As shown in the following table, the decoder receives the encoding result, scans the single_values sequence, and traverses the single_values sequence from the first element of the single_values sequence. If an element includes the same data as the fourth element of the target_set, the element is determined as the first element, and the data included in the first element is the first data suitable for RLE. Thus, the first data is outputted continuously according to the consecutive occurrence number represented by the first second element of the repeated_counts sequence, and then the first second element of the repeated_counts sequence is deleted. If an element includes different data from the fourth element of the target_set, the element is determined as the third element, and the data included in the third element is the second data unsuitable for RLE. Thus, the second data included in the third element is outputted directly. After the traversal is completed, the decoding result is obtained and outputted. Figure 9 For example, in the encoding result, the target_set comprises {AE}, the single_values sequence comprises [ABBBCCDEA], and the repeated_counts sequence comprises

[442] . In the decoding process, the single_values sequence is scanned, A is in the target_set, and A is outputted four times according to the first 4 in the repeated_counts sequence, and the first 4 in the repeated_counts sequence is deleted, and the updated repeated_counts sequence is

[42] .

[0157]

[0158]

[0159] ​​Continuing to scan the single_values sequence, since B, C and D are not in the target_set, they are output directly, resulting in the sequence [AAAABBBCCD];

[0160] Continuing to scan the single_values sequence, since E is in the target_set, it is output four times according to the first 4 in the updated repeated_counts sequence

[42] , resulting in the sequence [AAAABBBCCDEEEE], and the first 4 in the updated repeated_counts sequence

[42] is deleted, resulting in the twice-updated repeated_counts sequence [2];

[0161] Continuing to scan the single_values sequence, since A is in the target_set, it is output twice according to the first 2 in the twice-updated repeated_counts sequence [2], resulting in the sequence [AAAABBBCCDEEEEAA], and 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 yet some embodiments, the encoding result is further obtained by encoding a second data of the N data other than the first data, the encoding result comprising a first element, a second element, a fifth element and a sixth element, the fifth element being determined based on the second data, and the sixth element being used to indicate an arrangement manner 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 comprises: decoding the first element and the fifth element according to the second element and the sixth element.

[0163] wherein, after the decoder receives the encoding result, the single_values sequence in the encoding result is scanned, and the first element of the single_values sequence is traversed, and the first data included in the first element is output continuously according to the continuous appearance times 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, and the first decoding result is obtained after the traversal. In addition, the fifth element is scanned and the second data included in the fifth element is output directly, obtaining the second decoding result. Then, the first decoding result and the second decoding result are arranged according to the arrangement manner of the second data and the first data in the N data indicated by the sixth element, obtaining 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 are all arranged after the first data. In the decoding process:

[0165] The single_values sequence is scanned, A is outputted continuously for 6 times according to the first 6 in the repeated_counts sequence, so that the first decoding result [AAAAAA] is obtained, and the first 6 in the repeated_counts sequence is deleted;

[0166] The sequence including all fifth elements is scanned, and the second decoding result [BBB] is obtained;

[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 by the embodiment of the application can decode the encoding result, and realizes lossless restoration of data. The encoding result is obtained based on the encoding method shown in the Figure 2 The technical effects of the encoding result can be referred to the description of the encoding method, and will not be repeated here.

[0169] In the foregoing, the encoding method and the decoding method provided by the embodiment of the application are described respectively. Next, the derivation process of the formula (1) proposed in the foregoing is described.

[0170] Wherein, there are i kinds of different values of data in the N data, the i-th data V i The frequency of occurrence of the i-th data V i in the N data is N i The probability p i of the i-th data V i in the N data is N i / N, or N i =Np i If the data V i is RLE, the single_values sequence is generated, and the frequency of occurrence of V i is reduced by RLE, and the reduction is denoted as expectation It is expressed as formula (3) as follows:

[0171] The frequency of occurrence of the i-th data V i in the N data is N

[0172] Of course, in addition to the single_values ​​sequence, a repeated_counts sequence will also be generated, and both the single_values ​​and repeated_counts sequences contain the same number of elements. Therefore, the data V in the single_values ​​sequence... i The number of bits occupied by the corresponding element is denoted as s. i The data V in the repeated_counts sequence i The number of bits occupied by the corresponding element is denoted as s. r This makes the data V i The condition for no degradation after RLE is expressed by the following formula (4):

[0173]

[0174] In formula (4), Np i ·s i For data V i The number of bits occupied in N data points. V as described in formula (3) above 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 single_values ​​sequence.

[0175] If formula (4) is used directly, then it is necessary to... The solution is then performed. During the solution process, a complete Restricted Execution (RLE) is performed on the N data points to obtain a reference encoding result. This reference encoding result is then used to solve for V for each data type. i of Reuse For each type of data V i Calculate whether formula (4) holds true. If it does, then confirm the value of this data V. i If an RLE is not valid, then confirm the data V. i If RLE is not suitable, obtain confirmation. Then, perform RLE again based on the confirmation result. If a data V i If the confirmation result indicates that RLE is appropriate, then when performing RLE again, the data V should be processed. i Perform RLE if a data V i If the confirmation result indicates that RLE is not suitable, then this data V will not be used again when performing RLE again. i Perform RLE.

[0176] It can be seen that the above solution process requires two rounds of RLE, resulting in high encoding overhead, low encoding efficiency, and poor practicality. Moreover, the first complete RLE alone has a computational complexity of O(N), which is relatively high. Therefore, this application simplifies formula (4) to obtain formula (1) with a computational complexity of O(1), thereby obtaining an encoding method with lower computational complexity. This makes the encoding method applicable to fields such as information and communications technology (ICT), which require encoding massive amounts of data with low overhead.

[0177] According to the pigeonhole principle, a lossless compression algorithm that never degrades on any data distribution may not exist. Therefore, it is necessary to make assumptions about the data distribution of the data to be encoded based on the business scenario. Analysis shows that in business scenarios such as image compression, databases, and communications, the data to be encoded generally conforms to an independent and identically distributed (I / O) distribution. Therefore, it can be assumed that the data distribution is I / O. Furthermore, the data V... i The probability p of appearing in N data points i It could be an observation. To avoid random errors causing the observation to deviate too much from the true value, we can further assume that the amount of data to be encoded is large enough.

[0178] Based on this, a reference sequence is defined, which includes exactly n data V. i Or, in other words, data V i The consecutive occurrences of a given sequence are exactly n. When scanning N data points from beginning to end, the expected number of times this reference sequence appears is denoted as E. For example... Figure 10 As shown, in N data points, the position of the reference sequence can be divided into three categories: head, middle, and tail. This is easy to understand. Figure 10 The example uses a value of 4 for n, and a "single slash" indicates that the reference sequence includes data V. i The "cross line" indicates the relationship with data V. i Other data with different values. Under the assumption of independent and identically distributed distribution as explained above, p i Equal to data V i The probability of the reference sequence appearing at any position in N data points is expressed by the following formula (5), and the expected number of times the reference sequence appears at the head or tail is expressed by the following formula (6):

[0179] E = (1-p) i )p i n Formula (5)

[0180] E = (1-p) i )p i n (1-p i )(Nn-1) Formula (6)

[0181] If n ≤ N-2, the reference sequence may appear at the head, middle, and tail positions. If n = N-1, the reference sequence may appear at the head or tail position, and the expected exponent E is (1-p) / (1-p). i )p i N-1 If n = N, then all N data points are of the same type, V. i The expected number of times E is p i N .

[0182] For a dataset V containing n data points i After performing RLE on the reference sequence, the data V in the single_values ​​sequence i The number of corresponding elements Q, and the data V in the repeated_counts sequence. i The number of corresponding elements Q is expressed as in the following formula (7), where the symbol in formula (7) is the floor function:

[0183]

[0184] Furthermore, among the Q elements in the repeated_counts sequence, one element has a value (n modulo 1). )-1, mod is the modulo operator, (n mod 1) ) means n divided by The remainder is obtained, and the values ​​of the remaining elements are...

[0185] Therefore, each time the reference sequence appears, for The resulting contribution W is expressed as follows (8):

[0186]

[0187] Based on the above derivation, the following formula (9) can be obtained:

[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, it is necessary to continue to simplify formula (11).

[0194] Combining Figure 11 It can be seen that -∈1When N is small, it has shown a clear trend of convergence, there is a convergence value, so as to find the function for approximation of the convergence value. Among them, according to the following formula (12) and formula (13) to define two constants:

[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] In the case, there is the following formula (15) :

[0200]

[0201] According to the following formula (16) to define the error term ∈2:

[0202]

[0203] Then formula (14) can be expressed as the following formula (17) :

[0204]

[0205] In the case, the value of the item with the ceiling symbol in the above formula (15) is always 1, there is no error, so no special treatment is needed.

[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), according to the summation formula of geometric progression, the following formula (18) is obtained, and combined with formula (19), Lemma 1 is obtained as formula (20), wherein s.t. in formula (19) means subject to:

[0208]

[0209]

[0210]

[0211] In Lemma 2, when a∈(0, 1), the equal sign on both sides of Lemma 1 is simultaneously differentiated with respect to a, the following formula (21) is obtained, and thus Lemma 2 is obtained as formula (22) from formula (21):

[0212]

[0213]

[0214] In Lemma 3, when a∈(0, 1), the equal sign on both sides of Lemma 2 is simultaneously differentiated with respect to a, the following formula (23) is obtained, and multiplying a on both sides of formula (23) obtains Lemma 3 as formula (24):

[0215]

[0216]

[0217] Since N is large enough, according to Lemmas 1, 2 and 3 (p i That is, a in these lemmas), the summation symbol in formula (17) is replaced by the convergence value of the infinite series, and thus (i.e., the replacement process) introduces error term ∈3, and formula (17) can be simplified as the following formula (25):

[0218]

[0219] Wherein, the error terms ∈1, ∈2 and ∈3 are ignored, and formula (12) and formula (13) in the above are substituted into formula (25), so that the following formula (26) is obtained:

[0220]

[0221] In the embodiments of the present application, the error terms ∈1, ∈2 and ∈3 can be ignored for the following reasons.

[0222] First, for error term ∈1, when N>0 and p i<1 (because p i =1, N data are all the same kind of data, RLE can be directly performed without analysis), the following formula (27) is monotonically increasing:

[0223]

[0224] Therefore, there is the following formula (28):

[0225]

[0226] And, p i <1, because Np i is always an integer, so there are N-Np i ≥1, there is the following formula (29):

[0227]

[0228] Then, it can be concluded that ∈1∈(0, 1]<<N, so ∈1can be ignored.

[0229] Second, for the error term ∈2, based on formula (16), combined with the above lemma 1, lemma 2 and lemma 3, the following formula (30) is obtained:

[0230]

[0231] Therefore, formula (30) is a constant, also a constant, the impact of ∈2 is mainly related to s r , the greater s r , the smaller the impact of ∈2. Combined with (1) in Figure 12 , when s r =8 (i.e. one byte), the impact of ∈2 almost disappears because the coincidence degree of solid line and dashed line in (1) is very high. Combined with (2) in Figure 12 , when s r =4 (i.e. half a byte), the impact of ∈2 is also very small (which can be observed when p i >0.8), because the coincidence degree of solid line and dashed line in (2) is also relatively high. It is because the impact of s r is very small that ∈2 can be directly ignored.

[0232] Third, for the error term ∈3 which is difficult to quantify, because has obvious convergence trend when N is small, and N is often large, so the ∈3 brought by substituting the summation symbol with the convergence value of infinite series can also be ignored.

[0233] In this embodiment of the application, an experiment was conducted to further demonstrate that the above three error terms can be ignored. In the experiment, with N taking values ​​of 1024, 2048, and 4096 (a total of three possible values ​​for N), the following conditions were met for p... i The values ​​are 0%, 5%, ..., 95% (p i There are 20 possible values ​​in total, and data is randomly selected from N data points to replace the values ​​occupying s. i Data V (number of bits) i (Data V) i The value of is different from the values ​​of the data included in N data points. Next, set s r And using RLE for encoding, then for each group of s i and s r A total of 60 (3*20) data points were obtained. For each data point, the uncompressed data V was... i Occupied bits (i.e., NP in formula (4)) i ·s i ) and compressed data V i Occupied bits (i.e., in formula (4)) By comparing the data, the value of V can be calculated. i The space saved by performing RLE, i.e., the data V before compression. i Bits occupied - Compressed data V i The number of bits occupied, when the space is positive, allows for Restricted Execution (RLE) to prevent degradation.

[0234] like Figure 13 As shown, Figure 13 Each group of s is shown i and s r The corresponding measured results and the results calculated according to formula (26). Figure 13 Of the eight coordinate systems, the coordinate system s located in the first column is... r =4, coordinate system s located in the second column r =8, coordinate system s located in the first row i =1, coordinate system s located in the second row i =2, coordinate system s located in the third row i =3, coordinate system s located in the fourth row i =4. And, in Figure 13 In each coordinate system, the vertical axis represents the space saved, and the horizontal axis represents the data V before compression. iThe occupied bits, the magnitude of the longitudinal axis and the transverse axis of different coordinate systems can be slightly different, the discrete points are all measured results, the continuous lines are all results calculated according to formula (26), and the three lines in each coordinate system correspond to the value of N being 1024, 2048 and 4096 from left to right. It can be easily seen that in each group of s i and s r , the measured results and the results calculated according to formula (26) are fully consistent, thereby verifying the correctness and usability of formula (26).

[0235] Further, compared with the related art in which s r is often set to a larger value such as 8 bits, 24 bits and the like, the embodiments of the present application reversely select to set s r to a smaller value such as 4 bits, thereby ensuring more space to be saved when performing RLE on data, because the saved space is negatively correlated with the value of s r , and the reason is as follows.

[0236] By substituting formula (26) into formula (4), the following formula (31) can be obtained:

[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, Np i -(N-1)p i 2 ≥ 0, so it can be concluded that within the allowable range of error, the saved space is negatively correlated with the value of s r .

[0239] Furthermore, we can further transform formula (31) to obtain formula (32) as follows:

[0240]

[0241] Since N is large enough, N-1≈N≈N+1, so formula (32) can be further simplified to the following formula (33):

[0242]

[0243] Thus, the derivation process is complete, and the above formula (1) is obtained.

[0244] The above describes the encoding method provided by the embodiments of this application. Corresponding to the above method, the embodiments of this application also provide an encoding device. This device is used to encode... Figure 14 Each module shown performs the above... Figure 2 The encoding method shown. For example... Figure 14 As shown, the encoding device provided in this application embodiment includes the following modules.

[0245] Module 1401 is used to acquire a data set, which includes N data points, where N is greater than or equal to 2.

[0246] Encoding module 1402 is used to perform RLE on the first data if the frequency of the first data in N data is greater than or equal to a reference threshold.

[0247] The reference threshold is determined based on N, the number of bits occupied by the first element, and the number of 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 one possible implementation, the reference threshold is determined based on the ratio of a first value to a second value, where 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.

[0249] In one possible implementation, the encoding module 1402 is further used to encode the second data other than the first data in 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 further 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 1 bit, M is greater than or equal to 1.

[0252] This application embodiment also provides a decoding device, which is used for decoding... Figure 15 Each module shown performs the above... Figure 8 The decoding method is shown. For example... Figure 15 As shown, the decoding device provided in this application embodiment includes the following modules.

[0253] The acquisition module 1501 is used to acquire the encoding result. The encoding result is obtained by performing RLE on the first data in the N data included in the data set. N is greater than or equal to 2. The frequency 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 number of bits occupied by the first element and the number of 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.

[0254] Decoding module 1502 is used to decode the encoded result.

[0255] In one possible implementation, the reference threshold is determined based on the ratio of a first value to a second value, where 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.

[0256] In one possible implementation, the encoding result is further obtained by encoding the second data (excluding the first data) among 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 among the N data. 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 based on the second element and the fourth element.

[0257] In one possible implementation, the encoding result is also obtained by encoding the second data other than the first data in N first data. 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 based on the second element and the sixth element.

[0258] In one possible implementation, the second element occupies 2 bits. M 1 bit, M is greater than or equal to 1.

[0259] The above Figure 14 The device shown, in performing its function, possesses beneficial effects and Figure 2 The encoding methods shown above have the same beneficial effects. Figure 15 The device shown, in performing its function, possesses beneficial effects and Figure 8 The decoding method shown has the same beneficial effects. Figure 14 and Figure 15 The provided device, in implementing its functions, is only illustrated by the division of the above-described functional modules. In practical applications, the functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. Furthermore, the device and method embodiments provided in the above embodiments belong to the same concept, and their specific implementation processes are detailed in the method embodiments, and will not be repeated here.

[0260] See Figure 16 , Figure 16 A schematic diagram of the structure of an exemplary computer device 1600 of this 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 unit (NPU), a data processing unit (DPU), a microprocessor, or one or more integrated circuits or application-specific integrated circuits (ASICs), programmable logic devices (PLDs), other general-purpose processors or other programmable logic devices, discrete gates, transistor logic devices, discrete hardware components, or any combination thereof used to implement the scheme of this application. A PLD is, for example, a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), generic array logic (GAL), or any combination thereof. A general-purpose processor can be a microprocessor or any conventional processor. It is worth noting that the processor can be a processor supporting an advanced reduced instruction set machine (RISC) machine (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, etc.

[0262] Optionally, the computer device 1600 also includes a bus 1602. The bus 1602 is used to transmit information between the various components of the computer device 1600. The bus 1602 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus 1602 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 16 The symbol is represented by only one line, but this does not mean that there is only one bus or one type of bus.

[0263] The memory 1603 may be, for example, volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. The non-volatile memory may be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. The volatile memory may be 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 random access memory (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 linked dynamic random access memory (SLDRAM), and direct rambus RAM (DR RAM).

[0265] The memory 1603 can also be other types of storage devices capable of storing static information and instructions. Alternatively, it can be other types of dynamic storage devices capable of storing information and instructions. It can also be other optical disc storage, optical disk storage (including compressed optical discs, laser discs, optical discs, digital versatile optical discs, Blu-ray discs, etc.), magnetic disk storage media, or other magnetic storage devices, or any other medium capable of carrying or storing desired program code in the form of instructions or data structures that can be accessed by a computer, but is not limited thereto. The memory 1603 may exist independently, for example, and be connected to the processor 1601 via bus 1602. The memory 1603 may also be integrated with the processor 1601.

[0266] Network interface 1604 uses any transceiver-like device for communicating with other devices or communication networks, such as Ethernet, radio access network (RAN), or wireless local area network (WLAN). Network interface 1604 may include wired network interfaces and wireless network interfaces. Specifically, network interface 1604 can be an Ethernet interface, such as Fast Ethernet (FE), Gigabit Ethernet (GE), Asynchronous Transfer Mode (ATM), WLAN, cellular network, or combinations thereof. The Ethernet interface can be an optical interface, an electrical interface, or a combination thereof. In some embodiments of this application, network interface 1604 can be used for computer device 1600 to communicate with other devices.

[0267] In specific implementations, as some embodiments, the processor 1601 may include one or more CPUs, such as Figure 16 The CPU0 and CPU1 shown are examples of processors. Each of these processors can be a single-core processor or a multi-core processor. A processor here can refer to one or more devices, circuits, and / or processing cores used to process data (e.g., computer program instructions).

[0268] In specific implementations, as some methods, the computer device 1600 may include multiple processors, such as... Figure 16 The processors 1601 and 1605 are shown. Each of these processors may be a single-core processor or a multi-core processor. Here, "processor" may refer to one or more devices, circuits, and / or processing cores used to process data (such as computer program instructions).

[0269] In some embodiments, memory 1603 is used to store program instructions 1610 for executing the scheme of this application, and processor 1601 can execute the program instructions 1610 stored in memory 1603. That is, computer device 1600 can implement the method provided in the method embodiment through processor 1601 and program instructions 1610 in memory 1603, i.e. Figure 2 The encoding method shown or Figure 8 The decoding method is shown. Program instructions 1610 may include one or more software modules. Optionally, processor 1601 itself may also store program instructions for executing the scheme of this application.

[0270] In specific implementation, the computer device 1600 of this application can correspond to a product for performing the above-described method, such as an encoder or decoder. The processor 1601 in the computer device 1600 reads instructions from the memory 1603, causing... Figure 16 The computer device 1600 shown is capable of performing all or part of the steps in the method embodiments.

[0271] Computer device 1600 can also correspond to the above. Figure 14 or Figure 15 The device shown, Figure 14 or Figure 15 Each functional module in the illustrated device is implemented using software from computer device 1600. In other words, Figure 14 or Figure 15 The device shown includes functional modules generated by the processor 1601 of the computer device 1600 after reading the program instructions 1610 stored in the memory 1603.

[0272] in, Figure 2 or Figure 8 Each step of the method shown is implemented through integrated logic circuits in the hardware of the processor of the computer device 1600 or through instructions in the form of software. The steps of the method embodiments disclosed in this application can be directly implemented by the hardware processor, or implemented by a combination of hardware and software modules in the processor. The software modules can reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other storage media mature in the art. Since this storage medium is located in memory, the processor reads information from the memory and, in conjunction with its hardware, completes the steps of the above method embodiments; to avoid repetition, they will not be described in detail here.

[0273] This 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 to enable the computer device to perform the above-described functions. Figure 2 The encoding method shown or Figure 8 The decoding method shown.

[0274] This application provides an encoding / decoding system, which includes an encoder and a decoder, wherein the encoder is used to perform the above-described encoding / decoding operation. Figure 2 The encoding method shown is used by the decoder to perform the above. Figure 8 The decoding method shown.

[0275] For example, embodiments of this application provide a computer program or computer program product, which includes: computer instructions, which, when executed by a computer, cause the computer to perform the above-described... Figure 2The encoding method shown or Figure 8 The decoding method shown.

[0276] This application provides a computer-readable storage medium that stores computer instructions. When the computer instructions are executed on a computer, the computer performs the above-described... Figure 2 The encoding method shown or Figure 8 The decoding method shown.

[0277] In an exemplary embodiment, this application provides a chip, including a processor, for calling and executing instructions stored in a memory, causing a computer equipped with the chip to perform the aforementioned operations. Figure 2 The encoding method shown or Figure 8 The decoding method shown.

[0278] This application also provides another chip, including: an input interface, an output interface, a processor, and a memory. The input interface, output interface, processor, and memory are connected through internal interconnection paths. The processor is used to execute code in the memory. When the code is executed, a computer with the chip installed performs the above-described actions. Figure 2 The encoding method shown or Figure 8 The decoding method shown.

[0279] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as 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, all or part of the processes or functions described in this application are generated. 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. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium accessible to a computer or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state disk).

[0280] In this application, the terms "first," "second," etc., are used to distinguish identical or similar items with substantially the same function. There is no logical or temporal dependency between "first," "second," and "nth," nor are they used to limit quantity or 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 merely used to distinguish one element from another.

[0281] It should also be understood that, in the various embodiments of this application, the sequence number of each process does not imply 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 this application.

[0282] In this application, the term "at least one" means one or more, and the term "multiple" means two or more; for example, multiple data refers to two or more data. The terms "system" and "network" are often used interchangeably in this document.

[0283] It should be understood that the terminology used in the description of the various examples herein is for the purpose of describing particular examples only and is not intended to be limiting. As used in the description of the various examples and the appended claims, the singular forms “a” 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" as used herein refers to and covers any and all possible combinations of one or more of the associated listed items. The term "and / or" describes an association between related objects, indicating that three relationships can exist; for example, A and / or B can represent: A alone, A and B simultaneously, or B alone. Additionally, the character " / " in this application generally indicates that the preceding and following related objects are in an "or" relationship.

[0285] It should also be understood that the terms “if” and “if” can be interpreted as meaning “when” or “upon”, or “in response to determination” or “in response to detection”. Similarly, depending on the context, the phrases “if determination…” or “if detection [the stated condition or event]” can be interpreted as meaning “when determination…”, or “in response to determination…”, or “when detection [the stated condition or event]” or “in response to detection [the stated condition or event]”.

[0286] The above description is merely an embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the principles of this application should be included within the protection scope of this application.

Claims

1. An encoding method, characterized in that, The method includes: Obtain a dataset, wherein the dataset includes N data points, and N is greater than or equal to 2; If the frequency of the first data in the N data is greater than or equal to the reference threshold, then the first data is run-length encoded (RLE). 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.

2. The method according to claim 1, characterized in that, The reference threshold is determined based on the ratio of a first value to a second value, where 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.

3. The method according to claim 1 or 2, characterized in that, The method further includes: Encode the second data among the N data excluding the first data to obtain the encoding result; 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. 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 includes: Encode the second data among the N data excluding the first data to obtain the encoding result; 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 among the N data.

5. The method according to any one of claims 1-4, characterized in that, The second element occupies 2 bits. M 1 bit, wherein M is greater than or equal to 1.

6. A decoding method, characterized in that, The method includes: Obtain the encoding result, which is obtained by performing run-length encoding (RLE) on the first data in the N data included in the data set, where N is greater than or equal to 2, the frequency 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. The encoded result is then decoded.

7. The method according to claim 6, characterized in that, The reference threshold is determined based on the ratio of a first value to a second value, where 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.

8. 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 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. The fourth element is determined based on the first data. Decoding the encoded result includes: The first element and the third element are decoded based on 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. Decoding the encoded result includes: The first element and the fifth element are decoded based on the second element and the sixth element.

10. The method according to any one of claims 6-9, characterized in that, The second element occupies 2 bits. M 1 bit, wherein M is greater than or equal to 1.

11. An encoding device, characterized in that, The device includes: An acquisition module is used to acquire a data set, the data set including N data items, where N is greater than or equal to 2; The encoding module is used to perform run-length encoding (RLE) on the first data if the frequency 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.

12. The apparatus according to claim 11, characterized in that, The reference threshold is determined based on the ratio of a first value to a second value, where 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.

13. The apparatus according to claim 11 or 12, characterized in that, The encoding module is also used to encode the second data among the N data, excluding the first data, to obtain an encoding result; 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. The fourth element is determined based on the first data.

14. The apparatus according to claim 11 or 12, characterized in that, The encoding module is also used to encode the second data among the N data, excluding the first data, to obtain an encoding result; 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 among the N data.

15. The apparatus according to any one of claims 11-14, characterized in that, The second element occupies 2 bits. M 1 bit, wherein M is greater than or equal to 1.

16. A decoding device, characterized in that, The device includes: The acquisition module is used to acquire the encoding result, which is obtained by performing run-length encoding (RLE) on the first data in N data included in the data set, where N is greater than or equal to 2, the frequency 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. A decoding module is used to decode the encoded result.

17. The apparatus according to claim 16, characterized in that, The reference threshold is determined based on the ratio of a first value to a second value, where 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.

18. The apparatus 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 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. The fourth element is determined based on the first data. The decoding module is used to decode the first element and the third element based on the second element and the fourth element.

19. The apparatus 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 based on the second element and the sixth element.

20. The apparatus according to any one of claims 16-19, characterized in that, The second element occupies 2 bits. M 1 bit, wherein 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, which is loaded and executed by the processor to enable the computer device to implement the encoding method of any one of claims 1-5 or the decoding method of 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, which is loaded and executed by a processor to enable a computer device to implement the encoding method of any one of claims 1-5 or the decoding method of any one of claims 6-10.

23. A computer program product, characterized in that, The computer program product includes computer instructions that are executed by a processor to cause a computer device to implement the encoding method of any one of claims 1-5 or the decoding method of any one of claims 6-10.

Citation Information

Patent Citations

  • Coding method and related equipment

    CN112398484A

  • Data compression method and device, equipment and storage medium

    CN116418348A