Dynamic management method of tree structure data based on node level attributes and recursive update
By introducing node-level attributes and recursive update mechanisms in tree structure data management, the problems of large recursive operation resource consumption and encoding restrict structure scalability are solved, and flexible operation and batch deletion of nodes are realized, which significantly improves the efficiency and flexibility of data management.
Patent Information
- Application Number
- CN202510200749.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-24
- Publication Date
- 2025-05-02
- Estimated Expiration
- 2045-02-24
AI Technical Summary
When processing tree structure data, the prior art consumes a lot of recursive operation resources, coding limits structural scalability, node operations are inflexible, and lacks batch deletion functions, making it difficult to meet the increasingly diverse needs.
The dynamic management method of tree structure data based on node-level attributes and recursive updates is adopted. By introducing node-level attributes, the traditional data statistics method is changed, and the free movement and batch deletion of nodes are supported, and the need to perform specific encoding of each layer of the tree structure is removed.
It significantly improves data statistics efficiency, eliminates the limitations on the depth and breadth of tree structure, realizes flexible operation and batch deletion of nodes, and improves the efficiency, flexibility and accuracy of data management.
Smart Images

Figure CN119719048B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of Web applications, and in particular to the field of user organization and similar tree structure data, and specifically to a tree structure data dynamic management method based on node level attributes and recursive updating. Background Art
[0002] In today's Web application development field, tree-structured data has been widely used in many scenarios such as user organizational structure management, file directory system, and permission management system due to its hierarchical organization form, becoming a key way to organize and manage data. Efficient management and accurate statistics of tree-structured data are directly related to the performance of Web application systems, the quality of user experience, and the accuracy of data processing.
[0003] Currently, processing tree-structured data mainly relies on two common technical solutions. The recursive method is one of them. It traverses each node in the tree and performs statistical analysis on the node data, and uses recursive calls to go deep into each branch of the tree to achieve comprehensive statistics of the entire tree-structured data. However, this method has serious defects. When processing tree-structured data, if the data depth and breadth are too large, the recursive operation will cause a sharp increase in resource consumption due to frequent calls to itself. For example, when performing data statistics in a multi-level user organizational structure tree containing a large number of nodes, recursive operations may occupy a large amount of memory resources due to frequent function calls, and may even cause system freezes or crashes, seriously affecting system performance.
[0004] Another common solution is to implement specific encoding processing on tree nodes. By allowing child nodes to share some encoding information with parent nodes, it is convenient to quickly count and query child node related information based on the parent node encoding, simplifying the data statistics and query process. However, the use of this special encoding technology to construct a tree structure severely limits the breadth and depth of tree structure data expansion. Since the specific encoding method is designed based on fixed rules, when more levels or nodes need to be added, problems such as coding bit limit and coding rule conflicts are prone to occur, resulting in the inability to meet new requirements, greatly affecting the scalability and adaptability of the data structure.
[0005] In addition, the existing technology still has many inconveniences in the actual management operation of tree-structured data. When the node depth is too large, deleting a certain middle node requires deleting all its child nodes first. The operation is cumbersome and complicated, and it is very easy to cause data loss or structural damage due to misoperation. Moreover, the existing technology does not support the flexible movement of nodes. If you want to adjust the position of the node, you can only delete it first and then rebuild it. For application scenarios that require frequent adjustment of the tree structure, this greatly reduces the efficiency of data management. At the same time, the existing technology cannot perform batch deletion of nodes at different levels. Users can only delete nodes one by one. When dealing with a large number of redundant nodes, it is not only time-consuming and labor-intensive, but also seriously affects the efficiency and convenience of data management.
[0006] In summary, with the continuous growth of data scale and complexity, the existing tree-structured data management technology has been unable to meet the increasingly diverse needs. An innovative technical solution is urgently needed to overcome these problems and achieve efficient and flexible management of tree-structured data. Summary of the invention
[0007] In view of the shortcomings of the current related prior art in processing tree structure data, such as large resource consumption of recursive operation, coding-limited structural scalability, inflexible node operation and lack of batch deletion function, the present invention provides a tree structure data dynamic management method based on node level attributes and recursive update to achieve the following key goals:
[0008] Improve data statistics efficiency: By introducing node level attributes, the traditional way of traversing the entire tree structure is changed. When performing node statistics and data analysis, the system can quickly locate and aggregate relevant data based on level attributes, and only perform statistical operations on specific levels and related sub-nodes, greatly reducing the time and resource consumption required for traversal, and significantly improving the efficiency of data statistics, especially when processing large-scale tree data.
[0009] Eliminate structural restrictions: Remove the need for specific coding for each layer of the tree structure, breaking the constraints of traditional coding technology on the depth and breadth of tree structure data. When building and managing tree structures, users can freely define the number of levels and nodes according to actual business needs. Whether increasing the depth of the tree or expanding the breadth, there is no need to be restricted by coding rules, which greatly improves the flexibility and adaptability of the tree structure and meets the construction needs of various complex data models.
[0010] Realize flexible node operation: Support the free movement of any node in the tree structure. Users can intuitively and conveniently move nodes to the target location. Whether it is to upgrade the sub-node level or adjust the node order within the same level, the system can automatically and accurately update the parent node information of the node, process related sub-nodes and connection relationships. Ensure the consistency and integrity of data during the node movement process, optimize the data organization method, make the data logical relationship clearer, and improve the flexibility of data management and user experience.
[0011] Support batch node operation: realize batch deletion of any node in the tree structure. Users only need to select multiple nodes to be deleted, and the system can quickly execute the deletion action, automatically bind the child nodes of the deleted nodes to their parent nodes, avoiding the tedious operation of deleting nodes one by one. Not only does it greatly improve the efficiency of data cleaning and maintenance, but it can also effectively avoid the problem of affecting data integrity and consistency due to missing deleted nodes, reducing the complexity of user operations.
[0012] Enhanced data visualization and analysis capabilities: It has the function of counting the number of all child nodes of any node in the tree structure. After the user adds a node, the system automatically changes the number of child labels contained in all parent nodes, allowing users to intuitively understand the data relationship and hierarchical distribution between nodes in the tree structure, providing strong support for data management and analysis, and enhancing the visualization and analysis capabilities of data management.
[0013] To achieve the above purpose, the technical solution adopted by the present invention is: a tree structure data dynamic management method based on node level attributes and recursive update, comprising the following steps:
[0014] S1: construct a tree structure data system, assign hierarchical attributes to each node, and construct a hierarchical attribute set for each node in the tree structure, which at least includes a unique identifier of the node, a parent node identifier, and a number of labels, wherein the number of labels is the total number of all child nodes of the node, and the hierarchical attribute is used to identify the position information of the node in the tree structure;
[0015] S2: receiving user operation instructions for tree structure data, the operation instructions include adding nodes, deleting nodes in batches, moving nodes, exporting and importing data, querying nodes, and counting the number of nodes; and performing dynamic update operations: in response to the operation of adding, deleting or moving the target node, recursively updating the hierarchical attribute set of the node and its associated parent node according to the operation type, specifically including:
[0016] When the operation type is node addition, update the label counts of the target node's parent node and all its ancestor nodes;
[0017] When the operation type is node deletion, the association between the target node and its parent node is removed, and all child nodes of the target node are mounted to its parent node, triggering the update of the label count of its parent node and its ancestor nodes;
[0018] When the operation type is node movement, the target node is disconnected from the original parent node, the target node is connected to the new parent node, and the label counts of the original parent node, the new parent node, and their ancestor nodes are recursively updated;
[0019] S3: Execute the corresponding processing logic according to different operation instructions: Based on the node hierarchical attributes, use the recursive update mechanism to realize the dynamic management of tree structure data and ensure data consistency and accuracy; perform node relationship query: Based on the hierarchical attribute set of the node, fast statistics are achieved through the number of labels, and the complete hierarchical path of the node is recursively generated through the parent node identifier.
[0020] Furthermore, in step S2, the specific method of recursively updating the number of tags is:
[0021] For the parent node of the target node, increase or decrease its label value, and then iterate the parent node of its parent node step by step until the root node;
[0022] The node deletion operation in step S2 further includes:
[0023] When the target node is deleted, the parent node identifiers of all its child nodes are replaced with the parent node identifier of the deleted node, and the hierarchical path update of the child nodes is triggered;
[0024] Bottom-up recursive traversal: starting from the current node, obtain the unique identifier of the parent node level by level, and concatenate them into a string in hierarchical order; path caching mechanism: when the node hierarchy path changes, only the affected child node path is updated.
[0025] Furthermore, the fast statistical operation in step S3 includes:
[0026] Count the number of all child nodes of a node: directly read the label value of the node;
[0027] Count the total number of nodes at a certain level: filter nodes based on the length of the identifier in the level path;
[0028] Count the number of nodes in some subtrees: recursively add up the number of labels of all child nodes from the target node downward.
[0029] Furthermore, the method also includes a method for constructing a horizontal index table:
[0030] The horizontal index table stores the serial numbers of all child nodes of the same parent node in the order in which they are added;
[0031] When a child node moves, the sequence number of its parent node in the horizontal index table is dynamically adjusted;
[0032] The horizontal index table is used for:
[0033] Generate a visual arrangement order of the tree structure in the user interface;
[0034] Supports sorting subnodes by adding time or custom order.
[0035] Furthermore, the processing logic of adding a node includes:
[0036] S11: receiving a user's instruction to add a node, and determining the position of the newly added node in the tree structure;
[0037] S12: Starting from the newly added node, recursively query all its parent nodes upwards;
[0038] S13: For each queried parent node, update the child node quantity information recorded therein, and save the updated data to a storage medium.
[0039] Furthermore, the processing logic of deleting nodes in batches includes:
[0040] S21: receiving a batch deletion instruction and obtaining a list of nodes to be deleted;
[0041] S22: traverse the list of nodes to be deleted and classify them according to the hierarchical attributes of each node;
[0042] S23: Process the nodes to be deleted at each level from high level to low level: search for all child nodes under it, update the parent node of the child node to the parent node of the node to be deleted, and remove the node to be deleted;
[0043] S24: saving the processed tree structure data to a storage medium, and performing an actual deletion operation on the node marked as to be deleted;
[0044] S25: calling the update function to update the number of child nodes of the relevant parent nodes in the remaining nodes according to the deletion operation result.
[0045] Further, the processing logic of the mobile node includes:
[0046] S31: When a user moves a node, the new parent node ID of the node is recorded;
[0047] S32: After the user submits the move operation, the system obtains the operation parameters including the new parent node ID;
[0048] S33: Compare the new and old parent node IDs. If the new parent node ID is different from the old parent node ID and the new parent node ID is not empty, it is determined that the node position has changed.
[0049] S34: For the node whose position has changed, update the stored parent node ID information and save it to the storage medium;
[0050] S35: Call the update function to update the number of child nodes of the relevant parent node according to the node movement result.
[0051] Furthermore, the processing logic of the data export and import includes:
[0052] S41: Data export: receiving a data export instruction, converting the node data in the tree structure into a table or CSV file format, and providing a download path;
[0053] S42: Data import: Receive the import file and verify the information of each node in the file; based on the verification result, integrate and generate a unique signature for the file and return it to the user; after the user confirms that there is no problem, import the file again, regenerate the signature and compare it with the first generated signature. If they are consistent, the imported node data is saved in the tree structure data system.
[0054] Furthermore, the processing logic of the node query includes:
[0055] S51: receiving a node name keyword input by a user;
[0056] S52: Based on the tree structure, starting from the root node, a fuzzy query algorithm is used to search for nodes whose names contain the keyword;
[0057] S53: For the found node, recursively trace upward to obtain its complete parent node path, and display the query result to the user.
[0058] Furthermore, the processing logic of the node quantity statistics includes:
[0059] S61: Acquire all node information of the tree structure data from the storage medium;
[0060] S62: using multithreading technology, classifying nodes according to their hierarchical attributes;
[0061] S63: Starting from the maximum depth level of the tree structure, loop upward layer by layer: at each level, classify the nodes according to the parent node ID, count the number of direct child nodes under each parent node, and accumulate the number of all child nodes under the same parent node ID;
[0062] S64: updating the counted number of child nodes into the number information of the corresponding parent node until the count of the root node is completed.
[0063] The tree structure data dynamic management method based on node level attributes and recursive update proposed in the present invention has shown significant beneficial effects in many aspects, effectively solved many problems existing in the prior art, greatly improved the efficiency, flexibility and accuracy of tree structure data management, and has at least the following beneficial effects:
[0064] Improve data statistics efficiency and visualization: Statistics on the number of child nodes of each node are realized. Users can intuitively view the number of child nodes under each node and quickly understand their position and information in the entire tree structure. For example, in a large user organizational structure tree, managers can quickly know the number of personnel distribution in each department without complex calculations and traversal. This not only improves the user experience, but also makes the management and maintenance of node information more efficient, greatly reduces the time cost of data statistics, enhances the visualization of data, and facilitates users to conduct macro control and micro analysis of tree structure data.
[0065] Optimize node statistics and modification process: The introduction of node level attributes has greatly optimized the node statistics and modification process. When counting node data or performing modification operations, users do not need to traverse the entire node tree to obtain quantity data, and can directly perform efficient queries and operations on specific levels. For example, when counting the total number of nodes at a certain level, the results can be quickly obtained by filtering nodes based on the length of the identifier in the level attributes. This effectively reduces the number of data queries, improves system performance, makes data processing more flexible, and adapts to diverse data management needs.
[0066] Ensure data consistency and management convenience after node movement: Support nodes to move freely in the tree structure, and users can adjust the node position at will according to actual needs. After the node is moved, the system automatically updates the number of related sub-nodes and other related data to ensure data consistency. For example, when adjusting the hierarchical relationship of project tasks, there is no need to manually update the number of sub-tasks and related related information of the task one by one, the system will automatically complete it. This avoids the tedious operation and possible errors of manual updates by users, provides users with a more convenient node management experience, and improves the accuracy and efficiency of data management.
[0067] Enhanced data management flexibility and efficiency: It can perform batch deletion operations on nodes at different levels, and supports data import and export functions. When processing a large amount of redundant or erroneous data, users can select multiple nodes to delete at one time, and the system automatically handles sub-node mounting and label number updates, saving a lot of time and energy. The data import and export function supports the conversion of tree structure data into common formats, which is convenient for interaction with other systems or data analysis, further improving the flexibility and efficiency of data management and meeting the data processing needs in different business scenarios.
[0068] Optimize hierarchical path management and fast query: Generate node hierarchical paths through bottom-up recursive traversal, and adopt path caching mechanism to update only the affected child node paths when the node hierarchical path changes. This makes it faster and more efficient to query the complete hierarchical path of the node, reducing the waste of computing resources. For example, when looking for the complete path of a file in a complex file directory tree, accurate information can be obtained quickly, providing users with a more convenient data query method and improving the overall efficiency of data processing.
[0069] Supports diversified sorting and visual display: Builds a horizontal index table to store the order of adding sub-nodes, sorts sub-nodes by adding time or custom order, and is used to generate a visual arrangement order of the tree structure in the user interface. This meets the user's personalized needs for data display. For example, when displaying a product category tree, it can be sorted and displayed according to the product launch time, which is convenient for users to view and manage, further improving the user experience and the convenience of data management. BRIEF DESCRIPTION OF THE DRAWINGS
[0070] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0071] Figure 1 It is a flow chart of the tree structure data dynamic management method of the present invention.
[0072] Figure 2 It is a schematic diagram of the framework of the tree structure data dynamic management system of the present invention.
[0073] Figure 3 It is a schematic diagram of the tree structure of the present invention. DETAILED DESCRIPTION
[0074] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Instead, they are merely examples of devices and methods consistent with some aspects of the present invention as detailed in the appended claims.
[0075] Embodiment 1
[0076] See also Figure 1This embodiment provides a method for dynamically managing tree structure data based on node level attributes and recursive updates. The method is applied to user organization structure management, file directory management or permission management system in a Web application scenario, and includes the following steps:
[0077] S1: construct a tree structure data system, assign hierarchical attributes to each node, and construct a hierarchical attribute set for each node in the tree structure, which at least includes a unique identifier of the node, a parent node identifier, and a number of labels, wherein the number of labels is the total number of all child nodes of the node, and the hierarchical attribute is used to identify the position information of the node in the tree structure;
[0078] S2: receiving user operation instructions for tree structure data, the operation instructions include adding nodes, deleting nodes in batches, moving nodes, exporting and importing data, querying nodes, and counting the number of nodes; and performing dynamic update operations: in response to the operation of adding, deleting or moving the target node, recursively updating the hierarchical attribute set of the node and its associated parent node according to the operation type, specifically including:
[0079] When the operation type is node addition, update the label counts of the target node's parent node and all its ancestor nodes;
[0080] When the operation type is node deletion, the association between the target node and its parent node is removed, and all child nodes of the target node are mounted to its parent node, triggering the update of the label count of its parent node and its ancestor nodes;
[0081] When the operation type is node movement, the target node is disconnected from the original parent node, the target node is connected to the new parent node, and the label counts of the original parent node, the new parent node, and their ancestor nodes are recursively updated;
[0082] S3: Execute the corresponding processing logic according to different operation instructions: Based on the node hierarchical attributes, use the recursive update mechanism to realize the dynamic management of tree structure data and ensure data consistency and accuracy; perform node relationship query: Based on the hierarchical attribute set of the node, fast statistics are achieved through the number of labels, and the complete hierarchical path of the node is recursively generated through the parent node identifier.
[0083] As a preferred implementation, in step S2 of this embodiment, the specific method of recursively updating the number of tags is:
[0084] For the parent node of the target node, increase or decrease its label value, and then iterate the parent node of its parent node step by step until the root node;
[0085] The node deletion operation in step S2 further includes:
[0086] When the target node is deleted, the parent node identifiers of all its child nodes are replaced with the parent node identifier of the deleted node, and the hierarchical path update of the child nodes is triggered;
[0087] Bottom-up recursive traversal: starting from the current node, obtain the unique identifier of the parent node level by level, and concatenate them into a string in hierarchical order; path cache mechanism: when the node hierarchy path changes, only the affected child node path is updated. This series of operations ensures that when a node is deleted, the hierarchical relationship and quantity statistics of the entire tree structure can be updated accurately and efficiently, avoiding data confusion, reducing system errors caused by node deletion, and improving system stability and data processing accuracy.
[0088] As a preferred implementation, the fast statistical operation in step S3 of this embodiment includes:
[0089] Count the number of all child nodes of a node: directly read the label value of the node;
[0090] Count the total number of nodes at a certain level: filter nodes based on the length of the identifier in the level path;
[0091] Count the number of nodes in some subtrees: recursively add the number of labels of all subnodes from the target node downward. Through these fast statistical operations, when processing large-scale tree structure data, the statistical efficiency can be significantly improved, saving a lot of computing resources and time. Taking the example of counting the number of people in each department in the corporate organizational structure, accurate data can be quickly obtained to provide strong support for corporate management decisions.
[0092] As a preferred implementation, the method described in this embodiment also includes a method for constructing a horizontal index table:
[0093] The horizontal index table stores the serial numbers of all child nodes of the same parent node in the order in which they are added;
[0094] When a child node moves, the sequence number of its parent node in the horizontal index table is dynamically adjusted;
[0095] The horizontal index table is used for:
[0096] Generate a visual arrangement order of the tree structure in the user interface;
[0097] Supports sorting of subnodes by adding time or custom order. The construction and application of horizontal index tables provide users with richer data display and management methods. When displaying in the user interface, the node arrangement order can be flexibly adjusted according to user needs, enhancing user experience and improving the convenience and intuitiveness of data management.
[0098] As a preferred implementation, the processing logic for adding a node in this embodiment includes:
[0099] S11: receiving a user's instruction to add a node, and determining the position of the newly added node in the tree structure;
[0100] S12: Starting from the newly added node, recursively query all its parent nodes upwards;
[0101] S13: For each queried parent node, update the number of child nodes recorded in it, and save the updated data to the storage medium. This node addition processing logic ensures that when adding new nodes, the number of nodes in the tree structure is updated in a timely and accurate manner, maintaining the consistency and integrity of the data, and providing a reliable basis for subsequent data statistics and analysis.
[0102] As a preferred implementation, the processing logic for deleting nodes in batches in this embodiment includes:
[0103] S21: receiving a batch deletion instruction and obtaining a list of nodes to be deleted;
[0104] S22: traverse the list of nodes to be deleted and classify them according to the hierarchical attributes of each node;
[0105] S23: Process the nodes to be deleted at each level from high level to low level: search for all child nodes under it, update the parent node of the child node to the parent node of the node to be deleted, and remove the node to be deleted;
[0106] S24: saving the processed tree structure data to a storage medium, and performing an actual deletion operation on the node marked as to be deleted;
[0107] S25: Call the update function to update the number of child nodes of the relevant parent nodes in the remaining nodes according to the deletion operation results. The batch deletion node processing logic realizes efficient data cleaning function, greatly reducing the workload of users to manually delete nodes one by one, while ensuring the stability of the tree structure and the accuracy of the data during the batch deletion process, improving the efficiency and convenience of data management.
[0108] As a preferred implementation, the processing logic of the mobile node in this embodiment includes:
[0109] S31: When a user moves a node, the new parent node ID of the node is recorded;
[0110] S32: After the user submits the move operation, the system obtains the operation parameters including the new parent node ID;
[0111] S33: Compare the new and old parent node IDs. If the new parent node ID is different from the old parent node ID and the new parent node ID is not empty, it is determined that the node position has changed.
[0112] S34: For the node whose position has changed, update the stored parent node ID information and save it to the storage medium;
[0113] S35: Call the update function to update the number of child nodes of the relevant parent node according to the node movement result. The node movement processing logic enables users to flexibly adjust the position of nodes in the tree structure, and the system automatically completes the update of relevant data, ensuring the consistency of data and the correctness of logical relationships, and optimizing the user's management experience of tree structure data.
[0114] As a preferred implementation, the data export and import processing logic described in this embodiment includes:
[0115] S41: Data export: receiving a data export instruction, converting the node data in the tree structure into a table or CSV file format, and providing a download path;
[0116] S42: Data import: Receive the import file and verify the information of each node in the file; based on the verification results, integrate and generate a unique signature for the file and return it to the user; after the user confirms that there is no problem, import the file again, regenerate the signature and compare it with the first generated signature. If they are consistent, save the imported node data to the tree structure data system. The data export and import processing logic facilitates the data interaction between tree structure data and other systems or tools. Users can export data for further analysis and processing, and then accurately import the processed data into the system to ensure the accuracy and compatibility of the data and broaden the application scenarios of the data.
[0117] As a preferred implementation, the node query processing logic described in this embodiment includes:
[0118] S51: receiving a node name keyword input by a user;
[0119] S52: Based on the tree structure, starting from the root node, a fuzzy query algorithm is used to search for nodes whose names contain the keyword;
[0120] S53: For the found node, recursively trace upward to obtain its complete parent node path, and display the query results to the user. The node query processing logic provides users with a convenient way to find data. The fuzzy query algorithm improves the flexibility and efficiency of the query, can quickly locate the target node and obtain its hierarchical path information, and facilitates users to understand the position and relationship of the node in the tree structure, which improves the convenience of data query.
[0121] As a preferred implementation, the processing logic of node quantity statistics described in this embodiment includes:
[0122] S61: Acquire all node information of the tree structure data from the storage medium;
[0123] S62: using multithreading technology, classifying nodes according to their hierarchical attributes;
[0124] S63: Starting from the maximum depth level of the tree structure, loop upward layer by layer: at each level, classify the nodes according to the parent node ID, count the number of direct child nodes under each parent node, and accumulate the number of all child nodes under the same parent node ID;
[0125] S64: Update the number of child nodes obtained by statistics to the number information of the corresponding parent node until the statistics of the root node are completed. The node number statistics processing logic combined with multi-threading technology improves the statistical speed of large-scale tree structure data, ensures the accuracy of the number information of parent node and child node, provides accurate data support for data analysis and decision-making, and improves the scientific nature of data management.
[0126] Embodiment 2
[0127] See also Figure 2 This embodiment provides a tree structure data dynamic management system based on node level attributes and recursive updates, which is used to implement the content of the above embodiment 1. The system includes
[0128] Data construction module: used to construct a tree structure data system, assign hierarchical attributes to each node, and generate a hierarchical attribute set for each node in the tree structure. The hierarchical attribute set includes at least a unique identifier of the node, a parent node identifier, and a number of labels, wherein the number of labels is the total number of all child nodes of the node, and the position information of the node in the tree structure is identified by the hierarchical attributes;
[0129] Instruction receiving and processing module: receiving user operation instructions for tree structure data, including adding nodes, deleting nodes in batches, moving nodes, exporting and importing data, querying nodes, and counting the number of nodes; and for the addition, deletion or movement of the target node, recursively updating the hierarchical attribute set of the node and its associated parent node according to the operation type, specifically:
[0130] When the operation type is node addition, update the label counts of the target node's parent node and all its ancestor nodes;
[0131] When the operation type is node deletion, the association between the target node and its parent node is removed, and all child nodes of the target node are mounted to its parent node, triggering the update of the label count of its parent node and its ancestor nodes;
[0132] When the operation type is node movement, the target node is disconnected from the original parent node, the target node is connected to the new parent node, and the label counts of the original parent node, the new parent node, and their ancestor nodes are recursively updated;
[0133] Data management and query module: Based on the node hierarchical attributes, the recursive update mechanism is used to achieve dynamic management of tree structure data to ensure data consistency and accuracy; based on the node hierarchical attribute set, fast statistics are achieved through the number of labels, and the complete hierarchical path of the node is recursively generated through the parent node identifier;
[0134] Adding node module: It undertakes the function of adding node operations in the instruction receiving and processing module, including receiving the user's instruction to add nodes, determining the position of the newly added node in the tree structure; starting from the newly added node, recursively querying all its parent nodes upward; for each queried parent node, updating its recorded child node quantity information, and saving the updated data to the storage medium;
[0135] Batch deletion module: responsible for the functions of batch deletion of nodes in the instruction receiving and processing module, including receiving batch deletion instructions and obtaining a list of nodes to be deleted; traversing the list of nodes to be deleted and classifying them according to the hierarchical attributes of each node; processing the nodes to be deleted at each level from high level to low level, finding all the child nodes under it, updating the parent node of the child node to the parent node of the node to be deleted, and removing the node to be deleted; saving the processed tree structure data to the storage medium, and performing the actual deletion operation on the nodes marked as to be deleted; calling the update function, and updating the number of child nodes of the relevant parent node in the remaining nodes according to the result of the deletion operation;
[0136] Node moving module: executes the function of moving node operation in the instruction receiving and processing module, including recording the new parent node ID after the node is moved when the user moves the node; after the user submits the moving operation, the system obtains the operation parameters including the new parent node ID; compares the new and old parent node IDs, and if the new parent node ID is different from the old parent node ID and the new parent node ID is not empty, it is determined that the node position has changed; for the node whose position has changed, update its stored parent node ID information and save it to the storage medium; call the update function, and update the child node quantity information of the relevant parent node according to the node movement result;
[0137] Data export module: executes the data export operation function in the instruction receiving and processing module, receives data export instructions, converts the node data in the tree structure into a table or CSV file format, and provides a download path;
[0138] Data import module: executes the data import operation function in the instruction receiving and processing module, receives the import file, verifies the information of each node in the file, integrates and generates a unique signature for the file based on the verification result and returns it to the user; after the user confirms that there is no problem, imports the file again, regenerates the signature and compares it with the first generated signature. If they are consistent, the imported node data is saved in the tree structure data system;
[0139] Data query module: It is responsible for the node query operation in the data management and query module, and receives the node name keywords input by the user; based on the tree structure, starting from the root node, it uses the fuzzy query algorithm to search for nodes whose names contain keywords; for the found nodes, it recursively traces upward to obtain their complete parent node path, and displays the query results to the user.
[0140] As an implementation mode, the instruction receiving and processing module in this embodiment specifically performs the following when recursively updating the number of tags:
[0141] For the parent node of the target node, increase or decrease its label value, and then iterate the parent node of its parent node step by step until the root node;
[0142] During the node deletion operation, the parent node identifiers of all child nodes of the target node are replaced with the parent node identifier of the deleted node, triggering the hierarchical path update of the child nodes.
[0143] As an implementation mode, when the data management and query module in this embodiment performs a fast statistical operation, it specifically includes:
[0144] When counting the number of all child nodes of a node, directly read the label value of the node;
[0145] When counting the total number of nodes at a certain level, the nodes are filtered based on the length of the identifier in the level path;
[0146] When counting the number of nodes in a partial subtree, recursively add up the number of labels of all child nodes from the target node downward.
[0147] As an implementation mode, this embodiment further includes a horizontal index table management module:
[0148] Used to construct a horizontal index table, which stores the serial numbers of all child nodes of the same parent node generated in the order of addition;
[0149] Generates a visual arrangement order of the tree structure in the user interface, supporting sorting of child nodes by addition time or custom order.
[0150] As an implementation mode, when the data management and query module in this embodiment processes the node quantity statistics operation, it includes:
[0151] Node information acquisition unit: acquires all node information of tree structure data from the storage medium;
[0152] Multithreaded classification unit: using multithreaded technology to classify nodes according to their hierarchical attributes;
[0153] Statistical loop unit: Starting from the maximum depth level of the tree structure, loop upward layer by layer. At each level, classify the nodes according to the parent node ID, count the number of direct child nodes under each parent node, and accumulate the number of all child nodes under the same parent node ID;
[0154] Quantity update to root node unit: Update the counted number of child nodes to the quantity information of the corresponding parent node until the statistics of the number of node labels are completed.
[0155] Embodiment 3
[0156] See also Figure 3 In order to further illustrate the present invention, Example 3 is provided as a supplementary example to the above-mentioned Example 1 and / or Example 2.
[0157] This embodiment combines the attached Figure 3 The tree structure shown (the root node has child nodes A1, A2, A3, etc., A1 has child nodes B1, B2, etc., and so on) details the specific operation implementation method of the tree structure data dynamic management system based on node hierarchical attributes and recursive updates.
[0158] 1. Adding nodes When the user adds a node to the tree structure, the system uses recursion to query all parent nodes of the node. Taking adding a new node under node B1 as an example, the system will start from the new node and recursively find all parent nodes such as B1, A1 and the root node. Then, the number of child nodes of each parent node is modified, such as increasing the number of child nodes of B1 and A1 by 1, and the modified data is saved to the storage medium to ensure real-time update of the tree structure data.
[0159] 2. Batch deletion
[0160] Traversing the list of nodes to be deleted: Assuming that the nodes to be deleted are B2, C2, and B5, the system traverses these nodes to be deleted in turn and classifies them according to their hierarchical relationship in the tree structure, such as B2 and B5 belong to the B level, and C2 belongs to the C level, and places them in the corresponding lists respectively.
[0161] Hierarchical classification: During the classification process, nodes of the same level are grouped together. Start from the level closest to the root node (here we assume that level B is processed first), and search down to find all the child nodes of each level.
[0162] Find and process child nodes: For nodes B2 and B5 at level B, check their child nodes (if any) and remove the nodes to be deleted. At the same time, update the relevant information of parent nodes A1 and A3 of B2 and B5, and modify the parent node ID of their child nodes to the node (i.e., root node) ID of A1 and A3 to maintain the integrity of the tree structure.
[0163] Save the final result: After processing all the nodes to be deleted, save the final tree structure result to the database or the corresponding data structure to prevent data loss.
[0164] Delete the nodes to be deleted: actually perform the deletion operation and remove the B2, C2, and B5 nodes previously marked as to be deleted to ensure the consistency of system data.
[0165] Call the method to modify the number of child nodes: Finally, update the number of child nodes of the parent node (such as A1, A3, etc.) to accurately reflect the current actual situation.
[0166] 3. Node movement
[0167] Record the new parent node ID: When the user drags node C1 from B1 to B3, the system updates C1's information in real time and writes B3's ID as the new parent node ID into C1's node data.
[0168] User submits the operation: After the user completes the move and submits the operation, the system receives the request parameters containing the ID of the new parent node of C1 (the ID of B3) and related information.
[0169] Filtering and judgment: The system filters and judges C1, checks that the new parent node ID (B3's ID) is different from the original parent node ID (B1's ID) and that B3's ID is not empty, and determines that the parent node of node C1 has changed.
[0170] Update node information: Change the parent node ID of C1 to the ID of B3, and save the updated C1 node information.
[0171] Save operation: Save the modified C1 node information to the database or other persistent storage to ensure the persistence of the changes.
[0172] Call the node quantity modification method: update the number of child nodes of B1 and B3 to ensure that the number of child nodes of the parent node is consistent with the actual structure and maintain the consistency and integrity of the data.
[0173] 4. Data export
[0174] The system can export the node data in the tree structure into a table or CSV file format. For example, the node information of the entire tree structure, including node name, level, parent node and other information, can be organized and exported in a specific format to facilitate users to view and analyze data, and provide corresponding download channels.
[0175] 5. Data import
[0176] Verify the imported file and determine the information of each node in the file one by one. Based on the verification results, integrate and generate a unique signature for the file and return it to the user. After the user confirms that there is no problem, click Import. The system will generate a signature for the file again and compare it with the signature generated the first time. If the verification is consistent, the imported node data will be saved in the tree structure data system to ensure the accuracy and consistency of the imported data.
[0177] 6. Node query Based on the node name keyword entered by the user, the system performs fuzzy query and recursively queries the parent node path of the node. For example, the user enters "B3" for query, the system starts fuzzy matching from the root node, and after finding the B3 node, recursively traces upward to obtain its complete parent node path as "root node-A2-B3", and displays the query results to the user.
[0178] 7. Node quantity statistics
[0179] Get all nodes in the database: extract all node data of the tree structure from the database, such as the root node, A1-A3, B1-B6, C1-C3 and other nodes' related information, to provide a complete data basis for subsequent operations.
[0180] Multi-threaded processing node classification: Use multi-threaded technology to classify nodes according to hierarchical attributes, improve the efficiency of processing large-scale node data, and reduce response time.
[0181] Start looping from the maximum depth level: Start looping from the maximum depth level of the tree structure (here, it is assumed to be level C), ensuring that statistics are collected from the bottom node upwards layer by layer.
[0182] Classification and quantity statistics: In the C level, C1, C2, and C3 are classified according to the ID of the parent node, the number of direct child nodes of each parent node (B1, B3, B5) is counted, and the number of child nodes of the corresponding parent node is updated.
[0183] Update the number of parent nodes: After completing the statistics of the C level, obtain the B level, and add the number of C-level nodes and the number of child nodes of each B-level node to the corresponding B-level parent node (such as A1, A2, A3).
[0184] Recurse to the root node: Continue the counting process until the root node of the tree structure is counted, and comprehensively and accurately update the number of child nodes of all parent nodes to ensure the consistency and integrity of the data.
[0185] In order to improve the user's intuitive understanding of the node structure, this embodiment will implement the number of child nodes of each label to be counted. In this way, the user can view the number of child nodes under each label at a glance, and understand its position and information in the entire node tree. This not only improves the user experience, but also makes the management and maintenance of node information more efficient.
[0186] In order to optimize the node statistics and modification process, the concept of label hierarchy will be introduced. This improvement will effectively reduce the number of data queries required when counting and modifying nodes. When performing operations, users no longer need to traverse the entire node tree to obtain all quantity data, but can directly perform efficient queries and operations on specific levels. This not only improves system performance, but also makes data processing more flexible.
[0187] The free movement of nodes will be implemented, allowing users to adjust the position of nodes in the node tree at will. Every time the user completes the node movement, the system will automatically update the number of related child nodes. This function ensures data consistency after the node structure changes, and users do not have to worry about manually updating the number of child nodes, thus providing a more convenient node management experience.
[0188] The above-mentioned implementation 1, implementation 2 and implementation 3 at least solve the following technical problems:
[0189] 1. The present invention significantly improves the efficiency of data statistics by introducing node-level attributes, especially in application scenarios such as node statistics and data analysis, and its effect is particularly obvious. The design of node-level attributes enables each node to not only contain basic data content, but also to identify its hierarchical position in the tree structure. This structured information storage method enables the system to locate and aggregate related data more efficiently when performing data statistics. Specifically, the introduction of node-level attributes helps to achieve more refined and hierarchical data analysis. In traditional data statistics methods, it is often necessary to traverse the entire data structure, which will lead to low processing efficiency when facing large data sets. Through hierarchical attributes, the system can quickly identify subnodes related to a specific node, so that only the relevant nodes need to be counted, which greatly reduces the time and resource consumption of traversal.
[0190] 2. The present invention successfully eliminates the limitation on the depth and breadth of the data structure by removing the need for specific coding for each layer of the tree structure. This innovative design enables users to have greater flexibility and freedom when building and managing tree structures. In traditional data structure design, it is usually necessary to assign a specific coding method to each level. Although this method helps to organize and retrieve data to a certain extent, it also brings many limitations. On the one hand, the fixed coding method will lead to the limitation of the depth and breadth of the tree structure. For example, when more levels or nodes need to be added, it may not be smoothly implemented due to the limitations of the coding method, thereby affecting the scalability and adaptability of the entire data structure. The design concept of the present invention fundamentally solves this problem. By no longer applying specific coding to each layer of the tree structure, users can freely define the level and number of nodes of the tree structure, whether it is to increase the depth or expand the breadth, it can be flexibly adjusted according to actual needs. This degree of freedom enables the system to adapt to various complex data models, and users no longer need to worry about structural rigidity caused by coding restrictions.
[0191] 3. The present invention has the function of supporting the free movement of any node in the tree structure, which greatly enhances the flexibility of data management and user experience. Traditional data management systems often have strict restrictions on the adjustment of data structures. When users need to reorganize or adjust data, they may face complex operation processes and potential data consistency issues. The present invention completely changes this situation through the intuitive and convenient node movement function, making the data management process more efficient and flexible.
[0192] Specifically, users can freely select any node in the tree structure to move, whether it is to promote a child node to a higher-level node or to rearrange the position of nodes at the same level, the system can easily achieve this operation. This free movement function not only allows users to quickly adjust the data structure according to actual needs, but also helps users optimize the organization of data to ensure that the logical relationship of the data is clearer.
[0193] In addition, the present invention fully considers the consistency and integrity of data when implementing the node movement function. When a user moves a node to a new location, the system automatically processes all child nodes and connection relationships related to it to ensure that the hierarchical relationship and logic of the data structure after adjustment are consistent. Users can easily move nodes through simple drag-and-drop operations or one-click commands without worrying about data loss or structure damage.
[0194] 4. The present invention supports users to perform batch deletion operations on any node from the tree structure. This feature greatly improves the efficiency and flexibility of data management, allowing users to quickly and effectively clean and maintain complex data structures. In traditional data management systems, deleting nodes often requires operations from the end node one by one, especially in tree structures, where the hierarchical relationship and dependency between nodes may make the deletion process cumbersome and time-consuming. This one-by-one deletion method not only increases the complexity of the operation, but may also cause users to feel confused and tired when processing large amounts of data. In addition, during the deletion process, if some nodes are accidentally omitted, the integrity and consistency of the data may be affected, which will bring difficulties to subsequent data management and analysis. The present invention solves these problems by supporting batch deletion operations. Users only need to select multiple nodes in the tree structure to perform batch deletion with one click. Whether it is multiple nodes at the same level or nodes at different levels, the system can quickly process the user's deletion request and automatically bind the child nodes of the deleted node to the parent node of the deleted node. This batch processing capability greatly reduces the user's operation time.
[0195] 5. Supports counting the number of all child nodes of any node in the tree structure. This feature greatly enhances the visualization and analysis capabilities of data management, allowing users to more intuitively understand the data relationships and hierarchical distribution in the tree structure. When users add nodes, the number of child tags contained in all parent nodes will be changed.
[0196] Although the embodiments of the present invention have been shown and described above, it will be appreciated that the above embodiments are exemplary and are not to be construed as limitations of the present invention. A person skilled in the art may change, modify, substitute and vary the above embodiments within the scope of the present invention.
Claims
1. A tree structure data dynamic management method based on node level attributes and recursive updates, characterized by: The steps include: S1: construct a tree structure data system, assign hierarchical attributes to each node, and construct a hierarchical attribute set for each node in the tree structure, which at least includes a unique identifier of the node, a parent node identifier, and a number of labels, wherein the number of labels is the total number of all child nodes of the node, and the hierarchical attribute is used to identify the position information of the node in the tree structure; S2: receiving operation instructions from the user for tree structure data, the operation instructions including adding nodes, deleting nodes in batches, moving nodes, exporting and importing data, querying nodes, and counting the number of nodes; And perform dynamic update operations: in response to the addition, deletion or move operation of the target node, recursively update the hierarchical attribute set of the node and its associated parent node according to the operation type, specifically including: When the operation type is node addition, update the label counts of the target node's parent node and all its ancestor nodes; When the operation type is node deletion, the association between the target node and its parent node is removed, and all child nodes of the target node are mounted to its parent node, triggering the update of the label count of its parent node and its ancestor nodes; When the operation type is node movement, the target node is disconnected from the original parent node, the target node is connected to the new parent node, and the label counts of the original parent node, the new parent node, and their ancestor nodes are recursively updated; S3: Execute the corresponding processing logic according to different operation instructions: Based on the node hierarchical attributes, use the recursive update mechanism to realize the dynamic management of tree structure data and ensure data consistency and accuracy; perform node relationship query: Based on the hierarchical attribute set of the node, fast statistics are achieved through the number of labels, and the complete hierarchical path of the node is recursively generated through the parent node identifier.
2. The method according to claim 1, characterized in that: In step S2, the specific method of recursively updating the number of tags is: For the parent node of the target node, increase or decrease its label value, and then iterate the parent node of its parent node step by step until the root node; The node deletion operation in step S2 further includes: When the target node is deleted, the parent node identifiers of all its child nodes are replaced with the parent node identifier of the deleted node, and the hierarchical path update of the child nodes is triggered; Bottom-up recursive traversal: starting from the current node, obtain the unique identifier of the parent node level by level, and concatenate them into a string in hierarchical order; path caching mechanism: when the node hierarchy path changes, only the affected child node path is updated.
3. The method according to claim 2, characterized in that: The fast statistical operation in step S3 includes: Count the number of all child nodes of a node: directly read the label value of the node; Count the total number of nodes at a certain level: filter nodes based on the length of the identifier in the level path; Count the number of nodes in some subtrees: recursively add up the number of labels of all child nodes from the target node downward.
4. The method for dynamically managing tree structure data based on node level attributes and recursive updates according to claim 3, characterized in that: The method also includes a method for constructing a horizontal index table: The horizontal index table stores the serial numbers of all child nodes of the same parent node in the order in which they are added; When a child node moves, the sequence number of its parent node in the horizontal index table is dynamically adjusted; The horizontal index table is used for: Generate a visual arrangement order of the tree structure in the user interface; Supports sorting subnodes by adding time or custom order.
5. The method for dynamically managing tree structure data based on node level attributes and recursive updates according to claim 1, characterized in that: The processing logic of adding a node includes: S11: receiving a user's instruction to add a node, and determining the position of the newly added node in the tree structure; S12: Starting from the newly added node, recursively query all its parent nodes upwards; S13: For each queried parent node, update the child node quantity information recorded therein, and save the updated data to a storage medium.
6. The method according to claim 5, characterized in that: The processing logic of deleting nodes in batches includes: S21: receiving a batch deletion instruction and obtaining a list of nodes to be deleted; S22: traverse the list of nodes to be deleted and classify them according to the hierarchical attributes of each node; S23: Process the nodes to be deleted at each level from high level to low level: search for all child nodes under it, update the parent node of the child node to the parent node of the node to be deleted, and remove the node to be deleted; S24: saving the processed tree structure data to a storage medium, and performing an actual deletion operation on the node marked as to be deleted; S25: calling the update function to update the number of child nodes of the relevant parent nodes in the remaining nodes according to the deletion operation result.
7. The method according to claim 6, characterized in that: The processing logic of the mobile node includes: S31: When a user moves a node, the new parent node ID of the node is recorded; S32: After the user submits the move operation, the system obtains the operation parameters including the new parent node ID; S33: Compare the new and old parent node IDs. If the new parent node ID is different from the old parent node ID and the new parent node ID is not empty, it is determined that the node position has changed. S34: For the node whose position has changed, update the stored parent node ID information and save it to the storage medium; S35: Call the update function to update the number of child nodes of the relevant parent node according to the node movement result.
8. The method according to claim 7, characterized in that: The processing logic of data export and import includes: S41: Data export: receiving a data export instruction, converting the node data in the tree structure into a table or CSV file format, and providing a download path; S42: Data import: Receive the import file and verify the information of each node in the file; based on the verification result, integrate and generate a unique signature for the file and return it to the user; after the user confirms that there is no problem, import the file again, regenerate the signature and compare it with the first generated signature. If they are consistent, the imported node data is saved in the tree structure data system.
9. The method according to claim 8, characterized in that: The processing logic of the node query includes: S51: receiving a node name keyword input by a user; S52: Based on the tree structure, starting from the root node, a fuzzy query algorithm is used to search for nodes whose names contain the keyword; S53: For the found node, recursively trace upward to obtain its complete parent node path, and display the query result to the user.
10. The method according to claim 9, characterized in that: The processing logic of the node quantity statistics includes: S61: Acquire all node information of the tree structure data from the storage medium; S62: using multithreading technology, classifying nodes according to their hierarchical attributes; S63: Starting from the maximum depth level of the tree structure, loop upward layer by layer: at each level, classify the nodes according to the parent node ID, count the number of direct child nodes under each parent node, and accumulate the number of all child nodes under the same parent node ID; S64: updating the counted number of child nodes into the number information of the corresponding parent node until the count of the root node is completed.
Citation Information
Patent Citations
Tree structure data storage and application method supporting non-recursive fast query
CN117493615A
Method and device for updating state merkle tree
WO2021036175A1