CN102521334B - Data storage and query method based on classification characteristics and balanced binary tree - Google Patents

Data storage and query method based on classification characteristics and balanced binary tree Download PDF

Info

Publication number
CN102521334B
CN102521334B CN201110403732.1A CN201110403732A CN102521334B CN 102521334 B CN102521334 B CN 102521334B CN 201110403732 A CN201110403732 A CN 201110403732A CN 102521334 B CN102521334 B CN 102521334B
Authority
CN
China
Prior art keywords
node
binary tree
balanced binary
tree
deletion
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.)
Expired - Fee Related
Application number
CN201110403732.1A
Other languages
Chinese (zh)
Other versions
CN102521334A (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.)
Guangdong University of Technology
Original Assignee
Guangdong University of Technology
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 Guangdong University of Technology filed Critical Guangdong University of Technology
Priority to CN201110403732.1A priority Critical patent/CN102521334B/en
Publication of CN102521334A publication Critical patent/CN102521334A/en
Application granted granted Critical
Publication of CN102521334B publication Critical patent/CN102521334B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a data storage and query method based on classification characteristics and balanced binary tree. The method comprises the following steps: constructing a balanced binary tree to create nodes; dynamically classifying and storing data information in corresponding nodes according to the sequence of inorder traversal, preorder traversal and postorder traversal; and inputting an enquired content, dynamically traversing the AVL tree to obtain the desired data information. The method provided by the invention can lower the time complexity of dynamic query to static query level, thereby greatly improving storage and query efficiency. The method has the advantages of high speed, low energy consumption, less memory usage, and simple algorithm, and can be implemented by a plurality of languages. The method is widely suitable for data management in the communication field, in particular to massive data storage and query in communication of the internet of things.

Description

A kind of data storage, querying method based on sort feature and balanced binary tree
Technical field
The invention belongs to storage, the querying method field of big data quantity in the Internet of Things communications field, particularly a kind of data storage, querying method based on sort feature and balanced binary tree.
Background technology
In the communication technology, traditional data enquire method comprises static lookup method and dynamic lookup method.Static lookup method comprises sequential search, binary chop, index search; Dynamic lookup method comprises that binary search tree, B-set, Hash (Hash) is searched method, key tree etc.
In sequential search, hypothesis is for the look-up table of n record, and average length of search when it is searched is successfully ASL (Average Search Length), ASL=
Figure 2011104037321100002DEST_PATH_IMAGE002
=
Figure 2011104037321100002DEST_PATH_IMAGE004
, and number of comparisons is=n-i+1 that the probability finding is P i=
Figure 2011104037321100002DEST_PATH_IMAGE006
aSL=nP 1+ (n-1) P 2+ ... + 2P n-1+ P n=
Figure 667263DEST_PATH_IMAGE006
Figure DEST_PATH_IMAGE008
=
Figure DEST_PATH_IMAGE010
, its algorithm time complexity is O (n).
Binary chop is n=2 for the length of generally supposing ordered list h-1, in the situation that each record to search probability equal, i.e. P i=
Figure 646721DEST_PATH_IMAGE006
, can obtain its ASL= log 2(n+1)-1, when n value is greater than 50, its ASL can be approximately log 2(n+1)-1, therefore the time complexity of its algorithm is O(log 2n).
Index search method, it is a kind of method between sequential search and binary chop, can be described as again " piecemeal is orderly " and search method, be about to sequence list and carry out piecemeal, by the maximum key word of last, be less than the minimum key word in latter, inner key word is not necessarily orderly, and the length of supposing concordance list is b, the length of sequence list is n, its ASL=ASL index(b)+ASL seq(n/b) ≈ log 2(b+1)-1+ (n/b+1)/2, therefore the time complexity of its algorithm is (O (log 2n)+O (n))/2.
Binary search tree is searched method, and for the binary search tree that has n node, under balance, its height of tree is log 2n, its time cost of at every turn searching is O (log 2n), under extreme case as its n node become a straight chain table shape the height of tree be n, for the time cost that finds each node, be O (n), know that again it is that the traversal time cost that inserts node is O (n), the time complexity of its total algorithm the best is O (nlog 2n), the poorest is O(n 2).
B-tree is a kind of multichannel search tree of balance, and the key word of inter-node (in order) sequence is carried out to binary chop, if hit, finishes, otherwise enters son's node of the affiliated scope of key word of the inquiry; Repeating, until corresponding son's pointer is empty, or has been leafy node, therefore the time complexity of its algorithm is O(log 2n).
Hash (Hash) is searched method because self hash makes its search efficiency in being applied to classification searching not high.
Key tree is generally used for special searching, and one " path " from root to leaf node corresponds to a key word, is not suitable for the inquiry of general big data quantity.
In the current Internet of Things communications field, the development of communication data technology, more and more trends towards high real-time and hugeization.Traditional static lookup method, as sequential search, binary chop, index search, is difficult to meet current big data quantity and processes the requirement to real-time.And for dynamic lookup (DST), as binary search tree, B-tree, Hash (Hash) is searched method, key tree etc., its time complexity is far away higher than static lookup.
Summary of the invention
The present invention is directed to above deficiency, provide that a kind of speed for mass data is fast, energy consumption is low, committed memory is few, the simply storage of the data based on sort feature and balanced binary tree of algorithm, querying method.
The invention provides a kind of data storage, querying method based on sort feature and balanced binary tree (Adelson-Velskii-Landis tree), implementation method comprises the following steps:
1.1 build Adelson-Velskii-Landis tree, create node;
1.2 according to traversal rule, dynamically data information memory is arrived to corresponding node;
1.3 inputs need the information of inquiry, dynamically travel through Adelson-Velskii-Landis tree, until find required data message or traveled through Adelson-Velskii-Landis tree, return and search unsuccessfully.
Described Adelson-Velskii-Landis tree is orderly, and Adelson-Velskii-Landis tree is (middle order, preorder, postorder) traversal rule in order, dynamically data information memory is arrived to corresponding node.
described node data memory structure is divided into C language and C Plus Plus by the language of realizing.
Concrete methods of realizing of the present invention is as follows:
(1) newly-built Adelson-Velskii-Landis tree, first according to the achievement rule that has Adelson-Velskii-Landis tree, building a nodes is n, the height of tree is log 2the Adelson-Velskii-Landis tree of n, then increases node.Each node represents a feature class C 1,c 2,c 3,c 4c n, in each node, comprising again the information of a class refinement, the refinement information in node is used different data structure storage be convenient to data information memory and search according to the different language of realizing.
(2) to data inserting information in Adelson-Velskii-Landis tree, for the rule of Adelson-Velskii-Landis tree node employing order (middle order, preorder, postorder) traversal, insert, the time complexity of its algorithm is log 2n, can be divided into C Plus Plus and realizing and the realization of C language according to the language of realizing:
1. C Plus Plus is realized: adopt VECTOR class in C Plus Plus as data store organisation in node, when having data message to store, first to judge whether Adelson-Velskii-Landis tree is empty; If so, a newly-built root node data message is saved in to root node returns simultaneously and preserve successfully; If not, travel through Adelson-Velskii-Landis tree, judge whether it belongs to storage node; If so, according to the rule of storage information, the information that needs are preserved is saved in corresponding node, and returns and preserve successfully; If not, perform step (1), then the data message of required preservation is saved in newly-built node, finally by return function, saving result is returned for calling on upper strata;
2. C language is realized: utilize structure variable to build a structure struct, all nodes adopt the storage organization of doubly linked list, by all operations of node being defined as to the member variable of structure, when having data message to preserve, first judge whether Adelson-Velskii-Landis tree is empty; If so, a newly-built root node data message is saved in to root node returns simultaneously and preserve successfully; If not, travel through Adelson-Velskii-Landis tree, determine whether storage node class; The corresponding preservation of preservation member object execution of if so, calling structure operates and returns preserves successfully; If not, perform step (1), then the data message of required preservation is saved in newly-built node class, finally by return function, saving result is returned for calling on upper strata.
(3) data message of inquiry Adelson-Velskii-Landis tree, is O(log according to the time complexity of orderly Adelson-Velskii-Landis tree 2n), so inquiry node needs at most log 2n access memory, by the data message in node is read in buffer zone, utilizes binary search, and its time complexity is also O(log 2n).Preservation implementation according to node also can be divided into C Plus Plus realization and the realization of C language:
1. C Plus Plus is realized: when input inquiry information, call and search function, first judge whether Adelson-Velskii-Landis tree is empty; If so, directly return to tree for empty; If not, travel through Adelson-Velskii-Landis tree, determine whether storage node; If so, continue access node information, and node information is loaded into buffer area, utilize dichotomy to search, and Query Result is called for upper strata to return function; If not, return without node class to return function;
2. C language is realized: when needs data query information, call the function of searching variable and correspondence thereof of structure variable, first judge whether Adelson-Velskii-Landis tree is empty; If so, directly return to tree for empty; If not, travel through Adelson-Velskii-Landis tree, determine whether storage node; If so, call the query manipulation member object of structure and carry out corresponding query manipulation, continue the refinement information in access node class, until inquire results needed or inquired about all recorded informations, and Query Result is assigned to return function for upper strata, calls; If not, return without node class and call for upper strata to return function.
(4) delete balanced binary tree data message, the data message of first preserving the mode of deletion during deletion and needing to delete, then calls and obtains deletion mode (AVLTreeDeleteStyle) function, concrete minute following two kinds of situations:
1. when AVLTreeDeleteStyle value is for deleting node C itime, directly travel through Adelson-Velskii-Landis tree, inquire about the node C of required deletion iif, traveled through all nodes and do not found, return without this node deletion failure; If find direct deletion node C i, and return and delete successfully; Finally deletion result is assigned to return function and calls for upper strata, perform step (5) simultaneously, adjust the tree structure of balanced binary tree;
2. when AVLTreeDeleteStyle value is for deleting node C iin data time, first travel through Adelson-Velskii-Landis tree, inquiry node C i, traveled through all nodes and do not found to return without this node information and delete unsuccessfully; If find the node C of required deletion i, continue to search the information in node, until find required deletion data, by its deletion and return and delete successfully; Or inquired about all records and do not found information needed, returned without data recording and delete unsuccessfully; Finally deletion result being assigned to return function calls for upper strata.
(5) to the insertion of balanced binary tree (Adelson-Velskii-Landis tree) and deletion action, all can exert an influence to tree structure, be log in order to keep minimum to traversal of tree complexity 2n, need to carry out equilibrating adjustment to tree, can divide following four kinds of situations:
1. the L-type of balanced binary tree rotation, when Adelson-Velskii-Landis tree inserts (inserting node in the left child's of minimum subtree root node left subtree) or deletion action (node of deletion is the right child of minimum subtree root node and is leaf node), and the balance factor bf that meets minimum subtree is greater than at 1 o'clock, need to carry out the structure that L-type rotates to regulate Adelson-Velskii-Landis tree;
2. the R type of balanced binary tree rotation, when Adelson-Velskii-Landis tree inserts (inserting node in the right child's of minimum subtree root node right subtree) or deletion action (node of deletion is the left child of minimum subtree root node and is leaf node), and the bf that meets minimum subtree root node is less than at-1 o'clock, need to carries out the rotation of R type and adjust;
3. the LR type of balanced binary tree rotation, when balanced binary tree inserts (inserting node in the right child's of minimum subtree root node left subtree), meet simultaneously minimum subtree root node bf be less than-1 and its left child bf be greater than at 1 o'clock, need to carry out the structure that LR type rotates to regulate Adelson-Velskii-Landis tree;
4. the RL type of balanced binary tree rotation, when balanced binary tree inserts (inserting node in the left child's of minimum subtree root node right subtree), the bf that simultaneously meets minimum subtree root node be greater than 1 and its right child bf be less than at-1 o'clock; Need to carry out the structure that RL type rotates to regulate Adelson-Velskii-Landis tree.
(6) traversal of continuous and full Adelson-Velskii-Landis tree, the Adelson-Velskii-Landis tree that is n for continuous and full nodal point number, its total L=log 2n level node, CL is current progression, D cLfor the layer of current progression node is apart from poor (nodal value between adjacent tree layer poor); The traversal formula of so all nodes is: root node Pr=2 l-1, the father node of current node is P f, its left child P l=P f-D cL, its right child P r=P f+ D cL, D cL=2 l-CL-1, CL ∈ [1, L); Preorder traversal formula is: Pr=1, P l=P f+ 1, P r=P f+ D cL, D cL=2 l-CL, CL ∈ [1, L); Postorder traversal formula is: Pr=2 l-1, P l=P f-D cL, P r=P f-1, D cL=2 l-CL, CL ∈ [1, L).
This method and existing methodical comparison, have following beneficial effect:
(1) this method algorithm complex is little, realizes simply, can realize and rapidly and efficiently stores and inquire about.The tree that this method is n according to node of the structure principle construction of Adelson-Velskii-Landis tree, its height of tree is h=log 2n,, when data are inquired about, the algorithm complex of its traversal is not more than O(log 2n), the information inquiry in node class simultaneously adopts dichotomy, and its algorithm complex is also O(log 2n), in the search algorithm of current use, its algorithm complex is minimum, the time complexity of dynamic queries is reduced to the rank of Static Inquiry, has greatly improved the efficiency of storage and inquiry, reaches the requirement of fast query.
(2) this method algorithm complex is low, effectively reduces the access times of processor, reduces energy consumption.The algorithm complex of this method provides in a upper feature, and with respect to other algorithms of current use, algorithm complex is relatively low, when program is moved, can effectively reduce processor for the access times of internal memory, can effectively reduce energy consumption.
(3) this method can be rationally memory allocated space flexibly, save memory headroom, improve memory source utilization factor.Because the method is to be applied to dynamic memory and searching, for the distribution of resource, be not to use specified distribution, but self-characteristic based on descriptive language used (for example VECTOR in C Plus Plus, has self-propagation characteristic; Doubly linked list in C language, also has dynamic insertion characteristic), reach memory space dynamic allocation.Use C Plus Plus based on supporting VECTOR to realize, utilize the self-propagation characteristic having of VECTOR itself, will be categorized into the element distribution according to need storage unit of concrete node; And use C language to realize, be based on building structure, utilize the structure can associated member variable, its member variable is set to a function, when having data to deposit in, first be categorized into the node place of feature class, according to the function of the member variable of corresponding node, carry out respective handling again, and return to accordingly result and call for upper strata, its inherent treatment mechanism is also to utilize chained list to store in order.It not exclusively uses binary tree as memory carrier simultaneously, has saved the storage space for pointer before and after binary tree, thereby has effectively saved memory source.
(4) can support multilingual to realize, have wide range of applications.The inventive method can realize based on C++/C language, and this bilingual is the main flow of current descriptive language, the method can be applied to large-scale database platform, also can be applied to small-sized data terminal and use, and its range of application is effectively expanded.
Accompanying drawing explanation
fig. 1 isembodiment of the present invention Adelson-Velskii-Landis tree storage node composition;
fig. 2 isembodiment of the present invention Adelson-Velskii-Landis tree inserts process flow diagram;
fig. 3 isembodiment of the present invention Adelson-Velskii-Landis tree is searched process flow diagram;
fig. 4 isembodiment of the present invention Adelson-Velskii-Landis tree is deleted process flow diagram;
fig. 5 isembodiment of the present invention Adelson-Velskii-Landis tree L-type rotation schematic diagram;
fig. 6 isembodiment of the present invention Adelson-Velskii-Landis tree R type rotation schematic diagram;
fig. 7 isembodiment of the present invention Adelson-Velskii-Landis tree LR type rotation schematic diagram;
fig. 8 isembodiment of the present invention Adelson-Velskii-Landis tree RL type rotation schematic diagram;
fig. 9 isembodiment of the present invention Adelson-Velskii-Landis tree postorder storage node composition;
figure 10 isembodiment of the present invention Adelson-Velskii-Landis tree preorder storage node composition.
Embodiment
Below in conjunction with accompanying drawing and example, the invention will be further described, take inorder traversal as example.
The present invention is applied to the storage of the data of the big data quantity of the Internet of Things communications field and method for quickly querying.For example, to 50000 people in terminal place in Internet of Things (nodal point number N=50000), wherein IC-card number (1 byte), name (10 byte), personnel number (2 byte), work attendance information (2 byte), bulletin of assisting to investigate information (200 byte) and other carry out unified management for information about, terminal ram space resource is 8M, can use to swipe the card inquire about with manual two kinds of modes for the inquiry of data message.
Be directed to above demand, with the present invention, realize, adopt Adelson-Velskii-Landis tree as node class index, in Adelson-Velskii-Landis tree, preserve successively left pointer (4 byte), IC-card number (1 byte), node information is preserved address (2 byte), right pointer (4 byte), needs 11 * 50000 ≈ 530Kb altogether.
(1) first build the root node of an Adelson-Velskii-Landis tree, with reference to accompanying drawing 1, building a complexity is log 2n(N is nodal point number) balanced binary tree, call and create node (AVLTreeCreate) function, increase the node of Adelson-Velskii-Landis tree.Each node represents a people C 1,c 2,c 3,c 4c n, each node comprises again a class refinement information D 1,d 2,d 3,d 4d n(comprising personal information, work attendance information etc.), the refinement information in node is used different data structure storage according to the language of realizing is different, is convenient to data information memory and searches.
(2) then in Adelson-Velskii-Landis tree, deposit data message in, can be with reference to accompanying drawing 2, the rule that adopts inorder traversal for Adelson-Velskii-Landis tree is herein to data inserting information in node, and its algorithm complex is log 2n, it is that key word Key distinguishes that its storage node be take IC-card number, can be divided into C Plus Plus and realizing and the realization of C language.
1. C Plus Plus is realized: when having people to swipe the card or manually to input card number, preserve card number information, first whether decision tree is empty; If so, carry out the newly-built node class of AVLTreeCreate function; If not, travel through Adelson-Velskii-Landis tree, judge whether it belongs to storage node, if, carry out and insert (AVLTreeInsert) function, node data message in file reading is also loaded in buffer memory, then carry out and be saved in file (AVLTreeSaveToFile) function, by data according to the form of storage node (as charge time, on call time and date etc.) be saved in the VECTOR of corresponding node information class in file; If not, carry out AVLTreeCreate function, be its newly-built node, then the data message of required preservation is saved in newly-built node class.
2. C language is realized: based on C language, realizing is to utilize structure variable to remove to build a structure, to to the Operation Definition of data message, be a structure TPvector, the member variable of structure is the operation to data, as (inserted Insert, delete Delete, search Search, after turn over PushBack, the front PushFront that turns over).When having people to swipe the card or manually to input card number, preserve card number information, first whether decision tree is empty; If so, call the newly-built node of AVLTreeCreate function; If not, travel through Adelson-Velskii-Landis tree, judge whether it belongs to storage node, if, carry out AVLTreeInsert function, node data message in file reading is also loaded in buffer memory, then carries out AVLTreeSaveToFile function, by data according to the form of storage node class (as charge time, on call time and date etc.) be saved in the file of corresponding node; If not, carry out AVLTreeCreate function, be its newly-built node, then the data message of required preservation is saved in newly-built node.
(3) information in inquiry Adelson-Velskii-Landis tree, can be with reference to accompanying drawing 3, order sequential access in the foundation of the inquiry of Adelson-Velskii-Landis tree herein, time complexity log 2n, also can be divided into C Plus Plus and realizing and the realization of C language according to the preservation implementation of node.
1. C Plus Plus is realized: when having people to swipe the card or manually to input card number, preserve card number information, and by upper strata, call and search (AVLTreeSearch) function, first judge whether Adelson-Velskii-Landis tree is empty, if, redirect finishes to return tree for empty, if not, by inorder traversal Adelson-Velskii-Landis tree, the card number of preserving and the access node key word (key) of balanced binary tree are compared, determine whether storage node, if, file reading information being loaded in buffer memory, according to the mode of inquiry, (as pressed input number, search, search current last, search when one of front and back, search and need the information of deletion etc.) utilize dichotomy to continue the information in inquiry node, if find needed Query Information, Query Result is returned for calling on upper strata by return function, if inquired about all records, do not find information needed, will be assigned to return function without data recording and call for upper strata, if not, will be assigned to return function without these node data calls for upper strata.
2. C language is realized: define a structure TPVector, the member variable of structure is the operation to data, as (insert Insert, delete Delete, inquiry Search, after turn over PushBack, the front PushFront that turns over).When having people to swipe the card or manually to input card number, preserve card number information, and call structure search member object TPVector.AVLTreeSearch, call and search (AVLTreeSearch) function, first judge whether Adelson-Velskii-Landis tree is empty; If so, redirect finishes to return tree for empty; If not, travel through Adelson-Velskii-Landis tree, judge that whether it is storage node, if so, file reading information being loaded in buffer memory, according to the mode of inquiry, (as pressed input number, search, PushFront, PushBack, Delete etc.) utilize dichotomy to continue the information in inquiry node, if find needed information, Query Result is returned for calling on upper strata by return function; If inquired about all records, do not find information needed, will be assigned to return function without data recording and call for upper strata; If not, will be assigned to return function without these node data calls for upper strata.
(4) delete the information in Adelson-Velskii-Landis tree, can be with reference to accompanying drawing 4, the data message of first preserving the mode (AVLTreeDeleteStyle) of deletion during deletion and needing to delete, then judges whether Adelson-Velskii-Landis tree is empty; If so, directly redirect finishes to return tree for empty, travels through if not Adelson-Velskii-Landis tree, concrete minute following two kinds of situations:
1. when AVLTreeDeleteStyle value is, while deleting node, directly to travel through Adelson-Velskii-Landis tree, find the node of required deletion , directly delete whole node, and deletion result is assigned to return function calls for upper strata, call the tree structure that equilibrating function is adjusted Adelson-Velskii-Landis tree simultaneously.
2. when AVLTreeDeleteStyle value is when deleting in node data, first travel through Adelson-Velskii-Landis tree, judge whether it is with storage node; If not, redirect finishes to return without data recording; If so, call LoadAVLTreeNode function and continue to search the information in node, if find, delete the information find, and deletions result is assigned to return function confession upper strata calls; If inquired about all records, do not find information needed, will record result without this and be assigned to return function and call for upper strata.
(5) adjust Adelson-Velskii-Landis tree.The insertion of Adelson-Velskii-Landis tree and deletion action all can exert an influence to tree structure, cause balance factor bf(balance factor) be greater than 1 or be less than-1, in order to keep minimum to the time complexity of tree, be log 2n, need to carry out equilibrating adjustment to tree, to tree-like adjustment, can divide following four kinds of situations:
1. the L-type of balanced binary tree rotation, when Adelson-Velskii-Landis tree inserts (inserting node in the left child's of minimum subtree root node left subtree) or deletion action (node of deletion is the right child of minimum subtree root node and is leaf node), and the bf that meets minimum subtree is greater than at 1 o'clock, need to carry out the structure that L-type rotates to regulate Adelson-Velskii-Landis tree.
With reference to Fig. 5, when inserting C ntime, cause the bf of the root node A of minimum subtree to become 2, need to carry out L rotation and adjust, first by B rthe root node that is promoted to new subtree, A drops to B rright child, simultaneously by B lrotate to be B rleft child, B drops to B lright child; When deleting node A rtime, cause the bf of the root node A of minimum subtree to become 2, need to carry out L rotation and adjust, by B rbe promoted to minimum subtree root node, A rotates to be B rright child, B rotates to be B rleft child.
2. the R type of balanced binary tree rotation, when Adelson-Velskii-Landis tree inserts (inserting node in the right child's of minimum subtree root node right subtree) or deletion action (node of deletion is the left child of minimum subtree root node and is leaf node), and the bf that meets minimum subtree root node is less than at-1 o'clock, need to carries out the rotation of R type and adjust.
With reference to Fig. 6, when inserting C ntime, cause the bf of the root node A of minimum subtree to become-2, need to carry out R rotation and adjust; First promote the root node that B is minimum subtree, A drops to the left child of B, by B lrotate to be the right child of A; When deleting A ltime, cause the bf of the root node A of minimum subtree to become-2, need to carry out R rotation, first promote the root node that B is minimum subtree, B lthe left child who rotates to be B, A rotates to be B lleft child.
3. the LR type of balanced binary tree rotation, when balanced binary tree inserts (inserting node in the right child's of minimum subtree root node left subtree), meet simultaneously minimum subtree root node bf be less than-1 and its left child bf be greater than at 1 o'clock, need to carry out the structure that LR type rotates to regulate Adelson-Velskii-Landis tree.
With reference to Fig. 7, when inserting C ntime cause the bf of the root node A of minimum subtree become-2 and the bf of its left child B become 2, need to carry out LR rotation and adjust, first carry out L rotation, by C lbe promoted to the root node of right subtree, C rrotate to be C lright child, C rotates to be C rleft child, B rotates to be C rright child; Now carry out R rotation, the root node that lifting C is minimum subtree, left child and C that A is C lrotate to be the right child of A, B rotates to be the right child of C, C rrotate to be the left child of B.
4. the RL type of balanced binary tree rotation, when balanced binary tree inserts (inserting node in the left child's of minimum subtree root node right subtree), the bf that simultaneously meets minimum subtree root node be greater than 1 and its right child bf be less than at-1 o'clock; Need to carry out the structure that LR type rotates to regulate Adelson-Velskii-Landis tree.
With reference to Fig. 8, when inserting C ntime cause the bf of the root node A of minimum subtree become 2 and the bf of its left child B become-2, need to carry out RL rotation and adjust, first carry out R rotation, C is promoted to the root node of left subtree, B drops to the left child of C, by C lrotate to be the right child of B; Now carry out L rotation, C is promoted to the root node of minimum subtree, A drops to the right child of C, by C rrotate to be the left child of A.
(6) traversal of Adelson-Velskii-Landis tree under actual conditions, the Adelson-Velskii-Landis tree that is 50000 for continuous and full nodal point number, its total L=log 250000< log 265536=16 level node, CL is current progression, D cLfor the layer of current progression node is apart from poor; The traversal formula of so all nodes is: root node Pr=2 l-1, the father node of current node is P f, its left child P l=P f-D cL, its right child P r=P f+ D cL, D cL=2 l-CL-1, CL ∈ [1, L).
When needs are found node sequence number and are 20000, i.e. n =20000, by 2 14<20000<2 15=32768 is known, and destination node, in the left subtree of root node, is searched P for the first time l=32768-2 14=16384, P r=32768+2 14=49152; Obviously destination node, in its left subtree, is searched P for the second time l=16384-2 13=8192, P r=16384+2 13=24576; Obviously destination node, in its right subtree, is searched P for the third time l=24576-2 12=20480, P r=24576+2 12=28672; Carry out the 4th time and search P l=20480-2 11=18332, P r=20480+2 11=22528; Carry out P the 5th time l=18332-2 10=17284, P r=18332+2 10=19880; Carry out P the 6th time l=19880-2 9=19368, P r=19880+2 9=20392; Carry out P the 7th time l=20392-2 8=20136, P r=20392+2 8=20648; Carry out P the 8th time l=20136-2 7=20008, P r=20136+2 7=20264; Carry out P the 9th time l=20008-2 6=19944, P r=20008+2 6=20072; Carry out P the tenth time l=19944-2 5=19912, P r=19944+2 5=19976; Carry out the tenth once, P l=19976-2 4=19960, P r=19976+2 4=19992; Carry out P the 12 time l=19992-2 3=19984, P r=19992+2 3=20000; Now find needed destination node.
The present invention has announced a kind of data based on sort feature and balanced binary tree storage, querying method, and above-mentioned example has provided the whole procedure based on inorder traversal, and the method based on preorder and postorder traversal of providing is below respectively as Fig. 9 and Figure 10.
What Fig. 9 announced is the storage node composition based on preorder traversal Adelson-Velskii-Landis tree, be with inorder traversal storage organization difference, when data message is stored and inquired about, be to travel through according to the order of root left and right, the traversal formula of so all nodes is: root node Pr=1, the father node of current node is P f, its left child P l=P f+ 1, its right child P r=P f+ D cL, D cL=2 l-CL, CL ∈ [1, L).
What Figure 10 announced is the storage node composition based on postorder traversal Adelson-Velskii-Landis tree, and its storage of traversal order according to left and right root and inquiry Adelson-Velskii-Landis tree differently with middle order from preorder are that the traversal formula of its node is: root node Pr=2 l-1, the father node of current node is P f, its left child P l=P f-D cL, its right child P r=P f-1, D cL=2 l-CL, CL ∈ [1, L).
In above-mentioned example, in the situation that memory source is 8M, requiring nodal point number N is 50000, and applying so its height H of setting up binary tree of Adelson-Velskii-Landis tree is log 250000< log 265536=16, i.e. height of tree h=16, the time complexity of search tree is also 16 so, finds so any one node and need to access at most internal memory 16 times.For 10000000 data recording of 50000 nodes, on average each node is 200, then these 200 recorded informations are carried out to binary search, and algorithm complex is also O (log 2200) ﹤ 8, namely can determine the data that will search maximum 8 times.
The orderly Adelson-Velskii-Landis tree structure of the method utilization is stored data message and inquire about by sort feature, and the time complexity that makes the Adelson-Velskii-Landis tree of its storage node class is O (log 2n), search specifying information simultaneously and adopt and data to be loaded into buffer area to utilize dichotomy to complete, its time complexity is also O (log 2n), its algorithm complex of more current conventional querying method is minimum, has greatly improved search efficiency, saves query time, has reduced internal storage access number of times, has reduced energy consumption.Utilize the storage mode of binary tree index simultaneously, saved the memory headroom (8b * N, N nodal point number) of storage binary tree front and back pointers, realize dynamically and inserting, distributed flexibly resource space, improved memory usage.

Claims (4)

1. the storage of the data based on sort feature and balanced binary tree, a querying method, is characterized in that, comprises the following steps:
1.1 build balanced binary tree, create node;
1.2 according to the rule of traversal, dynamically data information memory is arrived to corresponding node;
1.3 inputs need the information of inquiry, dynamically travel through balanced binary tree, until find required data message or traveled through balanced binary tree, return and search unsuccessfully;
Described balanced binary tree is orderly, according to the traversal rule of middle order, preorder or postorder, dynamically data information memory is arrived to corresponding node;
Continuous and full nodal point number is the balanced binary tree of n, its total L=log 2n level node, CL is current progression, D cLfor the layer of current progression node is apart from poor, layer is apart from poor poor for the nodal value between adjacent tree layer; The inorder traversal formula of so all nodes is: root node Pr=2 l-1, the father node of current node is P f, its left child P l=P f-D cL, its right child P r=P f+ D cL, D cL=2 l-CL-1, CL ∈ [1, L); Preorder traversal formula is: Pr=1, P l=P f+ 1, P r=P f+ D cL, D cL=2 l-CL, CL ∈ [1, L); Postorder traversal formula is: Pr=2 l-1, P l=P f-D cL, P r=P f-1, D cL=2 l-CL, CL ∈ [1, L)
Described step 1.1, realizes: first according to the achievement rule of balanced binary tree, building a nodes is n, and the height of tree is log as follows 2the balanced binary tree of n, then increases node, and each node represents a feature class C 1, C 2, C 3, C 4c n, the information that each node comprises a class refinement;
Described step 1.2, the insertion to data message, carries out the insertion of data message to node according to the traversal rule of middle order, preorder or postorder, adjust the tree structure of balanced binary tree simultaneously, is divided into and utilizes C Plus Plus form to realize and utilize C linguistic form to realize:
1. C Plus Plus form realizes: adopt VECTOR class in C Plus Plus as data store organisation in node, when having data message to store, first to judge whether balanced binary tree is empty; If so, a newly-built root node data message is saved in to root node returns simultaneously and preserve successfully; If not, travel through balanced binary tree, judge whether it belongs to storage node; If so, according to the rule of storage information, the information that needs are preserved is saved in corresponding node, and returns and preserve successfully; If not, perform step 1.1, then the data message of required preservation is saved in newly-built node, finally by return function, saving result is returned for calling on upper strata;
2. C language is realized: utilize structure variable to build a structure struct, all nodes adopt the storage organization of doubly linked list, by all operations of node being defined as to the member variable of structure, when having data message to preserve, first judge whether balanced binary tree is empty; If so, a newly-built root node data message is saved in to root node returns simultaneously and preserve successfully; If not, travel through balanced binary tree, determine whether storage node class; The corresponding preservation of preservation member object execution of if so, calling structure operates and returns preserves successfully; If not, perform step 1.1, then the data message of required preservation is saved in newly-built node class, finally by return function, saving result is returned for calling on upper strata;
The inquiry of node data message in described step 1.3, by the data message in node is read in buffer zone, utilizes binary search, is divided into and utilizes C Plus Plus form to realize and utilize C linguistic form to realize:
1. C Plus Plus is realized: when input inquiry information, first judge whether balanced binary tree is empty; If so, directly return to tree for empty; If not, travel through balanced binary tree, determine whether storage node; If so, continue access node information, and node information is loaded into buffer memory. district, utilizes dichotomy to search, and Query Result is called for upper strata to return function; If not, return without node class to return function;
2. C language is realized: utilize structure variable to remove to build a structure struct, all nodes adopt the storage organization of doubly linked list, will all operations of node be defined as to the member object of structure; When needs data query information, first judge whether balanced binary tree is empty; If so, directly return to tree for empty; If not, travel through balanced binary tree, determine whether storage node; If so, call the query manipulation member object of structure and carry out corresponding query manipulation, continue the refinement information in access node class, until inquire results needed or inquired about all recorded informations, and Query Result is assigned to return function for upper strata, calls; If not, return without node class and call for upper strata to return function.
2. data based on sort feature and balanced binary tree storage according to claim 1, querying method, is characterized in that, nodal point number is the form storage of C language or C Plus Plus according to this.
3. data storage, the querying method based on sort feature and balanced binary tree according to claim 1, is further characterized in that, the deletion action of balanced binary tree is divided into two classes, deletes node and deletes the data in node; First the data message of preserving the mode of deletion during deletion and needing to delete, then calls the AVLTreeDeleteStyle function that obtains deletion mode, concrete minute following two kinds of situations:
1. when AVLTreeDeleteStyle value is for deleting node C itime, directly travel through balanced binary tree, inquire about the node C of required deletion iif, traveled through all nodes and do not found, return without this node deletion failure; If find direct deletion node C i, and return and delete successfully; Finally deletion result is assigned to return function and calls for upper strata, adjust the tree structure of balanced binary tree simultaneously;
2. when AVLTreeDeleteStyle value is for deleting node C iin data time, first travel through balanced binary tree, inquiry node C i, traveled through all nodes and do not found to return without this node information and delete unsuccessfully; If find the node C of required deletion i, continue to search the information in node, until find required deletion data, by its deletion and return and delete successfully; Or inquired about all records and do not found information needed, returned without data recording and delete unsuccessfully; Finally deletion result being assigned to return function calls for upper strata.
4. data storage, the querying method based on sort feature and balanced binary tree according to claim 3, is characterized in that, balanced binary tree is carried out to equilibrating adjustment, is divided into following four kinds of situations:
1. the L-type of balanced binary tree rotation, when balanced binary tree inserts and insert node in the left child's of minimum subtree root node left subtree, or the node of deletion action and deletion is the right child of minimum subtree root node and when the leaf node, and the balance factor bf that meets minimum subtree is greater than at 1 o'clock, need to carry out the structure that L-type rotates adjustment binary tree;
2. the R type of balanced binary tree rotation, when balanced binary tree inserts and insert node in the right child's of minimum subtree root node right subtree, or the node of deletion action and deletion is the left child of minimum subtree root node and when the leaf node, and the balance factor bf that meets minimum subtree root node is less than at-1 o'clock, need to carry out the structure that R type rotates adjustment binary tree;
3. the LR type of balanced binary tree rotation, when balanced binary tree inserts and insert node in the right child's of minimum subtree root node left subtree time, the balance factor bf that simultaneously meets minimum subtree root node be less than-1 and its left child's balance factor bf be greater than at 1 o'clock, need to carry out the structure that LR type rotates adjustment binary tree;
4. the RL type of balanced binary tree rotation, when balanced binary tree inserts and insert node in the left child's of minimum subtree root node right subtree time, the balance factor bf that simultaneously meets minimum subtree root node be greater than 1 and its right child's balance factor bf be less than at-1 o'clock; Need to carry out the structure that RL type rotates adjustment binary tree.
CN201110403732.1A 2011-12-07 2011-12-07 Data storage and query method based on classification characteristics and balanced binary tree Expired - Fee Related CN102521334B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201110403732.1A CN102521334B (en) 2011-12-07 2011-12-07 Data storage and query method based on classification characteristics and balanced binary tree

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201110403732.1A CN102521334B (en) 2011-12-07 2011-12-07 Data storage and query method based on classification characteristics and balanced binary tree

Publications (2)

Publication Number Publication Date
CN102521334A CN102521334A (en) 2012-06-27
CN102521334B true CN102521334B (en) 2014-03-12

Family

ID=46292251

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201110403732.1A Expired - Fee Related CN102521334B (en) 2011-12-07 2011-12-07 Data storage and query method based on classification characteristics and balanced binary tree

Country Status (1)

Country Link
CN (1) CN102521334B (en)

Families Citing this family (22)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103580882A (en) * 2012-07-18 2014-02-12 上海斐讯数据通信技术有限公司 Operation method for light node management entity, and GPON system
CN103116641B (en) * 2013-02-21 2016-05-11 新浪网技术(中国)有限公司 Obtain method and the collator of the statistics of sequence
CN103984708B (en) * 2014-04-29 2017-11-28 暨南大学 The emergent decomposition method for sorting and system of catastrophe risk big data processing
CN105335411A (en) * 2014-07-31 2016-02-17 国际商业机器公司 Method and system for data processing
CN104486259A (en) * 2014-12-16 2015-04-01 上海斐讯数据通信技术有限公司 Switch configuration file storage method, and switch configuration file storage system
CN104462585A (en) * 2014-12-29 2015-03-25 芜湖乐锐思信息咨询有限公司 Large data classification system
CN105787083A (en) * 2016-03-02 2016-07-20 深圳市元征科技股份有限公司 Data processing method and device
CN106302177A (en) * 2016-08-23 2017-01-04 杭州迪普科技有限公司 The method for organizing of a kind of route filtering rule and device
CN106570056A (en) * 2016-09-28 2017-04-19 深圳盒子支付信息技术有限公司 Database implementation method and database
CN107153707B (en) * 2017-05-12 2020-08-14 华中科技大学 Hash table construction method and system for nonvolatile memory
CN109766565A (en) * 2018-10-31 2019-05-17 中国飞机强度研究所 A kind of lever system automated construction method
CN109710860B (en) * 2018-12-21 2021-07-27 武汉思普崚技术有限公司 URL (Uniform resource locator) classification matching method and device
CN109710542B (en) * 2018-12-28 2021-03-16 北京像素软件科技股份有限公司 Full N-way tree construction method and device
CN109815238B (en) * 2019-01-18 2021-09-28 武汉轻工大学 Method and device for realizing dynamic addition of database by strictly balanced binary tree
CN110134834B (en) * 2019-05-15 2023-06-09 四川新网银行股份有限公司 Method for accelerating IP positioning by using dynamic AVL forest cache
CN110213643B (en) * 2019-06-11 2023-03-24 北京奇艺世纪科技有限公司 Streaming media caching method and device and terminal equipment
CN110647907B (en) * 2019-08-05 2023-04-07 广东工业大学 Multi-label image classification algorithm using multi-layer classification and dictionary learning
CN111026765B (en) * 2019-12-16 2023-07-14 武汉轻工大学 Dynamic processing method, device, storage medium and apparatus for strictly balanced binary tree
CN112102930A (en) * 2020-02-10 2020-12-18 云池网络科技(上海)有限公司 Internet of things intelligent home-based old-age care large-screen information system
CN112712850A (en) * 2020-12-29 2021-04-27 中南大学 Seed sequence positioning method applicable to infectious disease pathogen sequencing read mapping
CN113778948A (en) * 2021-09-01 2021-12-10 中国人民银行清算总中心 Message persistent storage method and device
CN115134113B (en) * 2022-05-13 2024-04-09 山东鲁软数字科技有限公司 Platform data security authentication method, system, terminal and storage medium

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101419630B (en) * 2008-12-11 2011-03-23 中国科学院计算技术研究所 Top-k item digging method and system in data flow
CN101504668B (en) * 2009-03-24 2010-12-01 北京理工大学 Cryptograph index supported database transparent encryption method
CN101739462B (en) * 2009-12-31 2012-11-28 中兴通讯股份有限公司 Extensible markup language coding method, decoding method and client

Also Published As

Publication number Publication date
CN102521334A (en) 2012-06-27

Similar Documents

Publication Publication Date Title
CN102521334B (en) Data storage and query method based on classification characteristics and balanced binary tree
CN105320775B (en) The access method and device of data
CN104809190B (en) A kind of database access method of tree structure data
US20160283538A1 (en) Fast multi-tier indexing supporting dynamic update
EP2924594A1 (en) Data encoding and corresponding data structure in a column-store database
US6859808B1 (en) Mapping logical row identifiers for primary B+tree-like structures to physical row identifiers
US11789923B2 (en) Compression units in an index block
JP2002501256A (en) Database device
CN106682110B (en) Image file storage and management system and method based on Hash grid index
CN107577436A (en) A kind of date storage method and device
US8015195B2 (en) Modifying entry names in directory server
KR101400214B1 (en) Appratus for providing a hybrid c interface
CN106599091B (en) RDF graph structure storage and index method based on key value storage
US11294816B2 (en) Evaluating SQL expressions on dictionary encoded vectors
EP3767486B1 (en) Multi-record index structure for key-value stores
CN106599040A (en) Layered indexing method and search method for cloud storage
CN108717448B (en) Key value pair storage-oriented range query filtering method and key value pair storage system
KR101955376B1 (en) Processing method for a relational query in distributed stream processing engine based on shared-nothing architecture, recording medium and device for performing the method
Bercea et al. Fully-dynamic space-efficient dictionaries and filters with constant number of memory accesses
CN107273443B (en) Mixed indexing method based on metadata of big data model
Vassilakopoulos et al. Dynamic inverted quadtree: A structure for pictorial databases
CN110413724A (en) A kind of data retrieval method and device
Kvet Database Block Management using Master Index
CN114579537A (en) Distributed graph database optimization method and device, electronic equipment and storage medium
CN1235169C (en) Data storage and searching method of embedded system

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CF01 Termination of patent right due to non-payment of annual fee
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20140312

Termination date: 20211207