Rapid defect checking method based on balanced binary tree

文档序号:510413 发布日期:2021-05-28 浏览:20次 中文

阅读说明:本技术 基于平衡二叉树的快速查缺方法 (Rapid defect checking method based on balanced binary tree ) 是由 吴仕富 于 2021-02-20 设计创作,主要内容包括:本发明公开了基于平衡二叉树的快速查缺方法,包括如下步骤:S1、构建一个64位的整形数组Array,每个比特位表示一个分片,比如有512个分片,数组的第一个64位可以表示编号为0~63的分片,数组的第二个64位可以表示编号为64~127的分片,以此类推;S2、当收到一个分片后,通过计算分片在数组中的位置,并设置相应比特位为1;S3、通过平衡二叉树规则,将所有叶子节点两两做与运算,并构建其父节点,直至构建出根节点。本发明的有益效果是:通过平衡二叉树,以及比特位分块的快速缺失查询,在(N文件或消息分片的数量,M是缺失文件或分片的数量)复杂度的性能下,快速找到哪些分片是缺失的。(The invention discloses a quick defect checking method based on a balanced binary tree, which comprises the following steps: s1, constructing a 64-bit shaping Array, wherein each bit represents a fragment, for example, 512 fragments exist, the first 64 bits of the Array can represent fragments with the number of 0-63, the second 64 bits of the Array can represent fragments with the number of 64-127, and the like; s2, when a fragment is received, calculating the position of the fragment in the array and setting the corresponding bit as 1; and S3, performing AND operation on all leaf nodes pairwise through a balanced binary tree rule, and constructing father nodes of the leaf nodes until a root node is constructed. The invention has the beneficial effects that: by balancing the binary tree and fast miss-searching for bit partitions (number of N files or message fragments, M number of missing files or fragments) complexAnd under the performance of complexity, which fragments are missing can be quickly found.)

1. A quick defect checking method based on a balanced binary tree is characterized in that: the method comprises the following steps:

s1, constructing a 64-bit shaping Array, wherein each bit represents a fragment, for example, 512 fragments exist, the first 64 bits of the Array can represent fragments with the number of 0-63, the second 64 bits of the Array can represent fragments with the number of 64-127, and the like;

s2, when a fragment is received, calculating the position of the fragment in the array and setting the corresponding bit as 1;

s3, performing AND operation on all leaf nodes pairwise through a balanced binary tree rule, and constructing father nodes of the leaf nodes till a root node is constructed;

and S4, after the root node is constructed, which leaf nodes are missing can be inquired downwards from the root node.

2. The balanced binary tree-based fast defect checking method according to claim 1, wherein: in step S1, each node only displays the last 8 of the 64 bits, and the first 56 bits are default 1.

3. The balanced binary tree-based fast defect checking method according to claim 1, wherein: the query process in step S4 is as follows: if the root node is Uint64full (each bit of a 64-bit integer is 1), all fragments are received, the data is complete, the query efficiency is 0(1), otherwise, whether the left sub-tree is Uint64full is queried, then the right sub-tree is queried, the leaf node 3 can be rapidly queried to be missing through four query processes (query 1, query 2, query 3 and query 4), because each node is represented by 64 bits, although the leaf node 3 is determined to be missing, which bit is 0 is not determined, and the query is optimized again in order to not traverse 64 times.

Technical Field

The invention relates to the technical field of network data, in particular to a rapid defect checking method based on a balanced binary tree.

Background

In a large-scale network data transmission scene, a receiving end needs to check whether received data is complete, while sending data generally adopts a fragmentation and concurrent sending mode, which can cause that the data received by the receiving end is not continuous and complete, and the receiving end needs to check whether each fragmentation arrives at the time in a traversal mode.

Disclosure of Invention

The invention aims to provide a quick defect-checking method based on a balanced binary tree to solve the problems in the background technology.

In order to achieve the purpose, the invention provides the following technical scheme: a quick defect checking method based on a balanced binary tree comprises the following steps:

s1, constructing a 64-bit shaping Array, wherein each bit represents a fragment, for example, 512 fragments exist, the first 64 bits of the Array can represent fragments with the number of 0-63, the second 64 bits of the Array can represent fragments with the number of 64-127, and the like;

s2, when a fragment is received, calculating the position of the fragment in the array and setting the corresponding bit as 1;

s3, performing AND operation on all leaf nodes pairwise through a balanced binary tree rule, and constructing father nodes of the leaf nodes till a root node is constructed;

and S4, after the root node is constructed, which leaf nodes are missing can be inquired downwards from the root node.

Preferably, each node in the step S1 only displays the last 8 bits of the 64 bits, and the first 56 bits are default 1.

Preferably, the query process in step S4 is as follows: if the root node is Uint64full (each bit of a 64-bit integer is 1), all fragments are received, the data is complete, the query efficiency is 0(1), otherwise, whether the left sub-tree is Uint64full is queried, then the right sub-tree is queried, the leaf node 3 can be rapidly queried to be missing through four query processes (query 1, query 2, query 3 and query 4), because each node is represented by 64 bits, although the leaf node 3 is determined to be missing, which bit is 0 is not determined, and the query is optimized again in order to not traverse 64 times.

Compared with the prior art, the utility modelThe invention has the beneficial effects that: by balancing the binary tree and fast miss-searching for bit partitions(number of N files or message fragments, M number of missing files or fragments) complexity, quickly find which fragments are missing.

Drawings

The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the application and together with the description serve to explain the application and not to limit the application. In the drawings:

FIG. 1 is a flowchart of the defect checking of the balanced binary tree of the present invention.

Detailed Description

The technical solutions in the embodiments of the present invention are clearly and completely described below, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.

Referring to fig. 1, the fast defect checking method based on the balanced binary tree of the present invention includes the following steps:

s1, constructing a 64-bit shaping Array, wherein each bit represents a fragment, for example, 512 fragments exist, the first 64 bits of the Array can represent fragments with the number of 0-63, the second 64 bits of the Array can represent fragments with the number of 64-127, and the like;

s2, when a fragment is received, calculating the position of the fragment in the array and setting the corresponding bit as 1;

s3, performing AND operation on all leaf nodes pairwise through a balanced binary tree rule, and constructing father nodes of the leaf nodes till a root node is constructed;

and S4, after the root node is constructed, which leaf nodes are missing can be inquired downwards from the root node.

For convenience of viewing in step S1, each node in fig. 1 only displays the last 8 of 64 bits, and the first 56 bits are default 1.

The query process in step S4 is: if the root node is Uint64full (each bit of a 64-bit integer is 1), it indicates that all fragments have been received, the data is complete, the query efficiency is 0(1), otherwise, it queries whether the left sub-tree is Uint64full, then queries the right sub-tree, and it can quickly query that the leaf node 3 is missing through the four processes of the query in fig. 1 (query 1, query 2, query 3, and query 4), because each node is represented by 64 bits, it is not determined which bit is 0 although it is determined that the leaf node 3 is missing, and in order to not traverse 64 times, the query will be optimized again.

The first embodiment is as follows:

s1, constructing a 64-bit shaping Array, wherein each bit represents a fragment, for example, 512 fragments exist, the first 64 bits of the Array can represent fragments with the number of 0-63, the second 64 bits of the Array can represent fragments with the number of 64-127, and the like;

s2, after receiving a fragment, calculating the position of the fragment in the array, and setting the corresponding bit as 1, wherein the calculation formula is as follows:

Arrindex=Splitno/64

Bitindex=Splitno%64

Array[Arrindex]=Array[Arrindex]|(1<<Bitindex)

s3, performing AND operation on all leaf nodes pairwise through a balanced binary tree rule, and constructing father nodes of the leaf nodes till a root node is constructed;

and S4, after the root node is constructed, which leaf nodes are missing can be inquired downwards from the root node.

For convenience of viewing in step S1, each node in fig. 1 only displays the last 8 of 64 bits, and the first 56 bits are default 1.

The query process in step S4 is: if the root node is Uint64full (each bit of a 64-bit integer is 1), it indicates that all fragments have been received, the data is complete, the query efficiency is 0(1), otherwise, it queries whether the left sub-tree is Uint64full, then queries the right sub-tree, and it can quickly query that the leaf node 3 is missing through the four processes of the query in fig. 1 (query 1, query 2, query 3, and query 4), because each node is represented by 64 bits, it is not determined which bit is 0 although it is determined that the leaf node 3 is missing, and in order to not traverse 64 times, the query will be optimized again.

The missing index mapping table of the present invention is:

the above chart is: a lookup table of 0 to 65535 is constructed, and each table entry contains an index VALUE of which bit is 0, for example, KEY is 0, if all bits are 0, its VALUE is (0, 1, 2 … 15), KEY is 65534, if only the last bit is 0, its VALUE is (0), and it can know a 16-bit integer and which bits are missing by fast missing position lookup.

In step S4, it is found that there is a missing leaf node 3, but it is not known which bit is missing, the leaf node is divided into 4 integers of 16 bits, the 4 integers of 16 bits are found by querying the missing index mapping table, and the first three are found to be complete, the fourth integer value is 65533, and the missing position is: (1).

And then through the formula:

Missingindex=64*(Leafindex-1)+16*(Splitindex-1)+Mapindex

the loss position was calculated to be 64 x (3-1) +16 x (4-1) +1 ═ 177, i.e. the data loss with fragment number 177.

Firstly, mapping N fragments into 64-bit arrays to generate N/64 leaf nodes, then constructing a balanced binary tree, when a missing position is queried, quickly finding out the missing leaf nodes through binary tree search, then dividing 64-bit integers into 4 16-bit integers through a quick missing mapping table, and carrying out key value query with the efficiency of 0(1), so that the query efficiency is the efficiency of querying the leaf child nodes by the balanced binary tree: 0(LogN/64), therefore, if it is necessary to check whether one piece of data is complete, it is only necessary to determine whether the root node is the maximum value of 64-bit shaping, and it is not necessary to traverse all the fragments.

The above description is only an embodiment of the present invention, and is not intended to limit the present invention. Various modifications and alterations to this invention will become apparent to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention should be included in the scope of the claims of the present invention.

6页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:营销物料管理系统

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!