CN108090122A - Initialization method for realizing equalization tree by iteration method - Google Patents
Initialization method for realizing equalization tree by iteration method Download PDFInfo
- Publication number
- CN108090122A CN108090122A CN201711106686.2A CN201711106686A CN108090122A CN 108090122 A CN108090122 A CN 108090122A CN 201711106686 A CN201711106686 A CN 201711106686A CN 108090122 A CN108090122 A CN 108090122A
- Authority
- CN
- China
- Prior art keywords
- row
- tree
- leaf
- search
- search index
- 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.)
- Granted
Links
- 238000000034 method Methods 0.000 title claims abstract description 34
- 238000011423 initialization method Methods 0.000 title abstract 2
- 230000003139 buffering effect Effects 0.000 claims description 15
- 238000013461 design Methods 0.000 abstract description 5
- 238000003860 storage Methods 0.000 description 12
- 238000004891 communication Methods 0.000 description 3
- 238000012545 processing Methods 0.000 description 3
- 238000000151 deposition Methods 0.000 description 2
- 238000005516 engineering process Methods 0.000 description 2
- 240000005266 Schlumbergera truncata Species 0.000 description 1
- 238000010276 construction Methods 0.000 description 1
- 230000007547 defect Effects 0.000 description 1
- 238000009826 distribution Methods 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 230000006870 function Effects 0.000 description 1
- 238000005304 joining Methods 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 230000008520 organization Effects 0.000 description 1
- 230000008569 process Effects 0.000 description 1
- 239000007787 solid Substances 0.000 description 1
- 239000002699 waste material Substances 0.000 description 1
- 238000004804 winding Methods 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/90—Details of database functions independent of the retrieved data types
- G06F16/901—Indexing; Data structures therefor; Storage structures
- G06F16/9027—Trees
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)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
- Data Exchanges In Wide-Area Networks (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
Technical field
The present invention relates to the initial methods that a kind of iterative method realizes balanced tree.
Background technology
Binary tree is a kind of important nonlinear data structure, it is the knot that data element is organized according to branch's relation
Structure, it is such like the tree in nature.The problem of all are with hierarchical relationship can use tree description, which is widely applied
In the storage and lookup of data.For example, it is necessary to IP address be searched, to determine forwarding in the data exchange of network communication
Situation.And generally longest match principle is followed when searching in IP address there are wildcard bit.It the storage of spanning tree and looks into
Algorithm is looked for meet very much this requirement of network communication, so the algorithm is widely used in network communication chip.
But in basic spanning tree algorithm, do not account for each storage data the number searched the problem of.Machine
Tool according to the principle that can be found, it would be desirable to the list item of lookup is placed on binary tree.All trees that the present invention is discussed are equal
Refer to binary tree.In this way, since the search efficiency of tree is related with the depth residing for current entry, the list item of current lookup is stored and must got over
Deep, number and the time cycle for searching list item cost are longer.If those are not added with judging by the very big list item of lookup probability, quilt
It is put into very deep storage location, then can waste many search efficiency searched the time, reduce the generation tree table.
The content of the invention
For in the prior art the defects of, the object of the present invention is to provide a kind of iterative method realize balanced tree initialization side
Method not only ensure that the list item for being stored in the binary tree can correctly be searched according to the lookup algorithm of tree, and consider
It has arrived by lookup item by lookup probability problem, will the less storage location of the number of plies be placed on by the higher list item of lookup probability,
To the deeper storage location of the number of plies be placed on by the relatively low list item of lookup probability, improved the search efficiency of the tree.
According to an aspect of the present invention, the initial method that a kind of iterative method realizes balanced tree is provided, which is characterized in that
The iterative method realizes that the initial method of balanced tree comprises the following steps:
Step 1:After all search index alignment, each row are observed, those full 0s or complete 1 row are removed, if depositing
In the row of no asterisk wildcard, then those row are found out;Otherwise, the minimum row of those asterisk wildcards are found out;
Step 2:If there are one a row chosen, the row are just used;Otherwise all row that will choose, successively with this
Index grouping will be searched for by being classified as benchmark, and 0 is left side group, and 1 is the right group, and the row search index of asterisk wildcard does not include;It calculates successively
Go out the difference of the lookup number of two groups of left and right;The difference is selected as that minimum row, if the row more than one, according to uniform rules,
It chooses near a left side or near that right row as the row picked out;By in the row row number root node, and using the row as benchmark,
All search indexes are divided into two groups, the search index that the corresponding position of the row is 0 is left side group, and the corresponding position of the row is 1
Search index is the right group, and the search index that row correspondence is classified as asterisk wildcard is put into left side group, is also placed in the right group;
Step 3:Judge whether the topological structure of the tree meets customized topological structure, if so, going to step four;If
It is no, then it is repeated in step 2 in the grouping of the subtree;
Step 4:The search index group in the leaf for the topological structure for being placed on tree at present is judged whether in addition to asterisk wildcard,
Remaining respective column is identical, if identical, all search on the leaf is indexed and are stored with the form of leaf node;If
All search index on the leaf is then continued to execute step 2, generates next subtree by difference, when the generation of next subtree terminates
Afterwards, which stores corresponding content with root node form.
Preferably, the iterative method realizes that the initial method of balanced tree has been introduced primarily into three buffering queue spaces:Son
Set cushion space, leaf cushion space and pseudo- leaf cushion space.
Preferably, the iterative method realizes that the initial method of balanced tree uses the queue mode of first in first out.
Compared with prior art, the present invention has following advantageous effect:One, on the basis of storage of data structure, not only
Meet the requirement of tree most long matched and searched in itself, and when the branch of tree is established in initialization, it is contemplated that search number and
Search the balance of depth so that the common tree of search efficiency ratio of list item and search index on whole tree is much higher.Two, at this
It invents in the balanced tree initial code implementation proposed, three buffering queues of introducing successfully reduce Code Design
Complexity, winding multiplexing by way of, simplify Code Design.So that the generation of tree construction complicated and changeable is finally refined
Into grouping, join the team and go out three key problems of team.
Description of the drawings
Upon reading the detailed description of non-limiting embodiments with reference to the following drawings, other feature of the invention,
Objects and advantages will become more apparent upon:
Fig. 1 is sub-tree structure figure.
Fig. 2 is the flow chart for the initial method that iterative method of the present invention realizes balanced tree.
Specific embodiment
With reference to specific embodiment, the present invention is described in detail.Following embodiment will be helpful to the technology of this field
Personnel further understand the present invention, but the invention is not limited in any way.It should be pointed out that the ordinary skill to this field
For personnel, without departing from the inventive concept of the premise, various modifications and improvements can be made.These belong to the present invention
Protection domain.
As shown in Fig. 2, iterative method of the present invention realizes that the initial method of balanced tree comprises the following steps:
Step 1:After all search index alignment, each row are observed, those full 0s or complete 1 row are removed, if depositing
In the row of no asterisk wildcard, then those row are found out;Otherwise, the minimum row of those asterisk wildcards are found out.
Step 2:If there are one a row chosen, the row are just used;Otherwise all row that will choose, successively with this
Index grouping will be searched for by being classified as benchmark, and 0 is left side group, and 1 is the right group, and the row search index of asterisk wildcard does not include.It calculates successively
Go out the difference of the lookup number of two groups of left and right.The difference is selected as that minimum row, if the row more than one, according to uniform rules,
It chooses near a left side or near that right row as the row picked out.By in the row row number root node, and using the row as benchmark,
All search indexes are divided into two groups, the search index that the corresponding position of the row is 0 is left side group, and the corresponding position of the row is 1
Search index is the right group, and the search index that row correspondence is classified as asterisk wildcard is put into left side group, is also placed in the right group.
Step 3:Judge whether the topological structure of the tree meets customized topological structure, if so, going to step four;If
It is no, then it is repeated in step 2 in the grouping of the subtree.
Step 4:The search index group in the leaf for the topological structure for being placed on tree at present is judged whether in addition to asterisk wildcard,
Remaining respective column is identical, if identical, all search on the leaf is indexed and are stored with the form of leaf node.If
All search index on the leaf is then continued to execute step 2, generates next subtree by difference, when the generation of next subtree terminates
Afterwards, which stores corresponding content with root node form.
As shown in Figure 1, three buffering queue spaces have been introduced primarily into here:Subtree cushion space, leaf cushion space and
Pseudo- leaf cushion space.Using the queue mode of first in first out, finally emptied when all space contents go out team, then represent one tree
Initialization complete.
Join the team out the order of team of these spaces can be:
Sequentially one:
Priority 1:Subtree buffering queue (highest priority)
Priority 2:Pseudo- leaf buffering queue
Priority 3:Leaf buffering queue
Sequentially two:
Priority 1:Subtree buffering queue (highest priority)
Priority 2:Leaf buffering queue
Priority 3:Pseudo- leaf buffering queue
When the queue not empty of current grouping completion and priority 1, data dequeued performs grouping from the queue of priority 1
Judge;When the queue not empty of the queue empty of current grouping completion and priority 1 and priority 2, go out from the queue of priority 2
Team's data perform grouping and judge (or data therein are write memory space);Completion, and the team of priority 1 are grouped when current
Row are empty, and the queue empty of priority 2, and during the queue not empty of priority 3, data dequeued, which performs, from the queue of priority 3 divides
Group judges (or data therein are write memory space).It is that will go out that leaf buffering queue, which goes out after team to need the operation completed,
The data write-in memory space of team.It is that will go out that subtree buffering queue and pseudo- leaf buffering queue, which go out after team to need the operation completed,
The data of team are grouped judgement.
Input search index+contents in table module:It is used for the data input algorithm process of binary tree to be generated is related
Module.
Choose grouping with reference to row module:As algorithm processing module, be used for input one or more search indexes+
In contents in table, being indexed according to the search of input, comparator algorithm step 1 and the described principle of step 2 pick out a row, with
Convenient for being subsequently grouped to input data.
According to reference to column split:As algorithm processing module, it is used for according to the row selected, comparator algorithm step 2
Input data is divided into 2 groups by principle.
According to rule judgment, grouped data is joined the team module:Algorithm processing module the most is used for the number after grouping
According to, first left side group the right group (or first the right group again left side group) again, a kind of buffering is selected in 3 kinds of cushion spaces according to rule
Space carries out enqueue operations.Rule is:If the topological structure of current subtree has met a kind of one of structure shown in FIG. 1, and if
The data currently organized can be put into same leaf, then by current group of leaf cushion space of joining the team;If current subtree topological structure
Met a kind of one of structure shown in FIG. 1, and if the data currently organized cannot be put into same leaf, current group is joined the team
Pseudo- leaf cushion space;If current subtree topological structure is unsatisfactory for a kind of one of structure shown in FIG. 1, enter subtree by current group
Cushion space.
List item and search index are used for as the output module of algorithm by leaf according to leaf node form memory module
The data of subspace go out team successively, and according to fixed form, write in correct space address, which is stored in root section
In dot format.
The present invention relates to following concepts:
Search index:For building the storage organization of whole tree, the index that uses when searching.For number plus asterisk wildcard
(asterisk wildcard * represents 0 or 1).In application of the IP address as search index is used, the length for searching for index is solid
Fixed, still, in other applications, the length for searching for index can also be unfixed, that is to say, that each search index
Length can be different.
Contents in table:Represent the resultant content by index search.Generally it is made of number.Its length can also be according to need
Different list lengths is used in a table, still, in being normally applied, the length of the contents in table in a table is
Identical.
The topological structure of tree:Here the structure of 9 kinds of binary trees is specified, each structure represents the topology of a subtree, such as
Fig. 1, light circle represent root and node, and dark circle represents leaf.Can also according to oneself need define it is different
Y-bend tree topology.
True leaf:On the leaf position of the topological structure of subtree, and the lattice that the content wherein stored is leaf node
Formula, only stores result and search indexes relevant content.The topological structure of subtree is not linked on this piece leaf still further below.
Pseudo- leaf:On the leaf position of the topological structure of subtree, but the form that the content wherein stored is root node,
The topological structure of link subtree downwards is stored on this piece leaf.
Root node:The beginning of one tree or subtree, for storing tree and the relevant content of topological structure, opening up including tree
Structure is flutterred, position number (position for 0 represent to the left look into, which for 1 represents to the right look into) of the storage every time with reference to search index is indicated, refers to
The storage address of bright each leaf node, and indicate whether each leaf node is true leaf.
Leaf node:For storing the related contents such as the address of search index and storage contents in table, including searching for rope
The value drawn and the position of asterisk wildcard link leaf storage address.
Search the calculating of number:The number of all search indexes is added in one grouping, if containing n in search index
Asterisk wildcard, the then number that the search indexes are calculated by 2 n times side;Otherwise, search index number is calculated by 1.
The principle of balanced tree generation, the higher principle of priority:As far as possible so that whole tree all list items lookup number it
And minimum;The relatively low principle of priority:As far as possible so that the topological structure distribution of whole tree is as far as possible uniform.
Here by taking the realization of verilog hardware identification codes as an example, (can also use other programming languages to realize) introduces this hair
Bright implementation.The input of search index+list item of tree to be generated, may be employed the mode of text invention, is invented using text
The mode of input is input to pending in code.Three buffer queue spaces can use the team of one first in first out of Code Design
Row by example, repeat exampleization three times.A module for calculating lookup number can be designed by choosing the module of grouping row, be passed through
Call and the exampleization module, calculate the difference of 0 and 1 group of lookup number of a certain row, similarly, calculate comparison in need
The difference of lookup number after the grouping of different lines, then by comparing, find out poor minimum near left (or near right side) that row, make
For the row chosen.When going out group leaf buffering queue, the content in leaf is write into memory space by realizing.This is all data
Jump out the outlet of code loop.That is, when all data finally with correct form write memory space, for after
Most long matched lookup, the function of entire code just complete.
Specific embodiments of the present invention are described above.It is to be appreciated that the invention is not limited in above-mentioned
Particular implementation, those skilled in the art can make various deformations or amendments within the scope of the claims, this not shadow
Ring the substantive content of the present invention.
Claims (3)
1. a kind of iterative method realizes the initial method of balanced tree, which is characterized in that the iterative method realizes the initial of balanced tree
Change method comprises the following steps:
Step 1:After all search index alignment, each row are observed, remove those full 0s or complete 1 row, if in the presence of not having
There are the row of asterisk wildcard, then find out those row;Otherwise, the minimum row of those asterisk wildcards are found out;
Step 2:If there are one a row chosen, the row are just used;Otherwise all row that will choose, successively using the row as
Benchmark will search for index grouping, and 0 is left side group, and 1 is the right group, and the row search index of asterisk wildcard does not include;A left side is calculated successively
The difference of lookup number two groups right;The difference is selected as that minimum row, if the row more than one, according to uniform rules, is chosen
Near a left side or near that right row as the row picked out;By in the row row number root node, and using the row as benchmark, by institute
Some search indexes are divided into two groups, and the search index that the corresponding position of the row is 0 is left side group, and the corresponding position of the row is 1 search
It indexes as the right group, the search index that row correspondence is classified as asterisk wildcard is put into left side group, is also placed in the right group;
Step 3:Judge whether the topological structure of the tree meets customized topological structure, if so, going to step four;If it is not, then
Step 2 is repeated in the grouping of the subtree;
Step 4:Judge that the search index group in the leaf for the topological structure for being placed on tree at present whether in addition to asterisk wildcard, is left
Respective column it is identical, if identical, all search on the leaf are indexed and are stored with the form of leaf node;If no
Together, then all search index on the leaf is continued to execute into step 2, generates next subtree, when the generation of next subtree terminates
Afterwards, which stores corresponding content with root node form.
2. iterative method according to claim 1 realizes the initial method of balanced tree, which is characterized in that the iterative method is real
The initial method of existing balanced tree has been introduced primarily into three buffering queue spaces:Subtree cushion space, leaf cushion space and puppet
Leaf cushion space.
3. iterative method according to claim 1 realizes the initial method of balanced tree, which is characterized in that the iterative method is real
The initial method of existing balanced tree uses the queue mode of first in first out.
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 true CN108090122A (en) | 2018-05-29 |
CN108090122B 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 (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101369267A (en) * | 2007-08-15 | 2009-02-18 | 中兴通讯股份有限公司 | Fuzzy query method based on internal memory warehouse |
US20090113309A1 (en) * | 2007-10-25 | 2009-04-30 | Robert Krauthgamer | Adaptive greedy method for fast list intersection via sampling |
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 |
-
2017
- 2017-11-10 CN CN201711106686.2A patent/CN108090122B/en active Active
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101369267A (en) * | 2007-08-15 | 2009-02-18 | 中兴通讯股份有限公司 | Fuzzy query method based on internal memory warehouse |
US20090113309A1 (en) * | 2007-10-25 | 2009-04-30 | Robert Krauthgamer | Adaptive greedy method for fast list intersection via sampling |
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)
Title |
---|
王俊杰 等: "LR-WPAN捷径式能量均衡树路由算法研究", 《计算机工程与应用》 * |
Also Published As
Publication number | Publication date |
---|---|
CN108090122B (en) | 2021-10-22 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
Winkler | Isometric embedding in products of complete graphs | |
US5995971A (en) | Apparatus and accompanying methods, using a trie-indexed hierarchy forest, for storing wildcard-based patterns and, given an input key, retrieving, from the forest, a stored pattern that is identical to or more general than the key | |
Malaguti et al. | A metaheuristic approach for the vertex coloring problem | |
CA2237161C (en) | Storage and retrieval of ordered sets of keys in a compact 0-complete tree | |
CN104392010B (en) | A kind of querying method of subgraph match | |
US8145665B2 (en) | Bit string search apparatus, search method, and program | |
CN104580027A (en) | OpenFlow message forwarding method and equipment | |
CN105224532B (en) | Data processing method and device | |
CN103475584B (en) | Three-state content addressing memory (TCAM) querying method and device | |
CN102148746A (en) | Message classification method and system | |
CN102427428A (en) | Stream identifying method and device based on multi-domain longest match | |
CN110222238A (en) | The querying method and system of character string and identifier biaxial stress structure | |
CN105282123A (en) | Network protocol identification method and device | |
Singh et al. | Improved heuristics for the bounded-diameter minimum spanning tree problem | |
CN110221960A (en) | Generate method and device, the computer equipment, storage medium of test case | |
Larmore | Height restricted optimal binary trees | |
CN108090122A (en) | Initialization method for realizing equalization tree by iteration method | |
CN109376546A (en) | Data packet auditing method, system, device and storage medium based on global rule | |
CN109800337A (en) | A kind of multi-mode canonical matching algorithm suitable for big alphabet | |
CN109254962A (en) | A kind of optimiged index method and device based on T- tree | |
CN103294735B (en) | The matching process of definitiveness finite state automata DFA based on TCAM and device | |
CN109992253A (en) | Source code is generated from table and using method, system and the equipment of the source code | |
US7313567B1 (en) | Schemaless XML payload generation | |
Korsh | Generating t-ary trees in linked representation | |
Karimov | Data Structures and Algorithms in Swift |
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 |