CN107332567B - Coding method and device - Google Patents

Coding method and device Download PDF

Info

Publication number
CN107332567B
CN107332567B CN201710432892.6A CN201710432892A CN107332567B CN 107332567 B CN107332567 B CN 107332567B CN 201710432892 A CN201710432892 A CN 201710432892A CN 107332567 B CN107332567 B CN 107332567B
Authority
CN
China
Prior art keywords
layer
probability
coded identification
father node
encoded
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201710432892.6A
Other languages
Chinese (zh)
Other versions
CN107332567A (en
Inventor
杨磊
钟炎培
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Xian Wanxiang Electronics Technology Co Ltd
Original Assignee
Xian Wanxiang Electronics Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Xian Wanxiang Electronics Technology Co Ltd filed Critical Xian Wanxiang Electronics Technology Co Ltd
Priority to CN201710432892.6A priority Critical patent/CN107332567B/en
Publication of CN107332567A publication Critical patent/CN107332567A/en
Application granted granted Critical
Publication of CN107332567B publication Critical patent/CN107332567B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

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

Abstract

The invention discloses a kind of coding method and devices.Wherein, this method comprises: obtaining the probability that each coded identification occurs in data to be encoded;Probable range corresponding to the probability occurred according to each coded identification, is layered each coded identification;According to the sequence of threshold value in probable range from small to large, the coded identification in the corresponding layer of probable range is risen to upper one layer according to preset rules, until the coded identification in the corresponding layer of minimum probability range rises to top layer, obtains the code tree of data to be encoded;According to coding tree-encoding data to be encoded.The present invention solve in the prior art Huffman tree establish it is slower, lead to the technical problem that coding rate is slow.

Description

Coding method and device
Technical field
The present invention relates to coding fields, in particular to a kind of coding method and device.
Background technique
Huffman encoding (Huffman Coding) is a kind of coding mode, is one kind of variable word length coding (VLC). Huffman proposes the coding method in nineteen fifty-two, and this method symbol more for frequency of occurrence uses shorter coded representation, The symbol less for frequency of occurrence uses longer coded representation, this just makes the average expectation length of the character string after coding It reduces, to achieve the purpose that lossless compression data.Huffman encoding algorithm needs to scan twice of data.First pass calculates symbol Then the frequency occurred in data constructs a Huffman tree according to symbol frequency, second of scan data is by symbol by Kazakhstan Fu Man tree is encoded.
The calculation method for constructing Huffman tree is as follows: initially setting up the coded character set of n character composition, saves it The frequency f of character denotation and each character is ranked up with the size of f value and is constituted Priority Queues Q, and 2 have minimum probability Number merges.After 2 trees with minimum probability merge, a new tree is generated, frequency is 2 trees merged The sum of frequency, and will newly set insertion Priority Queues Q.After n-1 merging, only remaining one tree, i.e. institute in Priority Queues It is required that Huffman tree.This Huffman tree can be compiled according to the allocation plan on left 0 right side 1 after building Huffman tree Code.Conventional Huffman tree method for building up time complexity is o (n^2).
The construction process of Huffman tree in the prior art is illustrated by taking Fig. 1 as an example below.Six coded identification a, b, C, d, e, f sort from small to large according to its frequency occurred are as follows: and " f:5, e:9, c:12, b:13, d:16, a:45 ", first by f Merge to obtain 14 with e, 14 are inserted between b and d in queue;Merge c and b to obtain 25, the d and a 25 being inserted into queue Between;Merge 14 and d to obtain 30,30 are inserted between 25 in queue and a;25 and 30 are merged and obtains 55, by 55 rows After a, a and 55 are finally merged into 100.Then this Huffman tree carries out it according to the allocation plan on left 0 right side 1 Coding.
Introduced in Huffman encoding algorithm heapsort thought can reduction operand by a relatively large margin, avoid repeatability Compare.According to minimum heapsort, then the time complexity for finding minimum node becomes O (logn), and whole complexity just subtracts It is less O (nlogn).Even if Huffman encoding use heapsort thought, but when n is bigger sort operation still can relatively consumption compared with The long time influences the speed of coding so that Huffman tree foundation is slower.
It is slower for the foundation of Huffman tree in the prior art, lead to the problem that coding rate is slow, not yet proposes at present effective Solution.
Summary of the invention
The embodiment of the invention provides a kind of coding method and devices, at least to solve Huffman tree foundation in the prior art It is relatively slow, lead to the technical problem that coding rate is slow.
According to an aspect of an embodiment of the present invention, a kind of coding method is provided, comprising: obtain every in data to be encoded The probability that a coded identification occurs;Probable range corresponding to the probability occurred according to each coded identification accords with each coding It number is layered;According to the sequence of threshold value in probable range from small to large, by the coded identification in the corresponding layer of probable range Upper one layer is risen to according to preset rules, until the coded identification in the corresponding layer of minimum probability range rises to top layer, is obtained The code tree of data to be encoded;According to coding tree-encoding data to be encoded.
Further, the quantity of all coded identifications in the frequency and data to be encoded that each coded identification occurs is obtained; The quantity of all coded identifications determines each coded identification in the frequency and data to be encoded occurred according to each coded identification The probability of appearance.
Further, it is determined that probable range and the corresponding layer of probable range, wherein probable range includes:Probable range is corresponding to be layered as k layers, and k ∈ [1, m], m are probability minimum and probability in data to be encoded Layer belonging to the coded identification of non-zero;Search probable range belonging to each coded identification, and by each coded identification sort out to The corresponding layer of affiliated probable range;The least significant end of layer where the coded identification of maximum probability in every layer is arranged in.
Further, in the case that the quantity of coded identification in current layer is even number, the coded identification of current layer is made For child node, merge constitute father node two-by-two, and in the case where father node meets default rising condition, father node is risen to Upper one layer;In the case that the quantity of coded identification in current layer is odd number, using the coded identification of current layer as child node, two Two merge composition father node, rise to upper one layer in the case where father node meets default rising condition and by father node, and will A remaining single coded identification directly rises to one layer of front end.
Further, the corresponding probability of father node belongs to one layer of corresponding probable range.
Further, the corresponding probability of father node is compared with maximum probability in upper one layer;If father node pair The probability answered is greater than maximum probability in upper one layer, then father node is placed in upper one layer of least significant end, will be maximum in upper one layer Probability is placed in the front end in one layer;If the corresponding probability of father node is less than maximum probability in upper one layer, father is saved Point is placed in one layer of front end.
Further, if the corresponding probability of father node is greater than maximum probability in current layer, by father node and currently The corresponding node replacement position of maximum probability of layer;If the corresponding probability of father node is less than maximum probability in current layer, The position for keeping father node to be presently in.
Further, father node is being retained in current layer, and after being compared with probability maximum in current layer, side Method further include: using father node as the coded identification of current layer, merged with the probability of other coded identifications.
Further, addition code length space and coding fluid space, wherein code length space is for saving each volume The code length of code sign, coding fluid space are used to save the encoded stream information of each coded identification.
Further, storage unit has the marks of all cotyledon under its command in the corresponding unit of each coded identification after separating the layers Know, wherein identify and have whether branch includes coded identification to be encoded under its command for characterize each unit.
Further, for being located at the child node on the left of father node, the lowermost end for the coded identification that child node is had under its command Code length adds one, and adds Zero-code before existing encoding code stream;To lowermost end in the child node being located on the right side of father node The code length of node add one, and one coding of addition before existing encoding code stream.
According to another aspect of an embodiment of the present invention, a kind of code device is additionally provided, comprising: module is obtained, for obtaining Take the probability that each coded identification occurs in data to be encoded;Hierarchical block, the probability for being occurred according to each coded identification Corresponding probable range is layered each coded identification;Code tree module is constructed, for according to thresholding in probable range The sequence of value from small to large, rises to upper one layer according to preset rules for the coded identification in the corresponding layer of probable range, until Coded identification in the corresponding layer of minimum probability range rises to top layer, obtains the code tree of data to be encoded;Coding module is used According to coding tree-encoding data to be encoded.
Further, obtaining module includes: acquisition submodule, for obtaining the frequency of each coded identification appearance and wait compile The quantity of all coded identifications in code data;First determines submodule, the frequency for being occurred according to each coded identification and to The quantity of all coded identifications determines the probability of the appearance of each coded identification in coded data.
Further, hierarchical block includes: the second determining submodule, for determining that probable range and probable range are corresponding Layer, wherein probable range includes:Probable range is corresponding to be layered as k layers, k ∈ [1, m], m be to Probability is minimum in coded data and the coded identification of probability non-zero belonging to layer;Submodule is searched, for searching each coding symbol Probable range belonging to number, and each coded identification is sorted out to the affiliated corresponding layer of probable range;Submodule is arranged, is used for The least significant end of layer where the coded identification of maximum probability in every layer is arranged in.
According to another aspect of an embodiment of the present invention, a kind of storage medium is additionally provided, storage medium includes the journey of storage Sequence, wherein equipment where control storage medium executes above-mentioned any one coding method in program operation.
According to another aspect of an embodiment of the present invention, a kind of processor is additionally provided, which is characterized in that processor is for transporting Line program, wherein program executes above-mentioned any one coding method when running.
In embodiments of the present invention, the probability that each coded identification occurs in data to be encoded is obtained, according to each coding Symbol occur probability corresponding to probable range, each coded identification is layered, according to threshold value in probable range by Coded identification in the corresponding layer of probable range is risen to upper one layer according to preset rules by as low as big sequence, until minimum Coded identification in the corresponding layer of probable range rises to top layer, obtains the code tree of data to be encoded, according to coding tree-encoding Data to be encoded.There is still a need for scanning calculation code symbols to occur in data to be encoded for the coding method method that above scheme provides Frequency construct near-optimization binary tree, but the probability when constructing on encoding binary tree without occurring to coded identification carries out Sequence saves Huffman encoding in the prior art and the probability occurred to coded identification is needed to be ranked up when establishing binary tree Process, the overall complexity of building near-optimization binary tree is only O (n), and compression rates and Huffman encoding are close, from And solve in the prior art Huffman tree establish it is slower, lead to the technical problem that coding rate is slow, reached the lossless pressure of raising The effect of contracting speed.
Detailed description of the invention
The drawings described herein are used to provide a further understanding of the present invention, constitutes part of this application, this hair Bright illustrative embodiments and their description are used to explain the present invention, and are not constituted improper limitations of the present invention.In the accompanying drawings:
Fig. 1 is a kind of schematic diagram of Huffman encoding according to prior art;
Fig. 2 is a kind of flow chart of coding method according to an embodiment of the present invention;
Fig. 3 is a kind of flow chart of optional coding method according to an embodiment of the present invention;
Fig. 4 is the schematic diagram that the coding method in a kind of Application Example 1 according to an embodiment of the present invention is encoded;
Fig. 5 a be it is according to an embodiment of the present invention it is a kind of building optimum binary tree when FPGA in layer data update schematic diagram;
Fig. 5 b be it is according to an embodiment of the present invention it is a kind of building optimum binary tree when FPGA in layer data update schematic diagram;
Fig. 5 c be it is according to an embodiment of the present invention it is a kind of building optimum binary tree when FPGA in layer data update schematic diagram;
Fig. 5 d be it is according to an embodiment of the present invention it is a kind of building optimum binary tree when FPGA in layer data update schematic diagram;
Fig. 5 e be it is according to an embodiment of the present invention it is a kind of building optimum binary tree when FPGA in layer data update schematic diagram;
Fig. 5 f be it is according to an embodiment of the present invention it is a kind of building optimum binary tree when FPGA in layer data update schematic diagram; And
Fig. 6 is a kind of schematic diagram of code device according to an embodiment of the present invention.
Specific embodiment
In order to enable those skilled in the art to better understand the solution of the present invention, below in conjunction in the embodiment of the present invention Attached drawing, technical scheme in the embodiment of the invention is clearly and completely described, it is clear that described embodiment is only The embodiment of a part of the invention, instead of all the embodiments.Based on the embodiments of the present invention, ordinary skill people The model that the present invention protects all should belong in member's every other embodiment obtained without making creative work It encloses.
It should be noted that description and claims of this specification and term " first " in above-mentioned attached drawing, " Two " etc. be to be used to distinguish similar objects, without being used to describe a particular order or precedence order.It should be understood that using in this way Data be interchangeable under appropriate circumstances, so as to the embodiment of the present invention described herein can in addition to illustrating herein or Sequence other than those of description is implemented.In addition, term " includes " and " having " and their any deformation, it is intended that cover Cover it is non-exclusive include, for example, the process, method, system, product or equipment for containing a series of steps or units are not necessarily limited to Step or unit those of is clearly listed, but may include be not clearly listed or for these process, methods, product Or other step or units that equipment is intrinsic.
Embodiment 1
According to embodiments of the present invention, a kind of embodiment of coding method is provided, it should be noted that in the process of attached drawing The step of illustrating can execute in a computer system such as a set of computer executable instructions, although also, in process Logical order is shown in figure, but in some cases, it can be to be different from shown or described by sequence execution herein Step.
Fig. 2 is a kind of flow chart of coding method according to an embodiment of the present invention, as shown in Fig. 2, this method includes as follows Step:
Step S202 obtains the probability that each coded identification occurs in data to be encoded.
As a kind of optional embodiment, the probability of the appearance of each coded identification in data to be encoded is obtained, comprising: obtain The quantity of all coded identifications in the frequency and data to be encoded for taking each coded identification to occur;Occurred according to each coded identification The frequency and data to be encoded in all coded identifications quantity determine each coded identification appearance probability.
Step S204, according to each coded identification occur probability corresponding to probable range, to each coded identification into Row layering.Herein it should be noted that meet probable range is just divided to corresponding layer, therefore it is layered to probability In obtained result, certain layer may be 0, that is, not include the coded identification that probability belongs to this layer.
Specifically, above-mentioned every layer of corresponding probable range is different from above-mentioned steps, and there is no overlapping region.
As a kind of optional embodiment, probable range corresponding to the probability occurred according to each coded identification, to every A coded identification is layered, comprising: determines probable range and the corresponding layer of probable range, wherein probable range includes:Probable range is corresponding to be layered as k layers, and k ∈ [1, m], m are probability minimum and probability in data to be encoded Layer belonging to the coded identification of non-zero;Search probable range belonging to each coded identification, and by each coded identification sort out to The corresponding layer of affiliated probable range;The least significant end of layer where the coded identification of maximum probability in every layer is arranged in.
In an alternative embodiment, the corresponding probable range of first layer be [1/2,1), the corresponding probability model of the second layer Enclose for [1/4,1/2), the corresponding probable range of third layer be [1/8,1/4), continue to be layered according to above-mentioned rule, until general Rate is minimum and the coded identification of probability non-zero can be fallen into m layers of maximum layer.Furthermore it is also possible to limit the maximum number of plies, and will most Small coding possibilities value is changed to the probability minimum value of kth layer.
Using the layered approach, the maximum code length of the coded identification of algorithm is k.It follows that the coding of same layer Quantized value probability is close, and the probability value of any two n-th layer is added, and the value after merging can necessarily rise to one layer.Often The maximum probability value of one layer of coded identification is placed on the last of this layer.
Step S206, according to the sequence of threshold value in probable range from small to large, by the volume in the corresponding layer of probable range Code sign rises to upper one layer according to preset rules, until the coded identification in the corresponding layer of minimum probability range rises to top Layer, obtains the code tree of data to be encoded.
Specifically, top layer be [1/2,1) the corresponding layer of probable range, execute merge and layer promotion after, which must Can so there are two nodes, the two nodes are merged, then can obtain the binary tree eventually for coding, it is therefore, each general Rate range is not overlapped.
In an alternative embodiment, it by the bottom after being layered, is added rises to one layer two-by-two, as upper one Node in layer, is added two-by-two again with the frequency of upper one layer of coded identification, until rising to top layer.Coding in layer The quantity of symbol is odd number, when cannot be in conjunction with the probability of other coded identifications, directly by the general of this individual coded identification Rate rises to one layer.
Step S208, according to coding tree-encoding data to be encoded.
Specifically, above-mentioned code tree is binary tree, data to be encoded are encoded according to final binary tree.
From the foregoing, it will be observed that the above embodiments of the present application obtain the probability that each coded identification occurs in data to be encoded, according to Probable range corresponding to the probability that each coded identification occurs, is layered each coded identification, according in probable range Coded identification in the corresponding layer of probable range is risen to upper one layer according to preset rules by the sequence of threshold value from small to large, Until the coded identification in the corresponding layer of minimum probability range rises to top layer, the code tree of data to be encoded is obtained, according to volume Code tree encodes data to be encoded.There is still a need for scanning calculation code symbols in number to be encoded for the coding method method that above scheme provides Construct near-optimization binary tree according to the frequency of middle appearance, but when constructing on encoding binary tree without occurring to coded identification Probability is ranked up, and is saved Huffman encoding in the prior art and is needed the probability occurred to coded identification when establishing binary tree The process being ranked up, the overall complexity of building near-optimization binary tree is only O (n), and compression rates and Huffman are compiled Code is close, to solve in the prior art, Huffman tree foundation is slower, leads to the technical problem that coding rate is slow, has reached and mentioned The effect of high lossless compression speed.
Optionally, according to the sequence of probable range from small to large, probable range is corresponding according to the above embodiments of the present application Layer in coded identification rise to upper one layer according to preset rules, until the corresponding layer of minimum probability range in coded identification The corresponding layer of maximum probability range is risen to, the code tree of data to be encoded is obtained, comprising:
In the case that the quantity of coded identification in current layer is even number, using the coded identification of current layer as child node, Merge two-by-two and constitute father node, and in the case where father node meets default rising condition, father node is risen to upper one layer;When In the case that the quantity of coded identification is odd number in current layer, using the coded identification of current layer as child node, merge structure two-by-two At father node, upper one layer is risen in the case where father node meets default rising condition and by father node, and by remaining one A single coded identification directly rises to one layer of front end.
As a kind of optional embodiment, above-mentioned default rising condition includes: that the corresponding probability of father node belongs to one layer Corresponding probable range.
In above-mentioned steps, after father node is risen to upper one layer, it can be placed on one layer of front end, then passed through It is compared with maximum probability in upper one layer, it is determined whether the maximum value in one layer is given birth to using the corresponding probability updating of father node.
As a kind of optional embodiment, father node is risen to upper one layer, comprising: by the corresponding probability of father node with it is upper Maximum probability is compared in one layer;If the corresponding probability of father node is greater than maximum probability in upper one layer, father is saved Point is placed in one layer of least significant end, and maximum probability in upper one layer is placed in the front end in upper one layer;If father node is corresponding Probability be less than upper one layer in maximum probability, then father node is placed in upper one layer of front end.
Optionally, in the above embodiments of the present application, in the case where father node is unsatisfactory for default rising condition, father is saved Point is retained in current layer, and is compared with probability maximum in current layer:
If the corresponding probability of father node is greater than maximum probability in current layer, by father node and current layer most probably The corresponding node replacement position of rate;If the corresponding probability of father node is less than maximum probability in current layer, father node is kept The position being presently in.
As a kind of optional embodiment, father node is being retained in current layer, and with probability maximum in current layer into After row compares, the above method further include: using father node as the coded identification of current layer, with the probability of other coded identifications into Row merges.
From the foregoing, it will be observed that the coded identification of each layer of maximum probability value is set in the above embodiment of the present invention The least significant end of this layer.When the quantity of coded identification in this layer is even number, the coded identification of least significant end can be with other coded identifications Probability value phase adduction rise to one layer, but in this layer the quantity of coded identification be odd number when, the probability value meeting of least significant end One layer is directly risen to, to reduce the code length of all cotyledon in the branch, therefore in each layer, on this is direct The sub-branch risen should remain the maximum value of this layer.
Above scheme can be realized with a variety of programming modes, realize that the above method is illustrated to using FPGA below.
In FPGA realization, each unit is obtained by coded identification Frequency statistics histogram, and (each coded identification is accounted for One unit) frequency, after the probability that each coded identification occurs in obtaining data to be encoded, addition code length is empty Between and coding fluid space, wherein code length space is used to save the code length of each coded identification, and coding fluid space is used for Save the encoded stream information of each coded identification.
The coded identification of the frequency value of all probability non-zeros is sorted out by layer, has returned the coded identification of class according to layer by small To big arranged in sequence, every layer of maximum value is placed on the last of the sequence of layer.
As a kind of alternative embodiment, the probable range corresponding to the probability occurred according to each coded identification, to volume After code sign is layered, storage unit has all cotyledon under its command in the corresponding unit of each coded identification after separating the layers Mark, wherein identify and have whether branch includes coded identification to be encoded under its command for characterize each unit.Namely in code tree Any node has whether branch includes the coded identification to be encoded (without the lowermost end cotyledon of any branch in code tree under its command Son), by taking Fig. 4 as an example, the coded identification in the example includes abcdef, and the node of each tree has the identifier of 6bit, often 1bit represents a corresponding symbol, and bit1 expression has had the coded identification under its command, and bit0 indicates to accord with without the coding Number, in an alternative embodiment, a:bit [5], b:bit [4], c:bit [3], d:bit [2], e:bit [1], f are set: Bit [0], then the mark of node 55 is 011111;The mark of node 14 is 000011, and the mark of node f is 000001.
Merge constitute father node two-by-two using the coded identification of current layer as child node as a kind of alternative embodiment Later, method further include: for being located at the child node on the left of father node, the volume of the lowermost end for the coded identification that child node is had under its command Code length adds one, and adds Zero-code before existing encoding code stream;To lowermost end in the child node being located on the right side of father node The code length of node adds one, and one coding of addition before existing encoding code stream.
Specifically, starting from maximum layer (k value is maximum, i.e. the smallest layer of probable range), when constructing code tree when each When the number of layer is even number, merges rise to one layer two-by-two, probability value is added;When each layer of number is odd number, two-by-two When merging rises to one layer, the last one remaining odd number need to directly rise to one layer of front end.Rise one layer new Maximum frequency value with upper layer rearmost end is compared by several frequency values, greater than maximum value then new probability value and maximum value Replace position.When merging two-by-two, the value neutron leaf flag bit in left side is that the sub- code length of lowermost end cotyledon of " 1 " adds 1, Add " 0 " coding before existing encoding code stream, the sub- code length of lowermost end cotyledon on right side adds 1, adds before existing encoding code stream " 1 " coding.Combined frequency value is merged into one layer of 1 new frequency value, and the sub- flag bit of cotyledon or addition are (under the branch of left and right It is 1 " that all lowermost end cotyledon of linchpin, which mark).
As a kind of optional embodiment, when all coded identifications are elevated to first layer (i.e. top layer), first layer must There can be two trees, frequency smaller value is the left limb of editor-in-chief's code tree, and frequency the larger value is the right limb of editor-in-chief's code tree, according to two Two merge when to the update for having lowermost end cotyledon under its command after, code tree and it is all initial when cotyledon code length and encode code Stream, which has updated, to be finished.
Fig. 3 is a kind of flow chart of optional coding method according to an embodiment of the present invention, in a kind of optional embodiment In, with example shown in Fig. 3, the coding method in the application is illustrated.
S31, coded identification frequency statistics.
S32, the normalization of the coded identification frequency.
S33, coded identification probabilistic hierarchical.
It, can be according to formula in above-mentioned stepsAffiliated layer is encoded to determine, wherein p For the probability that coded identification occurs, k is layer belonging to p.
S34, maximum probability value is placed on least significant end in same layer.
S35, judges whether bottom unit number is more than or equal to 2, the case where bottom unit number is more than or equal to 2 Under, S36 is entered step, S37 is otherwise entered step.Specifically, the above-mentioned bottom is for the smallest probable range after characterization layering Corresponding layer.
S36 merges the first two probability, and rises one layer, compared with upper one layer of maximum probability value.
In the case where bottom unit number is more than or equal to 2, determination can be merged the coded identification of the bottom. In this step, two probability of front end in the bottom are added, because its certain satisfaction enters upper one layer of condition, One layer is risen to, one layer of front end is placed in.
The probability after merging is compared with maximum probability in upper one layer again, if the probability after merging is greater than upper one Maximum probability in layer then replaces the position of maximum probability in the probability after merging and upper one layer, i.e., will be maximum in upper one layer Probability as the front end in upper one layer, by the probability after merging as upper one layer of least significant end;If the probability after merging Maximum probability in less than upper one layer, then keep current position.
S37 judges whether the number of bottom unit is 1.If the number of bottom unit is 1, enter step Otherwise S38 enters step S39.
In above-mentioned steps, if the number of bottom unit is 1, it is determined that the element number of the bottom is odd number, also There are a single probability that can not merge with other units, and the unit single to this is also needed to handle;If the bottom The number of unit is not 1, it is determined that the element number of the bottom is even number, can be completed to this most by way of merging two-by-two The processing of bottom.
S38, the unit directly rise to one layer, and are placed on one layer of front end.
Upper one layer is directly risen to the single probability that can not merge with other units, since it is centainly less than upper one layer Maximum value, therefore place it in one layer of front end.
S39 handles upper one layer as current layer.After completing to bottom processing, upper one layer is handled, At this point, upper one layer of the bottom is current layer.
S310 judges whether unit number is more than or equal to 2 in current layer.Unit number is more than or equal to 2 in current layer In the case of, S311 is entered step, S317 is otherwise entered step.
S311, judge currently processed unit whether be current layer the first two unit.It is to work as in currently processed unit In the case where the first two unit of front layer, S312 is entered step, S316 is otherwise entered step.
S312 merges the first two unit.
S313, judges whether the unit after merging meets promotion condition.Unit after merging meets the feelings of promotion condition Under condition, S314 is entered step, S315 is otherwise entered step.
In above-mentioned steps, if the probability of the unit after merging belongs to one layer of corresponding probability interval, it is determined that close Unit after and meets promotion condition.
S314 rises to one layer, and compared with upper one layer of maximum probability.
In the case that unit after merging meets promotion condition, if merge after probability be greater than upper one layer in it is maximum Probability, then replace merge after probability with upper one layer in maximum probability position, i.e., by maximum probability in upper one layer as Front end in upper one layer, by the probability after merging as upper one layer of least significant end;If the probability after merging is less than upper one layer In maximum probability, then keep current position.
S315 stays in current layer, and compared with the maximum probability of current layer.
In the case that unit after merging is unsatisfactory for promotion condition, current layer, and the maximum probability with current layer are stayed in Compare, if the probability after merging is greater than maximum probability in current layer, replaces maximum in the probability and current layer after merging Probability position, i.e., by maximum probability in upper one layer as the front end in current layer, by the probability after merging as working as The least significant end of front layer;If the probability after merging is less than maximum probability in current layer, current position is kept.
S316 merges the first two unit, and rises to one layer.
In the case where currently processed unit is not the first two unit of current layer, the unit after merging centainly meets The promotion condition for rising to one layer, there is no need to whether meet promotion condition to it to judge, directly by the unit after merging Rise to one layer.
S317 judges whether the number of current layer unit is 1.In the case where the number of current layer unit is 1, into step Rapid S318, otherwise enters step S319.
S318, the unit directly rise to one layer and are placed on one layer of front end.
In the case where the number of current layer unit is 1, determines that the quantity of unit in current layer is odd number, need to residue A unit directly handle, i.e., a remaining unit is directly risen to upper one layer, since a remaining unit is certain Less than the maximum probability in upper one layer, therefore place it in one layer of front end.
S319 handles upper one layer.In above-mentioned steps, the step of upper one layer is handled with S310 extremely S318 is identical.
S320 judges whether upper one layer be top.In the case where being top for upper one layer, S321 is entered step, it is no Then enter step 310.If upper one layer is not top, S310 is entered step, starts to handle upper one layer.
S321 merges two units of top layer, obtains final binary tree.
Fig. 4 is the schematic diagram that the coding method in a kind of Application Example 1 according to an embodiment of the present invention is encoded, knot It closes shown in Fig. 4, six coded identifications are respectively as follows: " f:5, e:9, c:12, b:13, d:16, a:45 ", corresponding probability difference Are as follows: " f:5%, e:9%, c:12%, b:13%, d:16%, a:45% ", according to formulaTo staying volume Code sign is layered to obtain layer 5 to include f:5, and the 4th layer includes e:9 and c:12, and third layer includes b:13 and d:16, the Four layers include a:45.
Layer 5 only includes a unit, is then directly risen to the 4th layer, be placed in the 4th layer as the bottom Front end.At this point, the 4th layer includes f:5, e:9 and c:12.
4th layer includes three units, and the first two unit is merged to obtain 14, meets the condition for rising to third layer, therefore Third layer is risen to, since 14 corresponding probability 14% are less than maximum probability 16% in third layer, is placed it in The front end of third layer.The 4th layer of remaining single c:12 is risen into third layer again.At this point, third layer include c:12,14, B:13 and d:16.
Merge b:13 and d:16 to obtain 29, rises to the front end of the second layer, then the c in third layer is merged with 14 26 are obtained, and rises to the front end of the second layer.At this point, the second layer includes: 26,29 and a:45.
55 and a:45 after 26 in the second layer are merged with 29 rise to first layer, then 55 and a:45 are closed And obtain final binary tree.
Fig. 5 a to Fig. 5 f is according to the update of layer data in FPGA when a kind of building optimum binary tree of the embodiment of the present invention Schematic diagram.As shown in Fig. 5 a, the 16th layer be data to be encoded the bottom, the number below each unit is for indicating the unit Position.
Firstly, the determining maximum value x16_7 (position 7 in Fig. 5 a) and the 15th layer of maximum value x15_ for having read the 16th layer 3 (positions 10 in Fig. 5 a).Two units x16_1 and x16_2 of the front end in the 16th layer are merged to obtain x16_12, It is secondary, judge whether x16_12 can rise to the 15th layer, if x16_12 can rise to the 15th layer, by xth 16_12 and X16_12 write-in as shown in Figure 5 b, is then already belonged to the 15th layer if x16_12 is less than x15_3 by the x15_3 in 15 layers Position 7.
Then x16_56 is obtained after the 16th layer of x16_5 being added with x16_6, x16_56 is risen to the 15th layer, and with 15th layer of maximum value x15_3 compares, if x16_56 is greater than x15_3, x15_3 is placed on position 6, and update the 15th layer Maximum value;If x16_56 is less than x15_3, x16_56 is placed on position 6.Then x16_3 is added to obtain with x16_4 The 15th layer is updated after x16_34, and by comparing x16_34 and current 15th layer of maximum value, determines that value is placed on Position 5.It is specific as shown in Figure 5 c, the x16_56/max of position 6 be used to indicate to rise to x16_56 the 15th layer of position 6 and with 15th layer of maximum value x15_3 compares, and the x16_34/max of position 5 is used to indicate to rise to x16_34 the 15th layer of position 5 And compared with the 15th layer of current maximum.
If finally, the 16th layer in addition to maximum value there are one number, a remaining number and current maximum merging after Compared with the 15th layer of maximum value, position 4 is updated according to comparison result;If the 16th layer is only had maximum value, the 16th The maximum value of layer is placed on position 4, and the merging of current layer terminates.
If x16_12, which is greater than x15_3, then x16_12 is written the 15th layer of least significant end (position as fig 5d 10), and by x15_3 writing position 7.
If x16_12 cannot rise to one layer, it is compared with the maximum value x16_7 (position 10) in the 16th layer, If x16_12 > x16_7, the maximum value for updating the 16th layer is x16_12, and by x16_7 writing position 2, such as Fig. 5 e;If X16_12 < x16_7, then by x16_12 writing position 7, as shown in figure 5f.
Embodiment 2
According to embodiments of the present invention, a kind of embodiment of code device is provided, Fig. 6 is according to an embodiment of the present invention one The schematic diagram of kind code device, as shown in fig. 6, the device includes:
Module 60 is obtained, for obtaining the probability that each coded identification occurs in data to be encoded.
Hierarchical block 62, probable range corresponding to the probability for being occurred according to each coded identification, to each coding Symbol is layered.
Code tree module 64 is constructed, for the sequence according to threshold value in probable range from small to large, by probable range pair The coded identification in layer answered rises to upper one layer according to preset rules, until the coding symbol in the corresponding layer of minimum probability range Number top layer is risen to, obtains the code tree of data to be encoded.
Coding module 66, for according to coding tree-encoding data to be encoded.
Optionally, according to the above embodiments of the present application, obtaining module includes:
Acquisition submodule, for obtaining all coded identifications in the frequency and data to be encoded that each coded identification occurs Quantity.
First determines submodule, all coding symbols in the frequency and data to be encoded for occurring according to each coded identification Number quantity determine each coded identification appearance probability.
Optionally, according to the above embodiments of the present application, hierarchical block includes:
Second determines submodule, for determining probable range and the corresponding layer of probable range, wherein probable range packet It includes:Probable range is corresponding to be layered as k layers, and k ∈ [1, m], m are that probability is minimum and general in data to be encoded Layer belonging to the coded identification of rate non-zero.
Search submodule, for searching probable range belonging to each coded identification, and by each coded identification sort out to The corresponding layer of affiliated probable range.
Submodule is arranged, the least significant end for layer where being arranged in the coded identification of maximum probability in every layer.
Optionally, according to the above embodiments of the present application, constructing code tree module includes:
First constitutes submodule, in the case that the quantity for working as coded identification in current layer is even number, by current layer Coded identification merges constitute father node two-by-two as child node, and in the case where father node meets default rising condition, by father Node rises to one layer.
Second constitutes submodule, in the case that the quantity for working as coded identification in current layer is odd number, by current layer Coded identification merges constitute father node two-by-two as child node, in the case where father node meets default rising condition and by father Node rises to one layer, and a remaining single coded identification is directly risen to upper one layer of front end.
Optionally, according to the above embodiments of the present application, presetting rising condition includes: that the corresponding probability of father node belongs to one The corresponding probable range of layer.
Optionally, include: according to the above embodiments of the present application, the first composition submodule or the second composition submodule
First comparing unit, for the corresponding probability of father node to be compared with maximum probability in upper one layer.
First position adjustment unit will if being greater than maximum probability in upper one layer for the corresponding probability of father node Father node is placed in one layer of least significant end, and maximum probability in upper one layer is placed in the front end in upper one layer.
Second position adjustment unit will if being less than maximum probability in upper one layer for the corresponding probability of father node Father node is placed in one layer of front end.
Optionally, submodule is constituted according to the above embodiments of the present application, first further include: the second comparing unit is used for In the case that father node is unsatisfactory for default rising condition, father node is retained in current layer, and with probability maximum in current layer It is compared: if the corresponding probability of father node is greater than maximum probability in current layer, by the maximum of father node and current layer The corresponding node replacement position of probability;If the corresponding probability of father node is less than maximum probability in current layer, father is kept to save The position that point is presently in.
Optionally, according to the above embodiments of the present application, the above method further include: father node is being retained in current layer, and After being compared with probability maximum in current layer, using father node as the coded identification of current layer, with other coded identifications Probability merge.
Embodiment 3
According to embodiments of the present invention, a kind of storage medium is provided, storage medium includes the program of storage, wherein in journey Equipment where controlling storage medium when sort run executes the coding method of any one of embodiment 1.
Embodiment 4
According to embodiments of the present invention, a kind of processor is provided, which is characterized in that processor is for running program, wherein The coding method of any one of embodiment 1 is executed when program is run.
The serial number of the above embodiments of the invention is only for description, does not represent the advantages or disadvantages of the embodiments.
In the above embodiment of the invention, it all emphasizes particularly on different fields to the description of each embodiment, does not have in some embodiment The part of detailed description, reference can be made to the related descriptions of other embodiments.
In several embodiments provided herein, it should be understood that disclosed technology contents can pass through others Mode is realized.Wherein, the apparatus embodiments described above are merely exemplary, such as the division of the unit, Ke Yiwei A kind of logical function partition, there may be another division manner in actual implementation, for example, multiple units or components can combine or Person is desirably integrated into another system, or some features can be ignored or not executed.Another point, shown or discussed is mutual Between coupling, direct-coupling or communication connection can be through some interfaces, the INDIRECT COUPLING or communication link of unit or module It connects, can be electrical or other forms.
The unit as illustrated by the separation member may or may not be physically separated, aobvious as unit The component shown may or may not be physical unit, it can and it is in one place, or may be distributed over multiple On unit.It can some or all of the units may be selected to achieve the purpose of the solution of this embodiment according to the actual needs.
It, can also be in addition, the functional units in various embodiments of the present invention may be integrated into one processing unit It is that each unit physically exists alone, can also be integrated in one unit with two or more units.Above-mentioned integrated list Member both can take the form of hardware realization, can also realize in the form of software functional units.
If the integrated unit is realized in the form of SFU software functional unit and sells or use as independent product When, it can store in a computer readable storage medium.Based on this understanding, technical solution of the present invention is substantially The all or part of the part that contributes to existing technology or the technical solution can be in the form of software products in other words It embodies, which is stored in a storage medium, including some instructions are used so that a computer Equipment (can for personal computer, server or network equipment etc.) execute each embodiment the method for the present invention whole or Part steps.And storage medium above-mentioned includes: that USB flash disk, read-only memory (ROM, Read-Only Memory), arbitrary access are deposited Reservoir (RAM, Random Access Memory), mobile hard disk, magnetic or disk etc. be various to can store program code Medium.
The above is only a preferred embodiment of the present invention, it is noted that for the ordinary skill people of the art For member, various improvements and modifications may be made without departing from the principle of the present invention, these improvements and modifications are also answered It is considered as protection scope of the present invention.

Claims (11)

1. a kind of coding method characterized by comprising
Obtain the probability that each coded identification occurs in data to be encoded;
Probable range corresponding to the probability occurred according to each coded identification, divides each coded identification Layer;
According to the sequence of threshold value from small to large in the probable range, by the coded identification in the corresponding layer of the probable range Upper one layer is risen to according to preset rules, until the coded identification in the corresponding layer of minimum probability range rises to top layer, is obtained The code tree of the data to be encoded;
According to data to be encoded described in the coding tree-encoding;
According to the sequence of the probable range from small to large, by the coded identification in the corresponding layer of the probable range according to default Rule rises to one layer, until to rise to maximum probability range corresponding for the coded identification in the corresponding layer of minimum probability range Layer, obtains the code tree of the data to be encoded, comprising:
In the case that the quantity of coded identification in current layer is even number, using the coded identification of current layer as child node, two-by-two Merge and constitute father node, and in the case where the father node meets default rising condition, the father node is risen to upper one Layer;
In the case that the quantity of coded identification in the current layer is odd number, using the coded identification of current layer as child node, Merge two-by-two and constitute father node, in the case where the father node meets default rising condition and rises to the father node One layer, and a remaining single coded identification is directly risen into upper one layer of the front end;
The father node is risen to upper one layer, comprising:
The corresponding probability of the father node is compared with maximum probability in described upper one layer;
If the corresponding probability of the father node is greater than maximum probability in described upper one layer, the father node is placed in described Maximum probability in described upper one layer is placed in the front end in described upper one layer by upper one layer of least significant end;
If the corresponding probability of the father node is less than maximum probability in described upper one layer, the father node is placed in described Upper one layer of front end.
2. the method according to claim 1, wherein obtaining the appearance of each coded identification in data to be encoded Probability, comprising:
Obtain the quantity of all coded identifications in the frequency and the data to be encoded that each coded identification occurs;
The quantity of all coded identifications determines institute in the frequency occurred according to each coded identification and the data to be encoded State the probability of the appearance of each coded identification.
3. the method according to claim 1, wherein according to corresponding to the probability that each coded identification occurs Probable range, each coded identification is layered, comprising:
Determine probable range and the corresponding layer of the probable range, wherein the probable range includes: The probable range is corresponding to be layered as k layers, and k ∈ [1, m], m are probability minimum and probability non-zero in the data to be encoded Layer belonging to coded identification;
Probable range belonging to each coded identification is searched, and each coded identification is sorted out to affiliated probability model Enclose corresponding layer;
The least significant end of layer where the coded identification of maximum probability in every layer is arranged in.
4. the method according to claim 1, wherein the default rising condition includes: that the father node is corresponding Probability belong to upper one layer of corresponding probable range.
5. according to the method described in claim 4, it is characterized in that, being unsatisfactory for the default rising condition in the father node In the case of, the father node is retained in the current layer, and be compared with maximum probability in the current layer:
If the corresponding probability of the father node is greater than maximum probability in the current layer, the father node is worked as with described The corresponding node replacement position of the maximum probability of front layer;
If the corresponding probability of the father node is less than maximum probability in the current layer, the current institute of the father node is kept The position at place.
6. according to the method described in claim 5, it is characterized in that, the father node is retained in the current layer, and with After maximum probability is compared in the current layer, the method also includes: using the father node as the volume of current layer Code sign is merged with the probability of other coded identifications.
7. a kind of code device characterized by comprising
Module is obtained, for obtaining the probability that each coded identification occurs in data to be encoded;
Hierarchical block, for the probable range according to corresponding to the probability of each coded identification appearance, to each volume Code sign is layered;
Code tree module is constructed, for according to the sequence of threshold value from small to large in the probable range, by the probable range Coded identification in corresponding layer rises to upper one layer according to preset rules, until the coding in the corresponding layer of minimum probability range Symbol rises to top layer, obtains the code tree of the data to be encoded;
Coding module is used for the data to be encoded according to the coding tree-encoding;
Constructing code tree module includes:
First constitutes submodule, in the case that the quantity for working as coded identification in current layer is even number, by the coding of current layer Symbol merges constitute father node two-by-two as child node, and in the case where father node meets default rising condition, by father node Rise to one layer;
Second constitutes submodule, in the case that the quantity for working as coded identification in current layer is odd number, by the coding of current layer Symbol merges constitute father node two-by-two as child node, in the case where father node meets default rising condition and by father node One layer is risen to, and a remaining single coded identification is directly risen into upper one layer of front end;
First composition submodule or the second composition submodule include:
First comparing unit, for the corresponding probability of father node to be compared with maximum probability in upper one layer;
First position adjustment unit saves father if being greater than maximum probability in upper one layer for the corresponding probability of father node Point is placed in one layer of least significant end, and maximum probability in upper one layer is placed in the front end in upper one layer;
Second position adjustment unit saves father if being less than maximum probability in upper one layer for the corresponding probability of father node Point is placed in one layer of front end.
8. device according to claim 7, which is characterized in that the acquisition module includes:
Acquisition submodule, for obtaining all coding symbols in the frequency and the data to be encoded that each coded identification occurs Number quantity;
First determines submodule, all volumes in the frequency and the data to be encoded for being occurred according to each coded identification The quantity of code sign determines the probability of the appearance of each coded identification.
9. device according to claim 7, which is characterized in that the hierarchical block includes:
Second determines submodule, for determining probable range and the corresponding layer of the probable range, wherein the probable range Include:The probable range is corresponding to be layered as k layers, and k ∈ [1, m], m are in the data to be encoded Layer belonging to probability minimum and the coded identification of probability non-zero;
Submodule is searched, is returned for searching probable range belonging to each coded identification, and by each coded identification Class is to the affiliated corresponding layer of probable range;
Submodule is arranged, the least significant end for layer where being arranged in the coded identification of maximum probability in every layer.
10. a kind of storage medium, which is characterized in that the storage medium includes the program of storage, wherein run in described program When control the storage medium where equipment perform claim require any one of 1 to 6 described in coding method.
11. a kind of processor, which is characterized in that the processor is for running program, wherein right of execution when described program is run Benefit require any one of 1 to 6 described in coding method.
CN201710432892.6A 2017-06-09 2017-06-09 Coding method and device Active CN107332567B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710432892.6A CN107332567B (en) 2017-06-09 2017-06-09 Coding method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710432892.6A CN107332567B (en) 2017-06-09 2017-06-09 Coding method and device

Publications (2)

Publication Number Publication Date
CN107332567A CN107332567A (en) 2017-11-07
CN107332567B true CN107332567B (en) 2019-06-28

Family

ID=60194715

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710432892.6A Active CN107332567B (en) 2017-06-09 2017-06-09 Coding method and device

Country Status (1)

Country Link
CN (1) CN107332567B (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109412604A (en) * 2018-12-05 2019-03-01 云孚科技(北京)有限公司 A kind of data compression method based on language model
CN113542308B (en) * 2021-09-15 2022-01-07 广州锦行网络科技有限公司 Information processing method, system and storage medium, electronic device
CN113987556B (en) * 2021-12-24 2022-05-10 杭州趣链科技有限公司 Data processing method and device, electronic equipment and storage medium
CN116367150B (en) * 2023-04-18 2023-11-10 甘肃昊润科技信息有限公司 Data encryption transmission method
CN117097441B (en) * 2023-10-19 2024-02-13 深圳龙电华鑫控股集团股份有限公司 Carrier communication system transmission efficiency optimization method based on data analysis

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101980537A (en) * 2010-10-21 2011-02-23 北京航空航天大学 Object and fractal-based binocular three-dimensional video compression coding and decoding method
CN104283568A (en) * 2013-07-12 2015-01-14 中国科学院声学研究所 Data compressed encoding method based on part Hoffman tree

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101980537A (en) * 2010-10-21 2011-02-23 北京航空航天大学 Object and fractal-based binocular three-dimensional video compression coding and decoding method
CN104283568A (en) * 2013-07-12 2015-01-14 中国科学院声学研究所 Data compressed encoding method based on part Hoffman tree

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
Huffman算法的改进及其在图像压缩中的应用;孙秉珏 吴开军;《微计算机信息》;20110105;第27卷(第1期);全文

Also Published As

Publication number Publication date
CN107332567A (en) 2017-11-07

Similar Documents

Publication Publication Date Title
CN107332567B (en) Coding method and device
CN104283567B (en) A kind of compression of name data, decompression method and equipment
EP2924594B1 (en) Data encoding and corresponding data structure in a column-store database
CN105917327A (en) System and method for inputting text into electronic devices
CN105045927B (en) Construction project labor and materials machine data automatic coding and system
CN112131218B (en) Hash table look-up method, device and equipment for gene comparison and storage medium
CN105589929B (en) Image search method and device
CN108804516A (en) Similar users search device, method and computer readable storage medium
CN105191144B (en) Compression set, compression method, decompression device, decompressing method and information processing system
KR960011770A (en) Pattern Recognition Method and Apparatus and Pattern Data Processing Apparatus
CN111325245B (en) Repeated image recognition method, device, electronic equipment and computer readable storage medium
CN102110171A (en) Method for inquiring and updating Bloom filter based on tree structure
JP3720412B2 (en) Information processing method and apparatus
CN110110120B (en) Image retrieval method and device based on deep learning
CN107562853A (en) A kind of method that streaming towards magnanimity internet text notebook data is clustered and showed
CN110442741A (en) A kind of mutual search method of cross-module state picture and text for merging and reordering based on tensor
CN104077272B (en) A kind of method and apparatus of dictionary compression
CN110019763A (en) Text filtering method, system, equipment and computer readable storage medium
CN108092670B (en) Coding method and device
KR101070738B1 (en) Method and apparatus for multi-stage document clustering using ontology
CN107170459A (en) Vector quantizer
CN104584439B (en) Store program, storage method, storage device, gunzip, decompression method and decompressing device
Feigenblat et al. Linear time succinct indexable dictionary construction with applications
CN110825846B (en) Data processing method and device
CN108460074A (en) Multiple row based on BloomFilter indexes establishment and application method in row deposit data library

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant