A new ANS encoding and decoding method, a computer device and a storage medium

By constructing a novel ANS encoding and decoding method using a symbol allocation list and a cumulative frequency table, the problem of ANS encoding being undecoding is solved, data compression performance is improved, and efficient data compression is achieved.

CN115776302BActive Publication Date: 2026-11-20SHANDONG YUNHAI GUOCHUANG CLOUD COMPUTING EQUIP IND INNOVATION CENT CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211186506.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-27
Publication Date
2026-11-20
Estimated Expiration
2042-09-27

AI Technical Summary

Technical Problem

Existing Huffman coding and arithmetic coding have shortcomings in compression ratio and coding efficiency in the field of data compression, and ANS coding cannot directly decode the original symbol sequence.

Method used

A novel ANS encoding and decoding method is proposed. By constructing a symbol allocation list Symbol[] and a cumulative frequency table count[], combined with a sequential cyclic allocation scheme, the encoding and decoding of symbol sequences are realized, ensuring that the encoded number uniquely corresponds to a symbol, and the decoding end can parse out the original sequence.

Benefits of technology

It improves data compression performance, achieving a compression ratio close to that of arithmetic coding and a coding efficiency close to that of Huffman coding, thus meeting the data compression requirements for real-time applications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115776302B_ABST
    Figure CN115776302B_ABST
Patent Text Reader

Abstract

The application provides a novel ANS encoding and decoding method, a computer device and a storage medium, and the method comprises an ANS encoding method and an ANS decoding method; in the encoding process, the probability of a symbol is counted, the probability is normalized, a probability distribution is obtained, and the probability distribution is encoded; a symbol allocation list Symbol[] is constructed; a cumulative frequency table count[] is constructed, cumulative frequencies are recorded, count[x+1] = count[x] + fx, a symbol position list Pos[] is constructed, and a fast search is used to find the index of each symbol in Symbol[]; and the symbol sequence is encoded in a natural order; in the decoding process, the probability distribution of each symbol set is decoded; the symbol allocation list Symbol[] is constructed, Symbol[] is consistent at both ends of the encoding / decoding, a symbol order table Sort[] is constructed, s = Symbol[i] is set, and the appearance frequency of s in the symbol list Symbol is represented by Sort[i]; and the data compression effect can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, specifically to a novel ANS encoding / decoding method, computer equipment, and storage medium. Background Technology

[0002] Entropy coding is a lossless data compression method. The core idea of ​​entropy coding is to achieve compression by using fewer bits to represent frequently occurring symbols and more bits to represent rarely occurring elements.

[0003] Huffman coding and arithmetic coding are two of the most common entropy coding methods. Huffman coding is an entropy coding technique developed by David A. Huffman. The algorithm of Huffman coding is simple, based on the probabilistic ordering of the symbol set to allocate the code length. Huffman coding always uses integer bits to represent a symbol, and it encodes each symbol individually. Therefore, Huffman coding cannot guarantee optimal compression performance. Huffman coding produces optimal results when the probabilities of all symbols are negative powers of 2. In Huffman coding, each occurrence of a symbol is always encoded with the same codeword. The advantage of Huffman coding is its fast coding speed.

[0004] According to information theory, the ideal codeword length of a single symbol is determined solely by the probability of the symbol's occurrence: code-length(x) = -log p(x) If the probability of a symbol occurring is 0.4, then the ideal codeword length is 1.32(-log₂). 0.4 Unfortunately, Huffman coding can only assign codewords of integer length. This is a major drawback of the Huffman coding algorithm.

[0005] Arithmetic coding addresses this limitation of Huffman coding; it's another entropy coding technique. It encodes input data as a range of real numbers between 0 and 1. This range becomes smaller as the number of bits required to encode the input increases. Unlike Huffman coding, arithmetic coding uses near-precise probabilities, thus achieving compression rates close to the theoretical limit. However, the algorithm for arithmetic coding is more complex, and its coding efficiency is very low (roughly 1 / 10th that of Huffman coding), limiting its application in real-time data compression applications.

[0006] Therefore, in recent years, many scholars have been searching for a new algorithm that achieves a compression ratio close to that of arithmetic coding and a coding efficiency close to that of Huffman coding. In 2009, Jarek Duda proposed Asymmetric Numeral Systems (ANS). According to Jarek Duda, Asymmetric Numeral Systems achieve a compression ratio comparable to arithmetic coding while having a processing speed similar to Huffman coding. However, this mathematical relationship cannot be directly applied to ANS coding because it cannot be decoded; the decoding end cannot parse the original symbol sequence. Summary of the Invention

[0007] In view of this, the purpose of this invention is to propose a novel ANS encoding / decoding method, computer device, and storage medium, thereby solving the technical problems in the background art by providing a feasible ANS encoding / decoding scheme.

[0008] To achieve the above objectives, in one respect, the present invention provides a novel ANS encoding and decoding method, including an ANS encoding method and an ANS decoding method, wherein the ANS encoding method includes the following steps:

[0009] The probability statistics of the symbols, probability normalization, yields the probability distribution {f1, f2, f3, ..., f}. n}, encoding probability distribution;

[0010] Construct a symbol allocation list Symbol[];

[0011] Construct a cumulative frequency table count[] to record the cumulative frequency, count[x+1] = count[x] + fx, construct a symbol position list Pos[], and use fast lookup to index each symbol in Symbol[].

[0012] Encode the symbol sequence in natural order;

[0013] The ANS decoding method includes the following steps:

[0014] Decode the probability distribution of each symbol set, {f1, f2, f3, ..., f...} n};

[0015] By constructing a symbol allocation list Symbol[], the Symbol[] remains consistent at both the encoding and decoding ends;

[0016] Construct a symbol order list Sort[], where s = Symbol[i], and Sort[i] represents the number of times s appears in the symbol list Symbol;

[0017] Decode the symbol sequence and then reverse the order of the decoded symbol sequence.

[0018] As a further aspect of the present invention, the novel ANS encoding / decoding method performs encoding / decoding while satisfying the following conditions:

[0019] The symbol sequence is encoded using ANS to generate a number. The decoding end then reverse-engineers the number to obtain the entire sequence.

[0020] During encoding and decoding, the intermediate number 'x' can only correspond to one symbol.

[0021] C(x,s1)≠C(x,s2), which holds true even if the probabilities of s1 and s2 are equal (p1=p2), where C() represents the encoding algorithm;

[0022] C(x1,s)≠C(x2,s), C(x1,s) m )≠C(x2,s n );

[0023] For any x and s, x ≠ C(x,s).

[0024] As a further aspect of the present invention, a data formula for ANS decoding is constructed based on the mathematical principles of ANS, wherein the mathematical principle of ANS is: the number x and the symbol s are combined and encoded into a natural number x′, and the formula for calculating x′ is:

[0025] Based on the calculation formula The data formula for ANS decoding is derived as: x = x′ × p.

[0026] As a further aspect of the present invention, the calculation formula for the encoding algorithm C(x,s) is as follows:

[0027]

[0028] As a further aspect of the present invention, the calculation formula for decoding the decoded symbol sequence is as follows:

[0029] s = Symbol[mod(x,T)]

[0030]

[0031] D(x) = (x, s).

[0032] As a further aspect of the present invention, when the sequence is reversed, the sequence of symbols after decoding is the opposite of the sequence of symbols at the encoding end: the encoding end encodes the first symbol first, and the decoding end decodes the last symbol first.

[0033] As a further aspect of the present invention, when constructing the symbol allocation list, the construction method adopts a sequential cyclic allocation scheme, which includes:

[0034] Assign values ​​to the list in ascending order of sign value;

[0035] Each time a value is assigned, the list index of the assigned value is incremented by one, and the frequency of the symbol is decremented by one.

[0036] When the current symbol is the last one, the next symbol starts from the smallest one.

[0037] As a further aspect of the present invention, in the sequential cyclic allocation scheme, only symbols with positive frequencies are assigned values, that is, symbols with zero frequencies are skipped.

[0038] In another aspect, the present invention provides a computer device including a memory and a processor, wherein the memory stores a computer program that, when executed by the processor, performs any of the novel ANS encoding / decoding methods according to the present invention.

[0039] In another aspect, the present invention provides a computer-readable storage medium storing computer program instructions that, when executed, implement any of the novel ANS encoding / decoding methods according to the present invention.

[0040] Compared to traditional implementations, the main advantages of this invention are:

[0041] This invention presents a novel ANS encoding / decoding method, computer device, and storage medium. It proposes a fast ANS encoding scheme based on two lists, count[] and Pos[], including the generation and usage method of Pos[]. It also proposes a fast ANS decoding scheme based on Symbol[] and Sort[], including the mathematical form of Sort[], the generation and usage method of Sort[], and a symbol generation function based on a finite field "sequential loop". The decoding end can parse the original symbol sequence, which can improve the data compression effect.

[0042] These or other aspects of this application will become more apparent from the following description of embodiments. It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only, and are not intended to limit the application. Attached Figure Description

[0043] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other embodiments can be obtained based on these drawings without creative effort.

[0044] In the diagram:

[0045] Figure 1 This is a flowchart of the ANS encoding and decoding process in the novel ANS encoding and decoding method of the present invention;

[0046] Figure 2 This is a flowchart of the ANS decomposition process in the novel ANS encoding / decoding method of the present invention;

[0047] Figure 3 This is a schematic diagram of an embodiment of a computer-readable storage medium for implementing the novel ANS encoding / decoding method of the present invention;

[0048] Figure 4 This is a schematic diagram of the hardware structure of a computer device for implementing the novel ANS encoding / decoding method of the present invention. Detailed Implementation

[0049] To make the objectives, technical solutions, and advantages of the present invention clearer, the embodiments of the present invention will be further described in detail below with reference to specific examples and the accompanying drawings.

[0050] It should be noted that all uses of "first" and "second" in the embodiments of the present invention are for the purpose of distinguishing two different entities or different parameters with the same name. Therefore, "first" and "second" are merely for convenience of expression and should not be construed as limiting the embodiments of the present invention. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion, such as other steps or units inherent in a process, method, system, product, or device that includes a series of steps or units.

[0051] To make the objectives, technical solutions, and advantages of the present invention clearer, the embodiments of the present invention will be further described in detail below with reference to specific examples and the accompanying drawings. It should be understood that the specific embodiments described herein are merely illustrative and are not intended to limit the scope of this application.

[0052] Entropy coding (or entropy encoding) is a lossless data compression scheme. The core idea of ​​entropy coding is to achieve compression by using fewer bits to represent frequently occurring symbols and more bits to represent rarely occurring elements. This can be described by the following two formulas:

[0053]

[0054] In the above formula, P(x) refers to the statistical frequency of symbol x, and L(x) is the code length assigned to symbol x by the entropy coding algorithm.

[0055] Huffman coding and arithmetic coding are two of the most common entropy coding methods, which will be briefly described below. Huffman coding is an entropy coding technique developed by David A. Huffman. The algorithm of Huffman coding is simple, based on the probabilistic ordering of the symbol set to allocate the code length. Huffman coding always uses integer bits to represent a symbol, and it encodes each symbol individually. Therefore, Huffman coding cannot guarantee optimal compression. Huffman coding produces the best results when the probabilities of all symbols are negative powers of 2. In Huffman coding, each occurrence of a symbol is always encoded with the same codeword. The advantage of Huffman coding is its fast encoding speed.

[0056] According to information theory, the ideal codeword length of a single symbol is determined solely by the probability of the symbol's occurrence: code-length(x) = -log p(x) If the probability of a symbol occurring is 0.4, then the ideal codeword length is 1.32(-log₂). 0.4 Unfortunately, Huffman coding can only assign codewords of integer length. This is a major drawback of the Huffman coding algorithm.

[0057] Arithmetic coding addresses this limitation of Huffman coding; it's another entropy coding technique. It encodes input data as a range of real numbers between 0 and 1. This range becomes smaller as the number of bits required to encode the input increases. Unlike Huffman coding, arithmetic coding uses near-precise probabilities, thus achieving compression rates close to the theoretical limit. However, the algorithm for arithmetic coding is more complex, and its coding efficiency is very low (roughly 1 / 10th that of Huffman coding), limiting its application in real-time data compression applications.

[0058] Therefore, in recent years, many scholars have been searching for a new algorithm that achieves a compression ratio close to that of arithmetic coding and a coding efficiency close to that of Huffman coding. In 2009, Jarek Duda proposed Asymmetric Numeral Systems (ANS). According to Jarek Duda, Asymmetric Numeral Systems achieve a compression ratio comparable to arithmetic coding while having a processing speed similar to Huffman coding. However, this mathematical relationship cannot be directly applied to ANS coding because it cannot be decoded; the decoding end cannot parse the original symbol sequence.

[0059] The mathematical principle of ANS is as follows:

[0060] Suppose we need to convert a set S of two symbols... iEncoding the symbol sequence ∈A = {0,1} into a number num, first considering the standard binary number system, this symbol sequence can be encoded as num = ∑S i ·2 i In this case, each symbol ("0" or "1") in the sequence occupies 1 bit. The bit width of the number num is n. Obviously, the binary number system ignores the frequency of occurrence of the two symbols (0,1), that is, the binary number system is applicable to the case that conforms to a uniform distribution of (0,1).

[0061] According to Shannon's information theory, assuming the probability distribution of each symbol in a sequence of symbols is {P1, P2, P3, ..., P...} n}, then the average amount of information per symbol in the symbol set is:

[0062]

[0063] The amount of information contained in symbol S and the probability P of that symbol S Related log(1 / P) s The information content of the two symbols S1 and S2 combined is:

[0064] Assuming natural numbers Therefore, the information content of x combined with S2 is:

[0065]

[0066] Based on the mathematical relationship in the above formula, JarekDuda further hypothesizes that if the number x and the symbol s are combined and encoded into a natural number x′, then the formula for calculating x′ is as follows:

[0067]

[0068] The above is the basic mathematical principle of ANS. ANS encodes a sequence of symbols into natural numbers, which is similar to the principle of the AC (arithmetic coding) algorithm.

[0069] Equations (2) and (3) above describe the mathematical principles of ANS, but these mathematical relationships cannot be directly used for ANS encoding because they cannot be decoded:

[0070] Suppose there are two sequences [x,s1,s2] and [x,s2,s1]. If we use equation (3) for encoding, the resulting numbers are x1′ and x2′, respectively:

[0071]

[0072] Since x′1 = x′2, the encoded numbers of the two sequences are the same, therefore, the decoding end cannot parse out the original symbol sequence.

[0073] Therefore, to facilitate the description of the ANS encoding and decoding process, this invention introduces two expressions as follows:

[0074]

[0075] s is the current symbol, x is the current number, x' is the encoded number, C() represents the encoding algorithm, and D() represents the decoding algorithm. (x,s) is the decoded result.

[0076] A feasible ANS encoding / decoding scheme needs to meet the following conditions:

[0077] 1. A symbol sequence is encoded by ANS to generate a number. The decoding end reverses the process by parsing this number to obtain the entire sequence.

[0078] 2. During the encoding and decoding process, the intermediate number x (state) can only correspond to one symbol.

[0079] 3. C(x,s1)≠C(x,s2), even if the probabilities of s1 and s2 are equal (p1=p2), it still holds true.

[0080] 4. C(x1,s)≠C(x2,s), C(x1,s) m )≠C(x2,s n ).

[0081] 5. For any x and s, x ≠ C(x,s).

[0082] Therefore, in this embodiment of the invention, a novel ANS encoding / decoding method is provided, including an ANS encoding method and an ANS decoding method, wherein, see [link to relevant documentation]. Figure 1 As shown, the ANS encoding method includes the following steps:

[0083] Step S1: Perform probability statistics on the symbols, normalize the probabilities, and obtain the probability distribution {f1, f2, f3, ..., f...} n}, encoding probability distribution;

[0084] Step S2: Construct the symbol allocation list Symbol[];

[0085] Step S3: Construct a cumulative frequency table count[] to record the cumulative frequency, count[x+1] = count[x] + fx, construct a symbol position list Pos[], and use fast lookup to index each symbol in Symbol[].

[0086] Step S4: Encode the symbol sequence in natural order;

[0087] Among them, see Figure 2 As shown, the ANS decoding method includes the following steps:

[0088] Step S10: Decode the probability distribution of each symbol set, {f1, f2, f3, ..., f...} n};

[0089] Step S20: Construct a symbol allocation list Symbol[], which is consistent at both the encoding and decoding ends;

[0090] Step S30: Construct a symbol order list Sort[], where s = Symbol[i], and Sort[i] represents the number of times s appears in the symbol list Symbol (from 0 to i);

[0091] Step S40: Decode the symbol sequence and reverse the order of the decoded symbol sequence.

[0092] As a further aspect of the present invention, the novel ANS encoding / decoding method performs encoding / decoding while satisfying the following conditions:

[0093] The symbol sequence is encoded using ANS to generate a number. The decoding end then reverse-engineers the number to obtain the entire sequence.

[0094] During encoding and decoding, the intermediate number 'x' can only correspond to one symbol.

[0095] C(x,s1)≠C(x,s2), which holds true even if the probabilities of s1 and s2 are equal (p1=p2), where C() represents the encoding algorithm;

[0096] C(x1,s)≠C(x2,s), C(x1,s) m )≠C(x2,s n );

[0097] For any x and s, x ≠ C(x,s).

[0098] In an embodiment of the present invention, a data formula for ANS decoding is constructed based on the mathematical principles of ANS, wherein the mathematical principle of ANS is: a number x and a symbol s are combined and encoded into a natural number x′, and the formula for calculating x′ is:

[0099] Based on the calculation formula The data formula for ANS decoding is derived as: x = x′ × p.

[0100] The formula for calculating the encoding algorithm C(x,s) is as follows:

[0101]

[0102] The formula for calculating the decoding of the decoded symbol sequence is:

[0103]

[0104] When the sequence is reversed, the sequence of symbols after decoding is the opposite of the sequence of symbols at the encoding end: the encoding end encodes the first symbol first, and the decoding end decodes the last symbol first.

[0105] In the embodiments of this application, when constructing the symbol allocation list, the construction method adopts a sequential cyclic allocation scheme, which includes:

[0106] Assign values ​​to the list in ascending order of sign value;

[0107] Each time a value is assigned, the list index of the assigned value is incremented by one, and the frequency of the symbol is decremented by one.

[0108] When the current symbol is the last one, the next symbol starts from the smallest one.

[0109] In the embodiments of this application, the mathematical principle of ANS is shown in formula (3). The mathematical relationship implied in formula (3) is the theoretical basis for constructing the proposed ANS scheme. From formula (3), the following formula can be easily derived:

[0110] x=x′×p(6)

[0111] Suppose that the probability distribution of the symbol set A = {s|0≤s<max} is p = {p1,p2,p3…}, and further suppose there exists a list List[] of length x′, where each element in the list comes from A (list[i]∈A) and follows the probability distribution of A. Clearly, for a specific symbol s, the frequency of s in the entire list is approximately:

[0112] f s =x′×p s (7)

[0113] (6) and (7) are completely identical in form, so we can assume that there are x symbols in the interval (0, x′], that is, List[x′] is the xth occurrence of s in the list List[].

[0114] ANS converts the sequence of symbols into a single number, which is obviously very large, making it impossible to construct an infinitely long list. A most feasible approach is to construct a fixed-length list within a finite field and extend this list to infinity, meaning the symbol distribution function is a periodic function S(x+n×T)=S(x).

[0115] Assume that symbol s appears f times within one period.s Therefore, it is clear that the number of cycles in which the xth s will appear is... And it appears for the mth time within this period, m = mod(x, f). s ).

[0116] Suppose that the period length of S(x) is T. For a specific number y, the sign at position y is obviously the same as the sign at position y′ = mod(y,T) in the first period, that is, S(y) = S(mod(y,T)). Let S(y′) be the m-th occurrence in this period, and let y be the x-th occurrence.

[0117] A symbol distribution function is constructed. In this invention, a "sequential cyclic" symbol allocation scheme is used. The "sequential cyclic" allocation scheme is as follows:

[0118] Assign values ​​to the list in ascending order of symbol values: Symbol[x] = n, Symbol[x+1] = n+1;

[0119] Each time a value is assigned, the list index (assignment position) is incremented by one (+1), and the frequency of the symbol is decremented by one (-1).

[0120] When the current symbol is the last one, the next symbol starts from the smallest (0);

[0121] Only assign values ​​to symbols with positive frequencies, i.e., skip symbols with zero frequencies.

[0122] The novel ANS encoding / decoding method of this invention can improve data compression performance.

[0123] It should be understood that although the above description follows a certain order, these steps are not necessarily executed in that order. Unless otherwise expressly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, some steps in this embodiment may include multiple steps or multiple stages, which are not necessarily completed at the same time, but may be executed at different times. The execution order of these steps or stages is not necessarily sequential, but may be performed alternately or in turn with other steps or at least a portion of the steps or stages in other steps.

[0124] It should be noted that the pseudocode for the "sequential round-robin" allocation scheme is as follows:

[0125]

[0126]

[0127]

[0128]

[0129]

[0130] A third aspect of the present invention also provides a computer device 400, including a memory 420 and a processor 410. The memory stores a computer program, which, when executed by the processor, implements the method of any of the above embodiments, including an ANS encoding method and an ANS decoding method, wherein the ANS encoding method includes the following steps:

[0131] The probability statistics of the symbols, probability normalization, yields the probability distribution {f1, f2, f3, ..., f}. n}, encoding probability distribution;

[0132] Construct a symbol allocation list Symbol[];

[0133] Construct a cumulative frequency table count[] to record the cumulative frequency, count[x+1] = count[x] + fx, construct a symbol position list Pos[], and use fast lookup to index each symbol in Symbol[].

[0134] Encode the symbol sequence in natural order;

[0135] The ANS decoding method includes the following steps:

[0136] Decode the probability distribution of each symbol set, {f1, f2, f3, ..., f...} n};

[0137] By constructing a symbol allocation list Symbol[], the Symbol[] remains consistent at both the encoding and decoding ends;

[0138] Construct a symbol order list Sort[], where s = Symbol[i], and Sort[i] represents the number of times s appears in the symbol list Symbol;

[0139] Decode the symbol sequence and then reverse the order of the decoded symbol sequence.

[0140] like Figure 4 The diagram shown is a hardware structure schematic of an embodiment of a computer device for executing the novel ANS encoding / decoding method provided by the present invention. Figure 4Taking the computer device 400 shown as an example, this computer device includes a processor 410 and a memory 420, and may also include an input device 430 and an output device 440. The processor 410, memory 420, input device 430, and output device 440 can be connected via a bus or other means. Figure 4 Taking a bus connection as an example, input device 430 can receive input digital or character information and generate signal inputs related to the new ANS encoding / decoding. Output device 440 may include display devices such as a display screen.

[0141] Memory 420, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer-executable programs, and modules, such as program instructions / modules corresponding to the novel ANS encoding / decoding method in this application embodiment. Memory 420 may include a program storage area and a data storage area, wherein the program storage area may store the operating system and application programs required for at least one function; the data storage area may store data created by using the novel ANS encoding / decoding method, etc. In addition, memory 420 may include high-speed random access memory and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other non-volatile solid-state storage device. In some embodiments, memory 420 may optionally include memory remotely located relative to processor 410, and these remote memories can be connected to the local module via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.

[0142] The processor 410 executes various server functions and data processing by running non-volatile software programs, instructions, and modules stored in the memory 420, thereby implementing the novel ANS encoding / decoding method of the above method embodiment, including an ANS encoding method and an ANS decoding method, wherein the ANS encoding method includes the following steps:

[0143] The probability statistics of the symbols, probability normalization, yields the probability distribution {f1, f2, f3, ..., f}. n}, encoding probability distribution;

[0144] Construct a symbol allocation list Symbol[];

[0145] Construct a cumulative frequency table count[] to record the cumulative frequency, count[x+1] = count[x] + fx, construct a symbol position list Pos[], and use fast lookup to index each symbol in Symbol[].

[0146] Encode the symbol sequence in natural order;

[0147] The ANS decoding method includes the following steps:

[0148] Decode the probability distribution of each symbol set, {f1, f2, f3, ..., f...} n};

[0149] By constructing a symbol allocation list Symbol[], the Symbol[] remains consistent at both the encoding and decoding ends;

[0150] Construct a symbol order list Sort[], where s = Symbol[i], and Sort[i] represents the number of times s appears in the symbol list Symbol;

[0151] Decode the symbol sequence and then reverse the order of the decoded symbol sequence.

[0152] A fourth aspect of the present invention also provides a computer-readable storage medium. Figure 3 A schematic diagram of a computer-readable storage medium for the novel ANS encoding / decoding method provided in an embodiment of the present invention. Figure 3 As shown, the computer-readable storage medium 300 stores computer program instructions 310, which can be executed by a processor. When executed, the computer program instructions 310 implement the method of any of the above embodiments, including an ANS encoding method and an ANS decoding method, wherein the ANS encoding method includes the following steps:

[0153] The probability statistics of the symbols, probability normalization, yields the probability distribution {f1, f2, f3, ..., f}. n}, encoding probability distribution;

[0154] Construct a symbol allocation list Symbol[];

[0155] Construct a cumulative frequency table count[] to record the cumulative frequency, count[x+1] = count[x] + fx, construct a symbol position list Pos[], and use fast lookup to index each symbol in Symbol[].

[0156] Encode the symbol sequence in natural order;

[0157] The ANS decoding method includes the following steps:

[0158] Decode the probability distribution of each symbol set, {f1, f2, f3, ..., f...} n};

[0159] By constructing a symbol allocation list Symbol[], the Symbol[] remains consistent at both the encoding and decoding ends;

[0160] Construct a symbol order list Sort[], where s = Symbol[i], and Sort[i] represents the number of times s appears in the symbol list Symbol;

[0161] Decode the symbol sequence and then reverse the order of the decoded symbol sequence.

[0162] It should be understood that, without conflict, all the embodiments, features and advantages described above for the novel ANS encoding and decoding method according to the present invention are equally applicable to the novel ANS encoding and decoding system and storage medium according to the present invention.

[0163] Finally, it should be noted that the computer-readable storage medium (e.g., memory) described herein can be volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. By way of example, and not limitation, non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM), which can act as external cache memory. By way of example, and not limitation, RAM can be obtained in various forms, such as synchronous RAM (DRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), and direct Rambus RAM (DRRAM). The storage devices disclosed herein are intended to include, but are not limited to, these and other suitable types of memory.

[0164] This invention presents a novel ANS encoding / decoding method, computer device, and storage medium. It proposes a fast ANS encoding scheme based on two lists, count[] and Pos[], including the generation and usage method of Pos[]. It also proposes a fast ANS decoding scheme based on Symbol[] and Sort[], including the mathematical form of Sort[], the generation and usage method of Sort[], and a symbol generation function based on a finite field "sequential loop". The decoding end can parse the original symbol sequence, which can improve the data compression effect.

[0165] The above are exemplary embodiments disclosed in this invention. However, it should be noted that various changes and modifications can be made without departing from the scope of the embodiments of this invention as defined by the claims. The functions, steps, and / or actions of the methods according to the disclosed embodiments described herein do not need to be performed in any particular order. Furthermore, although the elements disclosed in the embodiments of this invention may be described or claimed individually, they may be understood as multiple unless explicitly limited to a singular number.

[0166] It should be understood that, as used herein, the singular form "a" is intended to include the plural form as well, unless the context clearly supports an exception. It should also be understood that, as used herein, "and / or" refers to any and all possible combinations of one or more of the associatedly listed items. The embodiment numbers disclosed above are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.

[0167] Those skilled in the art should understand that the discussion of any of the above embodiments is merely exemplary and is not intended to imply that the scope of the invention (including the claims) is limited to these examples. Within the framework of the invention, technical features of the above embodiments or different embodiments can be combined, and many other variations of different aspects of the invention exist, which are not provided in the details for the sake of brevity. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the invention should be included within the protection scope of the invention.

Claims

1. A novel ANS encoding / decoding method, characterized in that, This includes an ANS encoding method and an ANS decoding method, wherein the ANS encoding method includes the following steps: Probability statistics of symbols, probability normalization, and probability distribution are obtained. Encoding probability distribution; Construct a symbol allocation list Symbol[]; Construct a cumulative frequency table count[] to record the cumulative frequency, count[x+1] = count[x] + fx; construct a symbol position list Pos[] to quickly find the index of each symbol in Symbol[]. Encode the symbol sequence in natural order; The ANS decoding method includes the following steps: Decoding the probability distribution of each symbol set ; By constructing a symbol allocation list Symbol[], the Symbol[] remains consistent at both the encoding and decoding ends; Construct a symbol order list Sort[], where s = Symbol[i], and Sort[i] represents the number of times s appears in the symbol list Symbol; Decode the symbol sequence, and then reverse the order of the decoded symbol sequence; The method further includes: ANS converts a sequence of symbols into a single number, constructs a fixed-length list in a finite field, and then extends this list to infinity, meaning the symbol distribution function is a periodic function. Where, assuming the number of times symbol s appears in one period is fs, then the number of periods in which the x-th s will appear is This is the mth occurrence within the stated period. ; If the period length of S(x) is T, for a specific number y, the sign at position y is different from that in the first period. The signs in the positions are consistent, that is ,set up It is the m-th occurrence within this period, and assuming y is the x-th occurrence. ; The formula for calculating the encoding algorithm C(x,s) is: ; The formula for calculating the decoding of the decoded symbol sequence is: ,in, 。 2. The novel ANS encoding / decoding method according to claim 1, characterized in that, When the sequence is reversed, the sequence of symbols after decoding is the opposite of the sequence of symbols at the encoding end: the encoding end encodes the first symbol first, and the decoding end decodes the last symbol first.

3. The novel ANS encoding / decoding method according to claim 1, characterized in that, When constructing the symbol allocation list, the construction method employs a sequential cyclic allocation scheme, which includes: Assign values ​​to the list in ascending order of sign value; Each time a value is assigned, the list index of the assigned value is incremented by one, and the frequency of the symbol is decremented by one. When the current symbol is the last one, the next symbol starts from the smallest one.

4. The novel ANS encoding / decoding method according to claim 3, characterized in that, In the sequential cyclic allocation scheme, only symbols with positive frequencies are assigned values, that is, symbols with zero frequencies are skipped.

5. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the computer program is executed by a processor, it performs the novel ANS encoding / decoding method according to any one of claims 1-4.

6. A computer-readable storage medium storing computer program instructions, characterized in that, When the computer program instructions are executed, they implement the novel ANS encoding / decoding method according to any one of claims 1-4.

Citation Information

Patent Citations

  • Self-adaptive finite state entropy coding method

    CN110602498A

  • Error-containing cascaded code identification method based on template matching

    CN111726125A