CN108090122B - Initialization method for realizing equalization tree by iteration method - Google Patents

Initialization method for realizing equalization tree by iteration method Download PDF

Info

Publication number
CN108090122B
CN108090122B CN201711106686.2A CN201711106686A CN108090122B CN 108090122 B CN108090122 B CN 108090122B CN 201711106686 A CN201711106686 A CN 201711106686A CN 108090122 B CN108090122 B CN 108090122B
Authority
CN
China
Prior art keywords
tree
column
search
leaf
group
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
CN201711106686.2A
Other languages
Chinese (zh)
Other versions
CN108090122A (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.)
No32 Research Institute Of China Electronics Technology Group Corp
Original Assignee
No32 Research Institute Of China Electronics Technology Group Corp
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 No32 Research Institute Of China Electronics Technology Group Corp filed Critical No32 Research Institute Of China Electronics Technology Group Corp
Priority to CN201711106686.2A priority Critical patent/CN108090122B/en
Publication of CN108090122A publication Critical patent/CN108090122A/en
Application granted granted Critical
Publication of CN108090122B publication Critical patent/CN108090122B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/901Indexing; Data structures therefor; Storage structures
    • G06F16/9027Trees

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention provides an initialization method for realizing a balanced tree by an iteration method, which comprises the following steps: the method comprises the following steps: after aligning all the search indexes, observing each column; step two: if only one column is picked, the column is used; step three: judging whether the topological structure of the tree meets the self-defined topological structure, if so, turning to the fourth step; if not, repeating the step two in the sub-tree grouping in sequence; step four: and judging whether the search index groups currently placed in the leaves of the topological structure of the tree are identical with the rest corresponding columns except for wildcards. The invention successfully reduces the complexity of code design and simplifies the code design by a loop-back multiplexing mode.

Description

Initialization method for realizing equalization tree by iteration method
Technical Field
The invention relates to an initialization method for realizing a balanced tree by an iteration method.
Background
A binary tree is an important non-linear data structure, which is a structure in which data elements are organized according to a branching relationship, much like a tree in nature. All problems with hierarchical relationships can be described by a tree, and the structure is largely applied to the storage and the searching of data. For example, in data exchange of network communication, an IP address needs to be searched to determine the forwarding condition. And the wildcard bit exists in the IP address, and the longest matching principle is generally followed in the searching process. The spanning tree storage and search algorithm is very suitable for the network communication, so the algorithm is widely applied to network communication chips.
However, the basic spanning tree algorithm does not take into account the number of times each item of stored data is searched. And mechanically placing the table items to be searched on the binary tree according to the searching principle. All trees discussed in this disclosure are referred to as binary trees. Thus, since the search efficiency of the tree is related to the depth of the current entry, the deeper the current entry is stored, the longer the number of times and the time period it takes to search the entry. If the searched list items with high probability are put in a very deep storage position without judgment, much searching time is wasted, and the searching efficiency of the spanning tree table is reduced.
Disclosure of Invention
Aiming at the defects in the prior art, the invention aims to provide an initialization method for realizing a balanced tree by an iterative method, which not only ensures that the items stored in the binary tree can be correctly searched according to a tree searching algorithm, but also considers the problem of the searched probability of the searched items, places the items with higher searched probability at the storage positions with fewer layers, places the items with lower searched probability at the storage positions with deeper layers and improves the searching efficiency of the tree.
According to one aspect of the present invention, there is provided an initialization method for implementing a balancing tree by an iterative method, wherein the initialization method for implementing a balancing tree by an iterative method includes the following steps:
the method comprises the following steps: after aligning all search indexes, observing each column, removing all columns of 0 or 1, and finding out the columns if columns without wildcards exist; otherwise, finding out the columns with the least wildcards;
step two: if only one column is picked, the column is used; otherwise, all the picked columns are sequentially grouped by taking the columns as a reference, 0 is a left side group, 1 is a right side group, and the row search index of the wildcard character is not calculated; calculating the difference between the search times of the left group and the search times of the right group in sequence; selecting the row with the minimum difference, and if the row is more than one, selecting the left-most or right-most row as the selected row according to a unified rule; dividing all search indexes into two groups by taking the column as a reference in the root node of the column number, wherein the search index with the bit of 0 corresponding to the column is a left group, the search index with the bit of 1 corresponding to the column is a right group, and the search indexes with the column corresponding to wildcards are put into the left group and the right group;
step three: judging whether the topological structure of the tree meets the self-defined topological structure, if so, turning to the fourth step; if not, repeating the step two in the sub-tree grouping in sequence;
step four: judging whether the search index groups placed in the leaves of the topological structure of the tree at present have the same corresponding columns except for wildcards, and if so, storing all the search indexes on the leaves in a leaf node format; if not, continuing to execute the step two on all the search indexes on the leaf to generate a next sub-tree, and after the generation of the next sub-tree is finished, storing corresponding contents in a root node format by the leaf.
Preferably, the initialization method for implementing the equalization tree by the iterative method mainly introduces three buffer queue spaces: a subtree buffer space, a leaf buffer space, and a dummy leaf buffer space.
Preferably, the initialization method for implementing the equalization tree by the iterative method adopts a first-in first-out queue mode.
Compared with the prior art, the invention has the following beneficial effects: firstly, on the basis of tree structure storage, the requirement of longest matching search of the tree is met, and in addition, when the branch of the tree is established in an initialization mode, the balance between the search times and the search depth is considered, so that the search efficiency of the table entries and the search indexes on the whole tree is higher than that of the common tree. Secondly, in the balanced tree initialization code implementation scheme provided by the invention, the complexity of code design is successfully reduced by introducing three buffer queues, and the code design is simplified in a loop-back multiplexing mode. The generation of the complex and changeable tree structure is finally refined into three core problems of grouping, enqueuing and dequeuing.
Drawings
Other features, objects and advantages of the invention will become more apparent upon reading of the detailed description of non-limiting embodiments with reference to the following drawings:
FIG. 1 is a view showing a structure of a subtree.
FIG. 2 is a flowchart of an initialization method for implementing a balanced tree by an iterative method according to the present invention.
Detailed Description
The present invention will be described in detail with reference to specific examples. The following examples will assist those skilled in the art in further understanding the invention, but are not intended to limit the invention in any way. It should be noted that variations and modifications can be made by persons skilled in the art without departing from the spirit of the invention. All falling within the scope of the present invention.
As shown in fig. 2, the initialization method for implementing the equalization tree by the iterative method of the present invention includes the following steps:
the method comprises the following steps: after aligning all search indexes, observing each column, removing all columns of 0 or 1, and finding out the columns if columns without wildcards exist; otherwise, those columns with the least wildcards are found.
Step two: if only one column is picked, the column is used; otherwise, all the picked columns are sequentially grouped by taking the columns as a reference, 0 is a left group, 1 is a right group, and the search index of the row of the wildcard character is not calculated. The difference between the search times of the left group and the search times of the right group are calculated in sequence. And selecting the row with the minimum difference, and if more than one row is selected, selecting the left-most or right-most row as the selected row according to a uniform rule. And dividing all the search indexes into two groups by taking the column as a reference, wherein the search index with the bit of 0 corresponding to the column is a left group, the search index with the bit of 1 corresponding to the column is a right group, and the search indexes with the column corresponding to wildcards are placed into the left group and the right group.
Step three: judging whether the topological structure of the tree meets the self-defined topological structure, if so, turning to the fourth step; if not, repeating the step two in the sub-tree grouping in sequence.
Step four: judging whether the search index groups currently placed in the leaves of the topological structure of the tree are completely the same except for wildcards, and if so, storing all the search indexes on the leaves in a leaf node format. If not, continuing to execute the step two on all the search indexes on the leaf to generate a next sub-tree, and after the generation of the next sub-tree is finished, storing corresponding contents in a root node format by the leaf.
As shown in fig. 1, three buffer queue spaces are mainly introduced here: a subtree buffer space, a leaf buffer space, and a dummy leaf buffer space. And finally, when all the space contents are dequeued and emptied, the initialization of one tree is finished.
The order of these several spatial enqueues may be:
the first sequence is as follows:
priority 1: subtree buffer queue (highest priority)
Priority 2: pseudo leaf buffer queue
Priority 3: leaf buffer queue
And a second sequence:
priority 1: subtree buffer queue (highest priority)
Priority 2: leaf buffer queue
Priority 3: pseudo leaf buffer queue
When the current grouping is completed and the queue of the priority level 1 is not empty, performing grouping judgment on dequeued data in the queue of the priority level 1; when the current packet is completed, the queue of the priority level 1 is empty and the queue of the priority level 2 is not empty, performing packet judgment (or writing data in the queue of the priority level 2 into a storage space) on the dequeued data; when the current packet is completed, the queue of priority 1 is empty, the queue of priority 2 is empty, and the queue of priority 3 is not empty, the packet judgment is performed (or the data in the queue of priority 3 is written into the storage space) by dequeuing the data from the queue of priority 3. The operation to be completed after the dequeue of the leaf buffer queue is to write the dequeued data into the storage space. The operation to be completed after dequeuing of the subtree buffer queue and the pseudo leaf buffer queue is to perform grouping judgment on dequeued data.
Input search index + entry content module: which is used for inputting the data of the binary tree to be generated into the algorithm processing correlation module.
Pick out packet reference column module: and the algorithm processing module is used for selecting a column from the input one or more search indexes + table entry contents according to the input search index and by referring to the principles described in the step 1 and the step 2 of the algorithm, so as to facilitate the subsequent grouping of the input data.
Grouped by reference columns: and the algorithm processing module is used for dividing the input data into 2 groups according to the selected columns and by referring to the principle of the algorithm step 2.
And according to the judgment of the rule, the grouping data enqueue module: and the arithmetic processing module is used for selecting one buffer space from the 3 buffer spaces according to rules to carry out enqueue operation on the grouped data by firstly carrying out left group and then carrying out right group (or firstly carrying out right group and then carrying out left group). The rule is as follows: if the topology of the current sub-tree already satisfies one of the structures shown in fig. 1, and if the current set of data can be put into the same leaf, enqueue the current set into the leaf buffer space; if the current sub-tree topology already satisfies one of the structures shown in fig. 1, and if the current set of data cannot be put into the same leaf, enqueue the current set into a pseudo-leaf buffer space; if the current subtree topology does not satisfy one of the structures shown in fig. 1, the current subtree buffer space is populated.
And taking a table entry and search index storage module according to a leaf node format as an output module of the algorithm, wherein the output module is used for sequentially dequeuing data of a leaf space and writing the data into a correct space address according to a fixed format, and the address is stored in a root node format.
The present invention relates to the following concepts:
searching the index: and the index is used for constructing a storage structure of the whole tree and is used in searching. Is a number plus a wildcard character (wildcard character, representing either 0 or 1). In an application using an IP address as a search index, the length of the search index is fixed, but in other applications, the length of the search index may not be fixed, that is, the length of each search index may be different.
The table entry content is as follows: representing the content of the result of the lookup by the index. Typically consisting of numbers. The length of the table entries may be different from one table to another as needed, but in general applications, the length of the table entries in one table is the same.
Topology of the tree: here 9 binary tree structures are specified, each representing the topology of a subtree, as in fig. 1, the light circles representing the roots and nodes and the dark circles representing the leaves. Different binary tree topologies can be defined according to own needs.
True leaves: and storing only the contents related to the results and the search index at the leaf positions of the topological structure of the subtree, wherein the stored contents are in the format of leaf nodes. The topology of the subtree is no longer linked down on this leaf.
Pseudo leaves: at the leaf position of the topological structure of the subtree, but where the stored content is in the form of the root node, the topological structure of the down-linked subtree is stored on this leaf.
Root node: the start of a tree or sub-tree for storing topology related content of the tree includes the topology of the tree, a bit number indicating each time a reference search index is stored (bit 0 for left-looking and bit 1 for right-looking), a memory address indicating each leaf node, and whether each leaf node is a true leaf.
Leaf node: the related contents such as addresses for storing the search index and the contents of the list items comprise the value of the search index, the positions of the wildcards, and the link leaf storage addresses.
And (3) calculating the searching times: adding the number of all search indexes in one group, and if the search indexes contain n wildcards, calculating the number of the search indexes according to the power n of 2; otherwise, the number of the search indexes is calculated according to 1.
The principle of balanced tree generation, the principle of higher priority: the sum of the searching times of all the table entries of the whole tree is minimized as much as possible; lower priority principle: the topological structure distribution of the whole tree is as uniform as possible.
The verilog hardware code implementation is used as an example (other programming languages may also be used) to describe the implementation scheme of the present invention. The search index of the tree to be generated and the input of the table entry can be input into the code to be processed by adopting a text invention mode and a text invention input mode. The three queue buffer spaces can use code to design a first-in first-out queue, and the instantiation is repeated three times. The module for picking the grouped columns can design a module for calculating the search times, the difference between the search times of the 0 group and the search times of the 1 group of a certain column is calculated by calling and instantiating the module, similarly, the difference between the search times of the grouped different columns which need to be compared is calculated, and then the column which is the smallest in difference and is closest to the left (or closest to the right) is found out by comparison to be used as the picked column. When dequeuing the leaf buffer queue, writing the contents of the leaf into the memory space will be implemented. This is the exit of all data jumping out of the code loop. That is, when all data is finally written into the memory space in the correct format for the longest match lookup later, the entire code function is completed.
The foregoing description of specific embodiments of the present invention has been presented. It is to be understood that the present invention is not limited to the specific embodiments described above, and that various changes and modifications may be made by one skilled in the art within the scope of the appended claims without departing from the spirit of the invention.

Claims (3)

1. An initialization method for realizing a balance tree by an iterative method is characterized by comprising the following steps:
the method comprises the following steps: after aligning all search indexes, observing each column, removing all columns of 0 or 1, and finding out the columns if columns without wildcards exist; otherwise, finding out the columns with the least wildcards;
step two: if only one column is picked, the column is used; otherwise, all the picked columns are sequentially grouped by taking the column as a reference, 0 is a left side group, 1 is a right side group, and the search index of the column of the wildcard character is not calculated; calculating the difference between the search times of the left group and the search times of the right group in sequence; selecting the row with the minimum difference, and if the row is more than one, selecting the left-most or right-most row as the selected row according to a unified rule; dividing all search indexes into two groups by taking the column as a reference in the root node of the column number, wherein the search index with the bit of 0 corresponding to the column is a left group, the search index with the bit of 1 corresponding to the column is a right group, and the search indexes with the column corresponding to wildcards are put into the left group and the right group;
step three: judging whether the topological structure of the tree meets the self-defined topological structure, if so, turning to the fourth step; if not, repeating the step two in the tree group in sequence;
step four: judging whether the search index groups placed in the leaves of the topological structure of the tree at present have the same corresponding columns except for wildcards, and if so, storing all the search indexes on the leaves in a leaf node format; if not, continuing to execute the step two on all the search indexes on the leaf to generate a next sub-tree, and after the generation of the next sub-tree is finished, storing corresponding contents in a root node format by the leaf.
2. The initialization method for realizing equalization tree by iterative method according to claim 1, wherein the initialization method for realizing equalization tree by iterative method introduces three buffer queue spaces: a subtree buffer space, a leaf buffer space, and a dummy leaf buffer space.
3. The initialization method for realizing equalization tree by iterative method according to claim 1, wherein the initialization method for realizing equalization tree by iterative method adopts a first-in first-out queue mode.
CN201711106686.2A 2017-11-10 2017-11-10 Initialization method for realizing equalization tree by iteration method Active CN108090122B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201711106686.2A CN108090122B (en) 2017-11-10 2017-11-10 Initialization method for realizing equalization tree by iteration method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201711106686.2A CN108090122B (en) 2017-11-10 2017-11-10 Initialization method for realizing equalization tree by iteration method

Publications (2)

Publication Number Publication Date
CN108090122A CN108090122A (en) 2018-05-29
CN108090122B true CN108090122B (en) 2021-10-22

Family

ID=62170446

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201711106686.2A Active CN108090122B (en) 2017-11-10 2017-11-10 Initialization method for realizing equalization tree by iteration method

Country Status (1)

Country Link
CN (1) CN108090122B (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101369267A (en) * 2007-08-15 2009-02-18 中兴通讯股份有限公司 Fuzzy query method based on internal memory warehouse
CN101853283A (en) * 2010-05-21 2010-10-06 南京邮电大学 Construction method for multidimensional data-oriented semantic indexing peer-to-peer network
CN105577563A (en) * 2015-12-22 2016-05-11 中国电子科技集团公司第三十二研究所 Method for flow management
CN106021560A (en) * 2016-05-30 2016-10-12 浙江工业大学 Data-flow-oriented construction method for low-time-delay memory B+ tree index

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7925604B2 (en) * 2007-10-25 2011-04-12 International Business Machines Corporation Adaptive greedy method for ordering intersecting of a group of lists into a left-deep AND-tree

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101369267A (en) * 2007-08-15 2009-02-18 中兴通讯股份有限公司 Fuzzy query method based on internal memory warehouse
CN101853283A (en) * 2010-05-21 2010-10-06 南京邮电大学 Construction method for multidimensional data-oriented semantic indexing peer-to-peer network
CN105577563A (en) * 2015-12-22 2016-05-11 中国电子科技集团公司第三十二研究所 Method for flow management
CN106021560A (en) * 2016-05-30 2016-10-12 浙江工业大学 Data-flow-oriented construction method for low-time-delay memory B+ tree index

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
LR-WPAN捷径式能量均衡树路由算法研究;王俊杰 等;《计算机工程与应用》;20120811;全文 *

Also Published As

Publication number Publication date
CN108090122A (en) 2018-05-29

Similar Documents

Publication Publication Date Title
CN103238145B (en) High-performance in network is equipped, the renewable and method and apparatus of Hash table that determines
US7356033B2 (en) Method and apparatus for performing network routing with use of power efficient TCAM-based forwarding engine architectures
CN107967219B (en) TCAM-based large-scale character string high-speed searching method
US7917835B2 (en) Memory system and method for use in trellis-based decoding
CN102184205B (en) Based on the Multi-Pattern Matching method of easily extensible precision chaos Hash
US10164884B2 (en) Search apparatus, search configuration method, and search method
Le et al. Scalable tree-based architectures for IPv4/v6 lookup using prefix partitioning
US20050083937A1 (en) IP address lookup method using pipeline binary tree, hardware architecture, and recording medium
JP6997297B2 (en) Establishing a packet classification decision tree
CN107153707A (en) A kind of Hash table construction method and system for nonvolatile memory
CN103051543A (en) Route prefix processing, lookup, adding and deleting method
CN107330094A (en) The Bloom Filter tree construction and key-value pair storage method of dynamic memory key-value pair
CN101277252A (en) Method for traversing multi-branch Trie tree
Job et al. Recursive backtracking for solving 9* 9 Sudoku puzzle
CN106933644A (en) Data processing method and device
CN108090122B (en) Initialization method for realizing equalization tree by iteration method
JP3691018B2 (en) Longest match search circuit and method, program, and recording medium
Zhang et al. A minimum resource neural network framework for solving multiconstraint shortest path problems
US9529835B2 (en) Online compression for limited sequence length radix tree
Avin et al. Deterministic self-adjusting tree networks using rotor walks
CN104090942A (en) Trie search method and device applied to network processor
CN110851658B (en) Tree index data structure, content storage pool, router and tree index method
WO2001063852A1 (en) A method and arrangement for constructing, maintaining and using lookup tables for packet routing
US20150324484A1 (en) Offline radix tree compression with key sequence skip
CN112905607A (en) Block chain data storage method and device and electronic equipment

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