CN116680252A - Tree data structure and node batch moving method thereof - Google Patents

Tree data structure and node batch moving method thereof Download PDF

Info

Publication number
CN116680252A
CN116680252A CN202310701340.6A CN202310701340A CN116680252A CN 116680252 A CN116680252 A CN 116680252A CN 202310701340 A CN202310701340 A CN 202310701340A CN 116680252 A CN116680252 A CN 116680252A
Authority
CN
China
Prior art keywords
node
value
nodes
field
ordering
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.)
Pending
Application number
CN202310701340.6A
Other languages
Chinese (zh)
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.)
Zhiyan Gongsoft (Hangzhou) Technology Co.,Ltd.
Zhiyanhui Shanghai Technology Co ltd
Original Assignee
Zhiyanhui Hangzhou Technology Co ltd
Zhiyanhui Shanghai Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhiyanhui Hangzhou Technology Co ltd, Zhiyanhui Shanghai Technology Co ltd filed Critical Zhiyanhui Hangzhou Technology Co ltd
Priority to CN202310701340.6A priority Critical patent/CN116680252A/en
Publication of CN116680252A publication Critical patent/CN116680252A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/21Design, administration or maintenance of databases
    • G06F16/214Database migration support
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2246Trees, e.g. B+trees

Landscapes

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

Abstract

The application belongs to the technical field of data processing, and particularly relates to a tree-shaped data structure and a node batch moving method thereof. The tree data structure comprises a plurality of nodes, wherein each node comprises a father node ID field, a node level field and a sequencing value field, and the data type of the sequencing value field is an N-system character string type; the tree data structure starts with a root node, and according to a preset ordering rule of ordering value fields, ordering value fields of nodes of each layer are respectively assigned according to a hierarchy, the ordering value fields of two adjacent nodes in the same layer are different by N/2, and two nodes in different layers are allowed to have the same ordering value field. After the tree data structure is adopted, when the node position is changed, only the sorting value of the current node and the connection (PID) of the upper node are required to be changed, and other associated nodes are not required to be changed, so that the algorithm efficiency can be remarkably improved.

Description

Tree data structure and node batch moving method thereof
Technical Field
The application belongs to the technical field of data processing, and particularly relates to a tree-shaped data structure and a node batch moving method thereof.
Background
Existing tree data structures whose nodes typically include data structures of node ID fields, node name fields, parent node ID fields, etc., do not achieve a good ordering function. Thus, as shown in fig. 1, the tree data structure supporting ordering includes a node level field and an ordering value field when defining the data structure of a plurality of nodes, the node level field represents the hierarchical relationship of the current node relative to the root node, and the ordering value field represents the absolute position of the current node in the tree data structure. The node level field and the order value field are typically of a shaping type, the values of which may be natural numbers of orders. When the tree data structure is to be ordered, the tree data structure is ordered only by ascending or descending the order of the order value field.
While this technique works well when rendering nodes, it is problematic when modifying node locations. As shown in fig. 2, in a tree data structure, the ordering value fields of nodes a to D are defined as 1 to 4, respectively. If it is necessary to move node D between nodes A and B, the following steps are required:
1. all nodes between node a and node D, e.g., node B and node C, are found.
2. The ordering values of node B and node C are modified (e.g., in this example, their ordering values need to be increased by 1).
3. The sorting value of the node D is modified to the original sorting value of the node B or modified to the sorting value of the node A plus 1.
In this process, there are the following problems:
first, if there are a large number of nodes between node A and node D, modifying the ordering value of the nodes between them would be a resource consuming operation.
Second, in the case where a plurality of users perform concurrent operations at the same time, it is necessary to lock the operations. If the execution of step 1 is very time consuming, it may result in the entire system being locked.
Finally, processing logic is more complex when moving across node levels.
Disclosure of Invention
The application aims at the technical problems and aims at providing a tree-shaped data structure and a node batch moving method thereof.
In order to solve the above-mentioned problems, according to an aspect of the present application, there is provided a tree-shaped data structure including a plurality of nodes including a parent node ID field, a node level field, and an ordering value field, the data type of the ordering value field being a string type of N-ary;
the tree data structure starts with a root node, and according to a preset ordering rule of ordering value fields, the ordering value fields of the nodes of each layer are respectively assigned according to a hierarchy, the ordering value fields of two adjacent nodes in the same layer are different by N/2, and two nodes in different layers are allowed to have the same ordering value field.
Optionally, in the tree data structure, the ordering value field of the first node of the same layer of nodes is a preset ordering value.
In order to solve the above problem, according to another aspect of the present application, there is provided a node batch moving method based on the tree data structure of the present application, including:
and acquiring the sequence values of the upper node and the lower node of the target position, taking the value between the sequence values of the upper node and the lower node, obtaining a new sequence value of the node to be moved, modifying the new sequence value, and completing the movement.
Optionally, a median algorithm is adopted to take the value between the sorting values of the upper node and the lower node, and the median algorithm is as follows:
dividing the difference between the sorting values of the upper node and the lower node by 2 to form a whole, obtaining a new sorting value of the node to be moved and modifying the new sorting value.
Optionally, when the difference between the ordering values of the upper node and the lower node is divided by 2 and rounded, and the obtained value is 0, modifying the character string length of the new ordering value field of the node to be moved, wherein the modifying method is as follows:
and rounding N/2 as a target character to be added, adding the target character after the sequence value field of the previous node or the next node according to the sequence rule of the sequence value field, obtaining a new sequence value of the node to be moved and modifying.
Optionally, when the ranking values of the upper node and the lower node of the target position are obtained, if the upper node of the target position does not exist, the node to be moved is considered to be moved to the first node of the current layer, at this time, a first ranking value generating algorithm is adopted to obtain a new ranking value of the node to be moved and modify the new ranking value, and the first ranking value generating algorithm is as follows:
and taking N/2 as a target value, subtracting or adding the target value to the ordering value field of the next node according to the ordering rule of the ordering value field, obtaining a new ordering value of the node to be moved, and modifying.
Optionally, when the sorting values of the upper node and the lower node of the target position are obtained, if the next node of the target position does not exist, the node to be moved is considered to be moved to the tail node of the current layer, at this time, a tail sorting value generating algorithm is adopted to obtain a new sorting value of the node to be moved and modify the new sorting value, and the tail sorting value generating algorithm is as follows:
and taking N/2 as a target value, adding or subtracting the target value to the sequence value field of the last node according to the sequence rule of the sequence value field, obtaining a new sequence value of the node to be moved, and modifying.
Optionally, when the target value is added or subtracted to the sorting value field, if the rightmost bit is greater than the maximum value of the sorting value field, the bit is advanced according to the N-ary rule, and if the rightmost bit is less than the minimum value of the sorting value field, the bit is borrowed forward according to the N-ary rule.
Optionally, before or after obtaining the new ranking value of the node to be moved and modifying, further performing:
judging whether the father node ID field of the target position is the same as the father node ID field of the node to be moved, if so, modifying the father node ID field of the node to be moved into the father node ID field of the target position.
Optionally, after obtaining a new ordering value of the node to be moved and modifying, judging whether the first node of the current layer reaches a preset rearrangement value, if so, triggering a reordering algorithm, wherein the reordering algorithm is as follows:
locking the current layer, acquiring all nodes of the current layer, and carrying out assignment on the sequence value fields of all the nodes of the current layer according to the sequence rule of the preset sequence value fields, wherein the sequence value fields of two adjacent nodes differ by N/2.
The beneficial effects are that: in a conventional tree data structure, when the position of a node changes, the subtree of the node needs to be readjusted to ensure that the entire tree structure is still correct. This process requires traversing the entire subtree and reordering each node, which can result in a significant reduction in the efficiency of the algorithm. After the tree data structure is adopted, when the node position is changed, only the sorting value of the current node and the connection (PID) of the upper node are required to be changed, and other associated nodes are not required to be changed, so that the algorithm efficiency can be remarkably improved. Particularly, under the condition of larger data volume, the time complexity of the algorithm can be greatly reduced, and the performance and efficiency of the algorithm are improved.
Drawings
FIG. 1 is a schematic diagram of a node of a tree data structure in the prior art;
FIG. 2 is a diagram of a prior art node movement process;
FIG. 3 is a schematic diagram of a node of the tree data structure of the present application;
FIG. 4 is a schematic diagram of a string size;
fig. 5 is a diagram of a node movement process according to embodiments 1 to 3 of the present application.
Description of the embodiments
The preferred embodiments of the present application will be described in detail below with reference to the attached drawings, so that the objects, features and advantages of the present application will be more clearly understood. It should be understood that the embodiments shown in the drawings are not intended to limit the scope of the application, but rather are merely illustrative of the true spirit of the application.
In the following description, for the purposes of explanation of various disclosed embodiments, certain specific details are set forth in order to provide a thorough understanding of the various disclosed embodiments. One skilled in the relevant art will recognize, however, that an embodiment may be practiced without one or more of the specific details. In other instances, well-known devices, structures, and techniques associated with the present application may not be shown or described in detail to avoid unnecessarily obscuring the description of the embodiments.
Reference throughout this specification to "one embodiment" or "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment is included in at least one embodiment. Thus, appearances of the phrases "in one embodiment" or "in an embodiment" in various places throughout this specification are not necessarily all referring to the same embodiment. Furthermore, the particular features, structures, or characteristics may be combined in any suitable manner in one or more embodiments.
In the following description, for the purposes of clarity of presentation of the structure and manner of operation of the present application, the description will be made with the aid of directional terms, but such terms as "forward," "rearward," "left," "right," "outward," "inner," "outward," "inward," "upper," "lower," etc. are to be construed as convenience, and are not to be limiting.
The tree data structure is an important nonlinear data structure, and can represent one-to-many relations among data table elements, so that the tree is visually defined as a hierarchical structure with branch relations. In computer science, trees are used to simulate data sets that have tree-structured properties. It is a set of n (n > 0) finite nodes that have a hierarchical relationship. It has the following characteristics: each node has zero or more child nodes; nodes without parent nodes are called root nodes; each non-root node has and has only one parent node; in addition to the root node, each child node may be divided into a plurality of disjoint sub-trees.
Referring to FIG. 3, an embodiment of the present application provides a tree data structure comprising a number of nodes, including a root node and other nodes. Each node includes a node ID field (ID), a node name field (name), a parent node ID field (pid), a node level field (level), and a rank value field (rank).
Wherein the node ID field and the parent node ID field are typically of a long integer data type, and the node name field is typically of a string data type. Of course other data types are possible.
The node level field indicates the hierarchical relationship of the current node with respect to the root node. The data type of the node level field is an integer. The node level fields are ordered starting with the root node, and the node level field of the parent node in the tree data structure is smaller than or greater than the node level field of the next node by 1. According to the habit, a mode that the node level field of the parent node is smaller than the node level field of the lower node thereof by 1 is generally adopted, but a mode that the node level field of the parent node is larger than the node level field of the lower node thereof by 1 is also possible. The hierarchy is ordered according to a preset rule.
For example, the node level field of the root node is 0, the node level field of the lower node of the root node is 1, and so on.
The rank value field indicates the position of the current node in the tree data structure, independent of the hierarchy, which is the absolute position of the current node on the entire tree. The data type of the sort value field is an N-ary character string. The N-system herein may be binary, octal, decimal, hexadecimal, etc.
Referring to fig. 4, in a computer, a comparison of the sizes of character strings is generally determined by ASCII, and when comparing the sizes of two character strings, the following procedure is followed:
1. and (5) taking out the characters to transfer the first character, and comparing the sizes of ASCII codes.
2. And if the comparison results in the step 1 are the same, respectively taking out the second characters of the two character strings for comparison.
3. And sequentially processing until the first non-identical character is found, and determining the sizes of the two character strings according to the comparison result of the character.
4. If no different character is found until the end, it is determined that the two character strings are identical.
Based on the principle, the application utilizes the character string size principle when the node is moved, thereby realizing more convenient node movement.
In one embodiment, the data type of the rank value field is a string greater than decimal.
The tree data structure of the application starts with a root node, and according to the ordering rule of the preset ordering value fields, the ordering value fields of the nodes of each layer are respectively assigned according to the hierarchy, the ordering value fields of two adjacent nodes in the same layer are different by N/2, and two nodes in different layers are allowed to have the same ordering value field.
Nodes with the same node level field are considered to be nodes of the same layer. The ordering of the ordering value field is to acquire a plurality of nodes of the same layer for the plurality of nodes of the same layer, and the plurality of nodes are sequentially assigned according to the absolute positions in the tree data structure according to the ordering rule.
The ordering rule of the ordering value field may be that the ordering rule is increased from the first node in the same layer of nodes, or may be that the ordering rule is decreased from the first node in the same layer of nodes.
According to the habit, it is preferable to employ an ordering rule that increases in order from the first node.
For example, if the node level field and the ranking value field of the root node are both 0, the node level field of all child nodes of the root node is assigned 1, and the ranking value field is assigned according to the absolute position of the root node, for example, a string of 1,2, … ….
The ordering value field of the root node can be assigned as AAAA0, the first child node in the root node position is used as the first node of the layer with the node level of 1, the ordering value field of the root node can be assigned as AAAA0, and other nodes can be assigned in sequence according to the absolute positions of the child nodes in the tree data structure.
The application adopts the mode that the sequence value fields of two adjacent nodes in the same layer differ by N/2, so that enough other character strings which can be inserted are arranged between the sequence values of the two adjacent nodes, and the movement of the nodes can be greatly facilitated.
In an embodiment, in the tree data structure, the ordering value field of the first node of the same layer of nodes is a preset ordering value.
The preset ranking value may be determined according to the number of nodes in the selected N-ary and tree data structures, and preferably takes a relatively intermediate value, so as to facilitate the forward or backward insertion of the nodes to be moved.
For example, when the data type of the ordering value field is hexadecimal and the number of nodes is small, the ordering value of the head node may be A0, AA0, AAA0 or the like, but when the number of nodes is large, it may be AAAA0 or AAAAA0 or the like.
The embodiment of the application provides a node batch moving method of a tree-shaped data structure, which is based on the tree-shaped data structure of each embodiment as an initial tree-shaped data structure and comprises the following steps:
and acquiring the sequence values of the upper node and the lower node of the target position, taking the value between the sequence values of the upper node and the lower node, obtaining a new sequence value of the node to be moved, modifying the sequence value field of the node to be moved, and completing the movement of the node to be moved.
Based on the principle of the size of the character string, the new sorting value of the node to be moved is set as a value between the sorting values of the upper node and the lower node of the target position, so that the absolute position of the node is between the upper node and the lower node without modifying the sorting values of other nodes.
Taking hexadecimal as an example, the data type of the sorting value field is that the sorting values of the upper node and the lower node of the target position are respectively AAAA0 and AAAA8, and the new sorting value of the node to be moved only needs to take any value between AAAA0 and AAAA8, for example, take AAAA1, AAAA2, AAAA3 … …, AAAA7 or the like.
In one embodiment, a median algorithm is used to take the value between the ordering values of the upper and lower nodes, where the median algorithm is:
dividing the difference between the sorting values of the upper node and the lower node by 2 to form a whole, obtaining a new sorting value of the node to be moved and modifying the new sorting value.
For example, the ranking values of the upper node and the lower node of the target position are respectively 0 and 5, the difference between the ranking values of the upper node and the lower node is divided by 2, and the obtained value is 2, and the new ranking value of the node to be moved is 2.
In an embodiment, when the difference between the ordering values of the upper node and the lower node is divided by 2 and rounded, and the obtained value is 0, the character string length of the new ordering value field of the node to be moved is modified, and the modification method is as follows:
and rounding N/2 as a target character to be added, adding the target character after the sequence value field of the previous node or the next node according to the sequence rule of the sequence value field, obtaining a new sequence value of the node to be moved and modifying.
For example, the ranking values of the upper and lower nodes of the target position are 2 and 3, respectively, the difference between the ranking values of the upper and lower nodes is divided by 2, and the obtained value is 0. At this time, the length of the character string needs to be modified, i.e., the length of the generated median increases. Taking hexadecimal as an example, 16 is divided by 2 to form a whole to obtain 8 as a target character. And as the ordering rule is that the ordering rules are increased from the first node in sequence, the target character is added after the ordering value field of the last node, so that a new ordering value of the node to be moved is obtained and is modified to be 28. The final sorting values of the three adjacent nodes are 2, 28 and 3 respectively.
If the sorting values of the upper node and the lower node of the target position are 3 and 2 respectively, the sorting rule is that the sorting values are sequentially reduced from the first node, the target character is added after the sorting value field of the next node, and a new sorting value of the node to be moved is obtained and modified to be 28. The final sorting values of the three adjacent nodes are 3, 28 and 2 respectively.
In an embodiment, when the ranking values of the upper node and the lower node of the target position are obtained, if the upper node of the target position does not exist, the node to be moved is considered to be moved to the first node of the current layer, at this time, a first ranking value generating algorithm is adopted to obtain a new ranking value of the node to be moved and modify the new ranking value, and the first ranking value generating algorithm is as follows:
n/2 is rounded as a target value, and the target value is subtracted or added to the sequencing value field of the next node according to the sequencing rule of the sequencing value field, so that a new sequencing value of the node to be moved is obtained and modified.
For example, taking hexadecimal and ordering rules as examples which are increased from the first node in sequence, dividing 16 by 2 to obtain a target value of 8;
1. the ordering value of the head node D generated at a certain level is AAAA0;
2. inserting a node C above the node D, wherein the sorting value of the node C is AAA98;
3. inserting a node B above the node C, wherein the sorting value of the node B is AAA90;
4. inserting a node A above the node B, wherein the sorting value of the node A is AAA88;
every time a node is inserted up, its rank value is subtracted by 8 from the rank value of the previous node, if it is already less than the minimum value of each bit (0), then the forward borrow is 16 in a bin.
If the ordering rule is that the ordering rule is sequentially reduced from the first node, a node C is inserted above the node D, the ordering value of the node C is AAAA8, and the like.
In an embodiment, when the ranking values of the upper node and the lower node of the target position are obtained, if the next node of the target position does not exist, the node to be moved is considered to be moved to the tail node of the current layer, at this time, a new ranking value of the node to be moved is obtained and modified by adopting an end ranking value generating algorithm, and the end ranking value generating algorithm is as follows:
and taking N/2 as a target value, adding or subtracting the target value from the sequence value field of the last node according to the sequence rule of the sequence value field, obtaining a new sequence value of the node to be moved, and modifying.
For example, taking hexadecimal and ordering rules as examples which are increased from the first node in sequence, dividing 16 by 2 to obtain a target value of 8;
1. the sorting value of the head node A generated at a certain level is AAAA0;
2. inserting a node B below the node A, wherein the sorting value of the node B is AAAA8;
3. inserting a node C below the node B, wherein the sorting value of the node C is AAAB0;
4. inserting a node D below the node C, wherein the sorting value of the node D is AAAB8;
for each node added, the sorting value of the node is added by 8 above the sorting value of the previous node, and if the sorting value is already greater than the maximum value (F) of each bit, the sorting value is carried forward in 16 scale.
If the ordering rule is decreasing from the first node, a node B is inserted below the node A, its ordering value is AAA98, and so on.
In an embodiment, before or after obtaining the new ranking value of the node to be moved and modifying, further performing:
judging whether the father node ID field of the target position is the same as the father node ID field of the node to be moved, if so, modifying the father node ID field of the node to be moved into the father node ID field of the target position.
When there is a cross-hierarchy mobile scenario, the original parent node ID field of the node to be moved is different from the parent node ID field of the target location, and thus the parent node ID field of the node to be moved needs to be modified. Modifying the parent node ID field may occur before or after the ranking value calculation.
In an embodiment, after obtaining a new ranking value of the node to be moved and modifying, determining whether the first node of the current layer reaches a preset ranking value, if so, triggering a reordering algorithm, where the reordering algorithm is as follows:
locking the current layer, acquiring all nodes of the current layer, and carrying out assignment on the sequence value fields of all the nodes of the current layer according to the sequence rule of the preset sequence value fields, wherein the sequence value fields of two adjacent nodes differ by N/2.
The preset rearrangement value of the present embodiment is preset, for example, a limit value of 0 is set, and other values near 0, such as A0, etc., may be set. On the premise of ensuring that the ordering value field of the tree data structure has the ordering according to the absolute position, the ordering value of each level cannot start from 0, if the first node becomes 0 or is close to 0 after a plurality of moving operations, the level data needs to be rearranged, and the reordering needs to be locked, namely the moving operation cannot be performed in the process.
Examples
Referring to fig. 5, the ordering value field of the tree data structure adopts hexadecimal character strings, the ordering rule is that the ordering value field is sequentially increased from the first node, a certain layer of the tree data structure is provided with nodes a to D, and the corresponding ordering values are CCC0, CCC8, CCD0 and CCD8 respectively.
The node D needs to be moved between the node a and the node B, and the following operations are required:
1. obtaining the PID of the node D (the PID can be obtained by finding the node D on a graphical interface and pressing a left mouse button to select the node D);
2. obtaining the PID of the target position, the rank value of the node A and the rank value of the node B (the PID and the rank values of the node A and the node B can be respectively obtained by dragging the node D between the node A and the node B under the condition of selecting the node D);
3. judging whether the PID of the node D is the same as the PID of the node A (or the PID of the node B), if so, indicating that the node D moves across the hierarchy, modifying the PID of the node D to the PID of the node A, and if so, not processing the PID;
4. calculating the median of the two values as CCC4 by using a median algorithm through the rank value of the node A and the rank value of the node B, and modifying the rank value of the node D as CCC4;
5. and re-rendering the node, and completing the operation.
The step 3 of determining PID, the step 4 of calculating and modifying the rank value may be vice versa.
Examples
Referring to fig. 5, the ordering value field of the tree data structure adopts hexadecimal character strings, the ordering rule is that the ordering value field is sequentially increased from the first node, a certain layer of the tree data structure is provided with nodes a to D, and the corresponding ordering values are CCC0, CCC8, CCD0 and CCD8 respectively.
Before the node D needs to be moved to the node a, the following operations are required:
1. obtaining the PID of the node D (the PID can be obtained by finding the node D on a graphical interface and pressing a left mouse button to select the node D);
2. obtaining the PID of the target position and the rank value of the node A (the PID and the rank value of the node A can be respectively obtained before dragging the node D to the node A under the condition of selecting the node D);
3. judging whether the PID of the node D is the same as the PID of the node A, if so, indicating that the node D moves across the hierarchy, modifying the PID of the node D to the PID of the node A, and if so, not processing the PID;
4. the rank value of the node D is modified to be CCB8 by adopting a rank value of the node A and adopting a first order value generation algorithm to calculate the generated value to be CCB8;
5. and re-rendering the node, and completing the operation.
The step 3 of determining PID, the step 4 of calculating and modifying the rank value may be vice versa.
Examples
Referring to fig. 5, the ordering value field of the tree data structure adopts hexadecimal character strings, the ordering rule is that the ordering value field is sequentially increased from the first node, a certain layer of the tree data structure is provided with nodes a to D, and the corresponding ordering values are CCC0, CCC8, CCD0 and CCD8 respectively.
After the node a needs to be moved to the node D, the following operations are required:
1. obtaining the PID of the node A (the PID can be obtained by finding the node A on a graphical interface and pressing a left mouse button to select the node A);
2. obtaining the PID of the target position and the rank value of the node D (the PID and the rank value of the node D can be respectively obtained after dragging the node A to the node D under the condition of selecting the node A);
3. judging whether the PID of the node A is the same as the PID of the node D, if so, indicating that the node A moves across the hierarchy, modifying the PID of the node A to the PID of the node D, and if so, not processing the PID;
4. calculating a generated value as CCE0 by adopting an end sorting value generation algorithm through the rank value of the node D, and modifying the rank value of the node A as CCE0;
5. and re-rendering the node, and completing the operation.
The step 3 of determining PID, the step 4 of calculating and modifying the rank value may be vice versa.
While the preferred embodiments of the present application have been described in detail, it will be appreciated that those skilled in the art, upon reading the above teachings, may make various changes and modifications to the application. Such equivalents are also intended to fall within the scope of the application as defined by the following claims.

Claims (10)

1. The tree-shaped data structure comprises a plurality of nodes, wherein each node comprises a father node ID field, a node level field and a sorting value field, and the data type of the sorting value field is an N-system character string type;
the tree data structure starts with a root node, and according to a preset ordering rule of ordering value fields, the ordering value fields of the nodes of each layer are respectively assigned according to a hierarchy, the ordering value fields of two adjacent nodes in the same layer are different by N/2, and two nodes in different layers are allowed to have the same ordering value field.
2. The tree data structure of claim 1, wherein the rank value field of the first node of the same level of nodes in the tree data structure is a preset rank value.
3. A method for batch movement of nodes based on the tree data structure of claim 1 or 2, comprising:
and acquiring the sequence values of the upper node and the lower node of the target position, taking the value between the sequence values of the upper node and the lower node, obtaining a new sequence value of the node to be moved, modifying the new sequence value, and completing the movement.
4. The method for batch movement of nodes in a tree data structure according to claim 3, wherein a median algorithm is adopted to take a value between the ordering values of the upper node and the lower node, and the median algorithm is as follows:
dividing the difference between the sorting values of the upper node and the lower node by 2 to form a whole, obtaining a new sorting value of the node to be moved and modifying the new sorting value.
5. The method for batch movement of nodes in tree data structure according to claim 4, wherein when the difference between the ordering values of the upper and lower nodes is divided by 2 and rounded, and the obtained value is 0, the character string length of the new ordering value field of the node to be moved is modified, and the modifying method is as follows:
and rounding N/2 as a target character to be added, adding the target character after the sequence value field of the previous node or the next node according to the sequence rule of the sequence value field, obtaining a new sequence value of the node to be moved and modifying.
6. The method for batch movement of nodes in tree data structure according to claim 3, wherein when the sorting values of the upper node and the lower node of the target position are obtained, if there is no upper node of the target position, the node to be moved is considered to be moved to the first node of the current layer, at this time, a first sorting value generating algorithm is adopted to obtain a new sorting value of the node to be moved and modify the new sorting value, and the first sorting value generating algorithm is as follows:
and taking N/2 as a target value, subtracting or adding the target value to the ordering value field of the next node according to the ordering rule of the ordering value field, obtaining a new ordering value of the node to be moved, and modifying.
7. The method for batch movement of nodes in tree data structure according to claim 3, wherein when the sorting values of the upper node and the lower node of the target position are obtained, if there is no next node of the target position, the node to be moved is considered to move to the tail node of the current layer, at this time, a new sorting value of the node to be moved is obtained and modified by adopting an end sorting value generating algorithm, and the end sorting value generating algorithm is as follows:
and taking N/2 as a target value, adding or subtracting the target value to the sequence value field of the last node according to the sequence rule of the sequence value field, obtaining a new sequence value of the node to be moved, and modifying.
8. The method for batch movement of nodes of a tree data structure according to claim 6 or 7, wherein when the target value is added or subtracted to the rank value field, if the rightmost bit is greater than the maximum value of the rank value field, the method advances according to the N-ary rule, and if the rightmost bit is less than the minimum value of the rank value field, the method advances according to the N-ary rule.
9. A method for batch movement of nodes in a tree data structure according to claim 3, wherein before or after obtaining the new ranking value of the nodes to be moved and modifying, further performing:
judging whether the father node ID field of the target position is the same as the father node ID field of the node to be moved, if so, modifying the father node ID field of the node to be moved into the father node ID field of the target position.
10. A method for batch movement of nodes in a tree data structure according to any one of claims 3 to 7 or 9, wherein after obtaining a new ranking value for the nodes to be moved and modifying, determining whether the first node of the current layer reaches a preset ranking value, if so, triggering a reordering algorithm, where the reordering algorithm is:
locking the current layer, acquiring all nodes of the current layer, and carrying out assignment on the sequence value fields of all the nodes of the current layer according to the sequence rule of the preset sequence value fields, wherein the sequence value fields of two adjacent nodes differ by N/2.
CN202310701340.6A 2023-06-13 2023-06-13 Tree data structure and node batch moving method thereof Pending CN116680252A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310701340.6A CN116680252A (en) 2023-06-13 2023-06-13 Tree data structure and node batch moving method thereof

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310701340.6A CN116680252A (en) 2023-06-13 2023-06-13 Tree data structure and node batch moving method thereof

Publications (1)

Publication Number Publication Date
CN116680252A true CN116680252A (en) 2023-09-01

Family

ID=87790569

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310701340.6A Pending CN116680252A (en) 2023-06-13 2023-06-13 Tree data structure and node batch moving method thereof

Country Status (1)

Country Link
CN (1) CN116680252A (en)

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2006054506A1 (en) * 2004-11-17 2006-05-26 Turbo Data Laboratories Inc. Tree data retrieving/accumulating/sorting method and program
CN102867059A (en) * 2012-09-19 2013-01-09 浪潮(北京)电子信息产业有限公司 Method and system for processing data in treelike structures
CN110309369A (en) * 2019-06-06 2019-10-08 福建天泉教育科技有限公司 A kind of implementation method and terminal of tree structure data
CN111767285A (en) * 2020-06-29 2020-10-13 四川阵风科技有限公司 Method for rapidly judging node relation
CN115221360A (en) * 2021-04-19 2022-10-21 奇安信科技集团股份有限公司 Tree structure configuration method and system
CN115840751A (en) * 2023-02-21 2023-03-24 山东经伟晟睿数据技术有限公司 Novel tree data coding method
CN115994141A (en) * 2022-12-06 2023-04-21 山东浪潮新基建科技有限公司 Tree-shaped coding method and system

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2006054506A1 (en) * 2004-11-17 2006-05-26 Turbo Data Laboratories Inc. Tree data retrieving/accumulating/sorting method and program
CN102867059A (en) * 2012-09-19 2013-01-09 浪潮(北京)电子信息产业有限公司 Method and system for processing data in treelike structures
CN110309369A (en) * 2019-06-06 2019-10-08 福建天泉教育科技有限公司 A kind of implementation method and terminal of tree structure data
CN111767285A (en) * 2020-06-29 2020-10-13 四川阵风科技有限公司 Method for rapidly judging node relation
CN115221360A (en) * 2021-04-19 2022-10-21 奇安信科技集团股份有限公司 Tree structure configuration method and system
CN115994141A (en) * 2022-12-06 2023-04-21 山东浪潮新基建科技有限公司 Tree-shaped coding method and system
CN115840751A (en) * 2023-02-21 2023-03-24 山东经伟晟睿数据技术有限公司 Novel tree data coding method

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
况立群;熊风光;韩燮;: "一种基于前缀编码的树生成算法", 小型微型计算机系统, no. 05 *
张素智;赵亚楠;杨芮;: "基于MPB-Tree索引的空间数据多关键词模糊查询算法研究", 华中师范大学学报(自然科学版), no. 06 *

Similar Documents

Publication Publication Date Title
CN107092659B (en) Universal tree structure storage and analysis method
JP4886693B2 (en) Information processing method, information processing apparatus, and information processing program
CN106570128A (en) Mining algorithm based on association rule analysis
JP2005025763A (en) Division program, division device and division method for structured document
US20110131259A1 (en) File location naming hierarchy
Jo et al. Panene: A progressive algorithm for indexing and querying approximate k-nearest neighbors
WO2006080268A9 (en) Tree search, totalizing, sort method, information processing device, and tree search, totalizing, and sort program
US20120209855A1 (en) Bit-string key classification/distribution apparatus, classification/distribution method, and program
CN111801665A (en) Hierarchical Locality Sensitive Hash (LSH) partition indexing for big data applications
CN113222165A (en) Quantum line optimization method based on genetic algorithm
CN109254962B (en) Index optimization method and device based on T-tree and storage medium
CN110362854B (en) Automatic processing method and device for fault tree graphical modeling node layout
Han et al. A fast layout algorithm for protein interaction networks
CN116680252A (en) Tree data structure and node batch moving method thereof
CN115206434A (en) De Bruijn graph-based multi-sequence comparison method
CN110321353B (en) Multi-dimensional spatial data indexing method based on semi-decomposition strategy
Shchur et al. Fast and scalable genome-wide inference of local tree topologies from large number of haplotypes based on tree consistent PBWT data structure
CN113961568A (en) Block chain-based block fast searching method for chain data structure
CN108153826B (en) Method and system for comparing hierarchical structure data in visual form based on bar code tree
CN109189996B (en) Based on K2Maximum common connectivity subgraph matching method of large-scale graph of MDD (minimization drive distribution)
CN114490799A (en) Method and device for mining frequent subgraphs of single graph
JP5516880B2 (en) Sequence analysis apparatus, sequence analysis method, and computer program
RU2534368C2 (en) Method of compressing prefix tree data structure
KR20220099745A (en) A spatial decomposition-based tree indexing and query processing methods and apparatus for geospatial blockchain data retrieval
Karczmarz A simple mergeable dictionary

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
TA01 Transfer of patent application right

Effective date of registration: 20231207

Address after: Area a, 1 / F, building 104, No. 1-30, Lane 88, Minbei Road, Minhang District, Shanghai, 201107

Applicant after: Zhiyanhui (Shanghai) Technology Co.,Ltd.

Applicant after: Zhiyan Gongsoft (Hangzhou) Technology Co.,Ltd.

Address before: Area a, 1 / F, building 104, No. 1-30, Lane 88, Minbei Road, Minhang District, Shanghai, 201107

Applicant before: Zhiyanhui (Shanghai) Technology Co.,Ltd.

Applicant before: Zhiyanhui (Hangzhou) Technology Co.,Ltd.

TA01 Transfer of patent application right