A tree structure node state updating method and device and related medium

CN117827845BActive Publication Date: 2026-10-27AFIRSTSOFT CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410030758.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-01-09
Publication Date
2026-10-27
Estimated Expiration
2044-01-09

AI Technical Summary

Technical Problem

此时,如果数据集体量较大,节点的深度(即从根节点到此节点的唯一路径所经过的节点总数)很深和节点的高度(从当前节点到最远叶子节点的路径上所经过的节点总数)很高的话,那么用户的勾选操作就不能得到及时的响应,甚至会造成程序的严重卡顿无响应

Benefits of technology

[0014]本发明实施例提供了一种树形结构的节点状态更新方法、装置、计算机设备及存储介质,该方法包括:创建数据集的树形结构;其中,所述树形结构包括所述数据集每一级文件所对应的节点;响应于用户对所述树形结构的节点勾选操作,确定对应的目标节点以及所述目标节点的子节点和/或父节点;基于用户的节点勾选操作,利用主线程对所述目标节点的当前勾选状态进行更新,并根据更新后的勾选状态,利用多个子线程向下逐级更新子节点和/或向上逐级更新父节点。本发明实施例在针对关于树形结构的勾选操作时,通过向下对子节点进行勾选更新和通过向上对父节点进行勾选更新的方式,可以实现对于树形结构勾选操作的快速响应。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117827845B_ABST
    Figure CN117827845B_ABST
Patent Text Reader

Abstract

The application discloses a tree structure node state updating method and device and a storage medium, and the method comprises the steps of creating a tree structure of a data set; wherein the tree structure comprises nodes corresponding to each level file of the data set; in response to a user's check operation on a node of the tree structure, determining a target node and child nodes and / or parent nodes of the target node; based on the user's node check operation, updating the current check state of the target node by using a main thread, and according to the updated check state, updating child nodes step by step downwards and / or parent nodes step by step upwards by using multiple sub-threads. When the check operation on the tree structure is performed, the check operation on the tree structure can be quickly responded by checking and updating the child nodes downwards and checking and updating the parent nodes upwards.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer software technology, and in particular to a method, apparatus and related medium for updating the state of nodes in a tree structure. Background Technology

[0002] In some current software and operating systems, using tree structures to display large datasets (such as file systems) often has a drawback: it either doesn't support checkboxes or the response time for checkboxes is too slow, preventing users from making selections or causing a delay between the user's click to check / uncheck and the interface update, resulting in a poor user experience. For example, some current tree-structured dataset display software often omit checkboxes to reduce implementation complexity and improve software stability, or they include checkboxes, but since interface updates must be performed on the main thread, developers typically use recursion or other methods to update node states and refresh the user interface on the main thread after a user clicks a checkbox. If the dataset is large, and the node depth (the total number of nodes along the unique path from the root node) and node height (the total number of nodes along the path from the current node to the farthest leaf node) are both high, then the user's checkbox operation cannot be responded to in a timely manner, and may even cause severe program lag and unresponsiveness. Therefore, how to achieve a fast response to checkbox operations in tree structures is a problem that those skilled in the art need to solve. Summary of the Invention

[0003] This invention provides a method, apparatus, computer device, and storage medium for updating the node state of a tree structure, aiming to achieve a fast response to tree structure selection operations.

[0004] In a first aspect, embodiments of the present invention provide a method for updating the node state of a tree structure, including:

[0005] Create a tree structure for the dataset; wherein the tree structure includes the nodes corresponding to each level of the dataset files;

[0006] In response to the user's selection of nodes in the tree structure, the corresponding target node and the child nodes and / or parent nodes of the target node are determined;

[0007] Based on the user's node selection operation, the main thread updates the current selection status of the target node, and according to the updated selection status, multiple sub-threads update the child nodes downwards and / or update the parent nodes upwards level by level.

[0008] Secondly, embodiments of the present invention provide a node state update device for a tree structure, comprising:

[0009] A structure creation unit is used to create a tree structure for the dataset; wherein the tree structure includes the nodes corresponding to each level of the dataset files;

[0010] An operation response unit is used to respond to a user's node selection operation on the tree structure and determine the corresponding target node and the child nodes and / or parent nodes of the target node;

[0011] The node update unit is used to update the current selection status of the target node based on the user's node selection operation using the main thread, and to update the child nodes downwards and / or the parent nodes upwards using multiple sub-threads according to the updated selection status.

[0012] Thirdly, embodiments of the present invention provide a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the node state update method of the tree structure as described in the first aspect.

[0013] Fourthly, embodiments of the present invention provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the node state update method for a tree structure as described in the first aspect.

[0014] This invention provides a method, apparatus, computer device, and storage medium for updating the node state of a tree structure. The method includes: creating a tree structure of a dataset; wherein the tree structure includes nodes corresponding to each level of files in the dataset; responding to a user's node selection operation in the tree structure, determining a corresponding target node and its child nodes and / or parent nodes; based on the user's node selection operation, updating the current selection state of the target node using a main thread, and updating the child nodes downwards and / or the parent nodes upwards level by level using multiple sub-threads according to the updated selection state. This invention, by updating the selection of child nodes downwards and the parent nodes upwards, enables a rapid response to tree structure selection operations. Attached Figure Description

[0015] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the following description of the embodiments will be briefly introduced. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0016] Figure 1A flowchart illustrating a method for updating the node state of a tree structure according to an embodiment of the present invention;

[0017] Figure 2 This is a schematic diagram of a sub-process of step S103 in a tree structure node state update method provided in an embodiment of the present invention;

[0018] Figure 3 This is a schematic diagram of a sub-process of step S203 in a tree structure node state update method provided in an embodiment of the present invention;

[0019] Figure 4 This is a schematic diagram of another sub-process of step S203 in a tree structure node state update method provided in an embodiment of the present invention;

[0020] Figure 5 This is an example diagram of a tree structure node state update method provided in an embodiment of the present invention;

[0021] Figure 6 A schematic block diagram of a tree-structured node state update device provided in an embodiment of the present invention;

[0022] Figure 7 This is a schematic block diagram of a node update unit in a tree-structured node state update device provided in an embodiment of the present invention;

[0023] Figure 8 A schematic block diagram of a parent-child update unit in a tree-structured node state update device provided in an embodiment of the present invention;

[0024] Figure 9 This is another schematic block diagram of the parent-child update unit in a tree-structured node state update device provided in an embodiment of the present invention. Detailed Implementation

[0025] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0026] It should be understood that, when used in this specification and the appended claims, the terms "comprising" and "including" indicate the presence of the described features, integrals, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.

[0027] It should also be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the invention. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.

[0028] It should also be further understood that the term "and / or" as used in this specification and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.

[0029] Please see below. Figure 1 , Figure 1 The flowchart of a tree structure node state update method provided in an embodiment of the present invention specifically includes steps S101 to S103.

[0030] S101. Create a tree structure for the dataset; wherein, the tree structure includes the nodes corresponding to each level of the dataset files;

[0031] S102. In response to the user's selection operation on the nodes of the tree structure, determine the corresponding target node and the child nodes and / or parent nodes of the target node;

[0032] S103. Based on the user's node selection operation, the main thread updates the current selection status of the target node, and according to the updated selection status, multiple sub-threads update the child nodes downwards and / or update the parent nodes upwards level by level.

[0033] In this embodiment, a tree structure is first created for the dataset. When a user makes a selection operation on this tree structure, the corresponding target node is determined based on the selection operation. The child nodes and / or parent nodes of the target node are then retrieved from the tree structure. The target node is then updated by checking the selection, and its child nodes are updated downwards and / or its parent nodes are updated upwards. It is understood that before receiving the user's operation, the position of the target node in the tree structure is uncertain. Therefore, the target node may have both child and parent nodes, or it may only have child nodes or only a parent node. For example, if the target node is the initial node of the tree structure, then it only has child nodes, so only the child nodes need to be updated. Furthermore, the dataset described in this embodiment is a dataset from software and operating systems, utilizing file system datasets, etc.

[0034] This embodiment achieves rapid response to tree-structure selection operations by updating selections at both the child and parent nodes. It carefully considers user actions, cleverly separating visible data (e.g., the target node) from invisible data (e.g., expanded child nodes under the target node). Visible data is updated on the main thread, ensuring timely and synchronized updates for a better user experience. Invisible data is updated using multi-threading to prevent lag under large datasets.

[0035] In practical applications, the node state update method for the tree structure provided in this embodiment is implemented using the programming language Objective-C and the compilation tool Xcode.

[0036] In one embodiment, step S101 includes:

[0037] Create a tree node structure named parentNode for the dataset, and use the tree node structure to store the parent nodes in the dataset;

[0038] Create a first array folderNodes, and use the first array folderNodes to store the folder nodes in the dataset;

[0039] Create a second array fileNodes, and use the first array fileNodes to store the file nodes in the dataset;

[0040] Create a Boolean variable isExpanded, and use the Boolean variable isExpanded to store whether the nodes in the tree structure are expanded.

[0041] In this embodiment, when creating a tree structure for the dataset, a structure named TreeNode is first created to represent a node in the tree structure. This structure contains the following data:

[0042] The parentNode structure, of type TreeNode, is used to store the parent node to which this node belongs;

[0043] The first array, folderNodes, is used to store the folder nodes (of type TreeNode) under this node;

[0044] The second array, fileNodes, is used to store the file nodes (of type TreeNode) under this node;

[0045] The boolean variable isExpanded is used to store whether the node has been expanded.

[0046] In one embodiment, such as Figure 2 As shown, step S103 includes steps S201 to S203.

[0047] S201. If the current selection status of the target node is "select all", then update the current selection status of the target node to "unselected".

[0048] S202. If the current selection status of the target node is unselected, then update the current selection status of the target node to selected all.

[0049] S203. Update the child nodes of the target node according to the updated check status; and update the parent node of the target node according to the updated check status.

[0050] In this embodiment, when a user performs a checkmark operation, if the target node's current checkmark state is "selected all," it is updated to "unchecked" according to the checkmark operation. Conversely, if the target node's current checkmark state is "unchecked," it is updated to "selected all" according to the checkmark operation. After updating the target node, the child and parent nodes are updated. When updating child and parent nodes, in addition to the "selected all" and "unchecked" states, a "partially selected" state is also involved. For example, if folder A has 10 subfiles and 10 subfolders, and 5 files and 1 folder are checked, then folder A is in a "partially selected" state. In other words, folder A is in a "partially selected" state as long as any files or folders are checked, but the number of checked files and folders is less than 10.

[0051] Combination Figure 5 When a user clicks the checkbox on the left side of snmpconf-data, the software needs to update the button to either select all or deselect all (depending on the current node's status) and update all files and folders under snmpconf-data to either select or deselect all (updating child nodes downwards). Simultaneously, it needs to update the parent node status of snmpconf-data (updating parent nodes upwards), and determine whether snmp is fully selected or completely deselected (whether snmp's fileNodes and folderNodes are both selected or deselected). If so, update to select all or deselect all; otherwise, update to partially select, and so on, up to the usr parent node.

[0052] In one embodiment, such as Figure 3As shown, step S203 includes steps S301 to S307.

[0053] S301. Create a data stack, a first temporary variable node, and a node set nodeSet respectively. Assign the target node to the first temporary variable node, and use the node set nodeSet to store the unexpanded subfolder nodes of the first temporary variable node.

[0054] S302. Perform a loop check on the first temporary variable node;

[0055] S303. If it is determined that the first temporary variable node is empty, then the update of the child node ends.

[0056] S304. If it is determined that the first temporary variable node is not empty, then iterate through the file array fileNodes of the first temporary variable node and update the check status of all corresponding sub-files; and iterate through the folder array folderNodes of the first temporary variable node and update the check status of all corresponding sub-folders, and determine whether each sub-folder is expanded.

[0057] S305. When it is determined that the subfolder has been expanded, the subfolder is added to the data stack.

[0058] S306. When it is determined that the subfolder is not expanded, the subfolder is added to the node set nodeSet, and the file nodes and / or folder nodes under the subfolder are traversed to update the selected status synchronously.

[0059] S307. Perform a pop operation on the data stack and assign the popped data to the first temporary variable node. Then continue to loop and check whether the first temporary variable node is empty until the first temporary variable node is empty.

[0060] In this embodiment, when updating child nodes, a data stack (a last-in-first-out data structure) is first created. Simultaneously, a first temporary variable `node` is created, and the currently selected target node is assigned to `node`. A node set `nodeSet` is also created to store subfolder nodes that are not expanded. Then, it iterates through `node` to check if it is empty; if `node` is empty, the update ends. When `node` is not empty, it iterates through the file array `fileNodes`, updating the selected status of all subfiles. Simultaneously, it iterates through the folder array `folderNodes`, updating the selected status of subfolders while checking if the subfolder is expanded (`isExpanded` being true indicates the node is expanded). If the subfolder is expanded, it is pushed onto the stack; if not, it is added to `nodeSet`. Then, it iterates through the file / folder nodes under that subfolder, updating their selected status synchronously to prevent the status from not updating when the user clicks to view the file / folder. Next, a pop operation is performed on the data stack, and the popped data is assigned to the variable `node`. The process continues to iterate through `node` to check if it is empty until `node` is empty, at which point the update ends.

[0061] Through the above update process, it can be ensured that the nodes being operated on, as well as the expanded child nodes, can display the correct checked state after the interface is refreshed. As for the child nodes that have not been expanded, since the user cannot see these nodes, their updates do not need to be executed on the main thread. This prevents the program from lagging when the amount of node data is large, thereby improving the response speed of the check operation.

[0062] In some specific embodiments, step S306 includes:

[0063] Create a second temporary variable dispatchNode, traverse the node set nodeSet to extract individual file nodes and / or folder nodes, and assign the file nodes and / or folder nodes to the second temporary variable dispatchNode;

[0064] Loop through and check if the second temporary variable dispatchNode is empty;

[0065] When it is determined that the second temporary variable dispatchNode is not empty, the check status of the file node and / or folder node of the second temporary variable dispatchNode is updated, and the stack operation is performed after the update is completed.

[0066] Perform a pop operation on the data stack and assign the popped data to the second temporary variable dispatchNode;

[0067] When the second temporary variable dispatchNode is determined to be empty, the loop ends and the traversal of the node set nodeSet stops.

[0068] For sub-file / folder nodes that are not expanded, this embodiment first creates a second temporary variable `dispatchNode` when updating the selection. Then, it iterates through the node set `nodeSet` and starts a sub-thread to assign the data of a single node to `dispatchNode`. Next, it loops to check if `dispatchNode` is empty; if it is, the loop ends. If `dispatchNode` is not empty, it updates the selection status of the sub-file / folder and pushes the sub-folder onto a stack. Then, it pops data from the stack and assigns it to the variable `dispatchNode`. The loop continues to check if `dispatchNode` is empty until it is empty, at which point the loop and `nodeSet` iteration end.

[0069] In this embodiment, when updating unexpanded nodes, the number of child threads is adjusted based on the size of the node set (nodeSet) to ensure update efficiency. For example, if the node set contains 10 folders, 10 child threads will be started, with each thread responsible for updating one folder, thereby improving update efficiency.

[0070] In one embodiment, such as Figure 4 As shown, step S203 further includes steps S401 to S406.

[0071] S401. Create a third temporary variable pNode, and assign the parent node of the target node to the third temporary variable pNode;

[0072] S402. Loop through and check if the third temporary variable pNode is empty;

[0073] S403. If it is determined that the third temporary variable pNode is empty, then the update of the parent node ends.

[0074] S404. If it is determined that the third temporary variable pNode is not empty, then traverse the sub-file array fileNodes of the third temporary variable pNode and obtain the current selection status of the sub-files; and traverse the sub-folder array folderNodes of the third temporary variable pNode and obtain the current selection status of the sub-folders.

[0075] S405. When the current selection status of the subfile or subfolder is all selected, the third temporary variable pNode is updated to the selected state; when the current selection status of the subfile is unselected, the third temporary variable pNode is updated to the unselected state; when the current selection status of the subfile is partially selected, the third temporary variable pNode is updated to the half-selected state.

[0076] S406. Assign the parent node of the third temporary variable pNode to the third temporary variable pNode, and continue to loop to determine whether the third temporary variable pNode is empty, until it is determined that the third temporary variable pNode is empty.

[0077] In this embodiment, when updating the parent node upwards, a third temporary variable `pNode` is first created, and the parent node of the currently selected target node, `parentNode`, is assigned to the temporary variable `pNode`. Then, it iterates through `pNode` to check if it is empty; if `pNode` is empty, the update ends. When `pNode` is not empty, it iterates through the `fileNodes` array of subfiles, checking if all subfiles are selected, none are selected, or only a portion is selected (partial selection). Simultaneously, it iterates through the `folderNodes` array of subfolders, checking if all subfolders are selected, none are selected, or only a portion is selected (partial selection). If all subfiles / folders are selected, `pNode` is updated to "selected all"; if none are selected, it is updated to "not selected"; if only a portion is selected, it is updated to "partial selection". This process continues until `pNode` is empty, at which point the update ends. After this, the parent node of `pNode` is assigned back to `pNode`, and the process continues to check if `pNode` is empty until it is empty.

[0078] It should be noted that since the user's expansion operations are limited and there will not be a large amount of data, and the node selected by the user is already displayed on the interface, this embodiment can be executed in the main thread when updating the parent node upwards, or it can be executed in a child thread.

[0079] In one embodiment, the node state update device of the tree structure further includes:

[0080] Create an NSOutlineView instance;

[0081] Set the TreeNode node in the tree structure as the data source for the NSOutlineView instance;

[0082] The `reloadData` function in the `NSOutlineView` instance is called to load the display interface, and the user's selection of the tree structure nodes is received based on the display interface.

[0083] In this embodiment, to facilitate user operation and interface display, an operation interface structure can be created. Specifically, an NSOutlineView instance (used in the Cocoa development framework to display hierarchical data using row and column formats, such as expandable and collapsible directories and files) can be created first. Then, the root node TreeNode in the tree structure is used as the data source for the NSOutlineView instance, while the main program acts as a proxy object for NSOutlineView (responsible for assembling the display, adding constraints between interfaces, etc.). Finally, the reloadData function of the NSOutlineView instance is called to load and display the interface. This created operation interface structure can further improve the user experience.

[0084] Figure 6 This is a schematic block diagram of a tree-structured node state update device 600 provided in an embodiment of the present invention. The device 600 includes:

[0085] The structure creation unit 601 is used to create a tree structure of the dataset; wherein, the tree structure includes the nodes corresponding to each level of the dataset files;

[0086] The operation response unit 602 is used to respond to the user's node selection operation on the tree structure and determine the corresponding target node and the child nodes and / or parent nodes of the target node;

[0087] The node update unit 603 is used to update the current selection status of the target node based on the user's node selection operation using the main thread, and to update the child nodes downwards and / or the parent nodes upwards using multiple sub-threads according to the updated selection status.

[0088] In one embodiment, the structure creation unit 601 includes:

[0089] The structure creation unit is used to create a structure parentNode of type TreeNode for the dataset, and to use the structure parentNode to store the parent nodes in the dataset;

[0090] The first array creation unit is used to create a first array folderNodes and use the first array folderNodes to store the folder nodes in the dataset;

[0091] The second array creation unit is used to create a second array fileNodes and use the first array fileNodes to store the file nodes in the dataset;

[0092] The variable creation unit is used to create a Boolean variable isExpanded, and to use the Boolean variable isExpanded to store whether the nodes in the tree structure are expanded.

[0093] In one embodiment, such as Figure 7 As shown, the node update unit 603 includes:

[0094] The first update unit 701 is used to update the current selection status of the target node to unselected if the current selection status of the target node is selected.

[0095] The second update unit 702 is used to update the current selection status of the target node to the selected state if the current selection status of the target node is unselected.

[0096] The parent-child update unit 703 is used to update the child nodes of the target node according to the updated check status; and to update the parent node of the target node according to the updated check status.

[0097] In one embodiment, such as Figure 8 As shown, the parent-child update unit 703 includes:

[0098] The data stack creation unit 801 is used to create a data stack, a first temporary variable node, and a node set nodeSet respectively, assign the target node to the first temporary variable node, and use the node set nodeSet to store the unexpanded subfolder nodes of the first temporary variable node.

[0099] The first loop judgment unit 802 is used to perform loop judgment on the first temporary variable node;

[0100] The first determination unit 803 is used to end the update of the child node if the first temporary variable node is determined to be empty.

[0101] The second determination unit 804 is used to, if the first temporary variable node is determined to be not empty, traverse the file array fileNodes of the first temporary variable node and update the check status of all corresponding sub-files; and traverse the folder array folderNodes of the first temporary variable node and update the check status of all corresponding sub-folders, and determine whether each sub-folder is expanded.

[0102] The data stack addition unit 805 is used to add the subfolder to the data stack when it is determined that the subfolder has been expanded.

[0103] The set addition unit 806 is used to add the subfolder to the node set nodeSet when it is determined that the subfolder is not expanded, and to traverse the file nodes and / or folder nodes under the subfolder to update the selected status synchronously.

[0104] The first pop assignment unit 807 is used to pop data from the data stack and assign the popped data to the first temporary variable node. Then, it continues to loop to check whether the first temporary variable node is empty until the first temporary variable node is empty.

[0105] In one embodiment, the collection addition unit 806 includes:

[0106] The node extraction unit is used to create a second temporary variable dispatchNode, traverse the node set nodeSet to extract a single file node and / or folder node, and assign the file node and / or folder node to the second temporary variable dispatchNode;

[0107] The second loop judgment unit is used to repeatedly judge whether the second temporary variable dispatchNode is empty;

[0108] The update push unit is used to update the check status of the file node and / or folder node of the second temporary variable dispatchNode when it is determined that the second temporary variable dispatchNode is not empty, and to perform the push operation after the update is completed.

[0109] The second pop assignment unit is used to pop data from the data stack and assign the popped data to the second temporary variable dispatchNode.

[0110] The traversal stop unit is used to end the loop and stop traversing the node set nodeSet when the second temporary variable dispatchNode is determined to be empty.

[0111] In one embodiment, such as Figure 9 As shown, the parent-child update unit 703 further includes:

[0112] The node assignment unit 901 is used to create a third temporary variable pNode and assign the parent node of the target node to the third temporary variable pNode;

[0113] The third loop judgment unit 902 is used to repeatedly judge whether the third temporary variable pNode is empty;

[0114] The third determination unit 903 is used to end the update of the parent node if the third temporary variable pNode is determined to be empty.

[0115] The fourth determination unit 904 is used to traverse the sub-file array fileNodes of the third temporary variable pNode and obtain the current selection status of the sub-files if it is determined that the third temporary variable pNode is not empty; and to traverse the sub-folder array folderNodes of the third temporary variable pNode and obtain the current selection status of the sub-folders.

[0116] The variable update unit 905 is used to update the third temporary variable pNode to the selected state when the current selection state of the subfile or subfolder is fully selected; to update the third temporary variable pNode to the unselected state when the current selection state of the subfile is unselected; and to update the third temporary variable pNode to the partially selected state when the current selection state of the subfile is partially selected.

[0117] The termination unit 906 is used to assign the parent node of the third temporary variable pNode to the third temporary variable pNode, and continue to loop to determine whether the third temporary variable pNode is empty, until it is determined that the third temporary variable pNode is empty.

[0118] In one embodiment, the tree-structured node state update device 600 further includes:

[0119] The instance creation unit is used to create NSOutlineView instances;

[0120] The data source setting unit is used to set the TreeNode in the tree structure as the data source of the NSOutlineView instance;

[0121] The operation receiving unit is used to call the loading function reloadData in the NSOutlineView instance to load the display interface, and to receive the user's selection operation on the tree structure node based on the display interface.

[0122] Since the embodiments of the apparatus and the embodiments of the method correspond to each other, please refer to the description of the embodiments of the method for the embodiments of the apparatus, which will not be repeated here.

[0123] This invention also provides a computer-readable storage medium storing a computer program thereon, which, when executed, can perform the steps provided in the above embodiments. The storage medium may include various media capable of storing program code, such as a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.

[0124] This invention also provides a computer device, which may include a memory and a processor. The memory stores a computer program, and when the processor calls the computer program in the memory, it can implement the steps provided in the above embodiments. Of course, the computer device may also include various network interfaces, power supplies, and other components.

[0125] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the systems disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple; relevant parts can be referred to in the method section. It should be noted that those skilled in the art can make various improvements and modifications to this application without departing from the principles of this application, and these improvements and modifications also fall within the protection scope of the claims of this application.

[0126] It should also be noted that, in this specification, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

Claims

1. A method for updating the state of nodes in a tree structure, characterized in that, include: Create a tree structure for the dataset; wherein the tree structure includes the nodes corresponding to each level of the dataset files; In response to the user's selection of nodes in the tree structure, the corresponding target node and the child nodes and / or parent nodes of the target node are determined; Based on the user's node selection operation, the main thread updates the current selection status of the target node, and according to the updated selection status, multiple sub-threads update the child nodes downwards and / or update the parent nodes upwards level by level. The step of updating the child nodes of the target node according to the updated check status includes: Create a data stack, a first temporary variable node, and a node set nodeSet respectively. Assign the target node to the first temporary variable node, and use the node set nodeSet to store the unexpanded subfolder nodes of the first temporary variable node. The first temporary variable node is checked in a loop. If the first temporary variable node is determined to be empty, then the update of the child node ends; If the first temporary variable node is determined to be non-empty, then iterate through the file array fileNodes of the first temporary variable node and update the check status of all corresponding subfiles; and iterate through the folder array folderNodes of the first temporary variable node and update the check status of all corresponding subfolders, and determine whether each subfolder is expanded. When it is determined that the subfolder has been expanded, the subfolder is added to the data stack; When it is determined that the subfolder is not expanded, the subfolder is added to the node set nodeSet, and the file nodes and / or folder nodes under the subfolder are traversed to update the selected status synchronously. Perform a pop operation on the data stack and assign the popped data to the first temporary variable node. Then continue to loop and check whether the first temporary variable node is empty until the first temporary variable node is empty. The step of updating the parent node of the target node according to the updated check status includes: Create a third temporary variable pNode, and assign the parent node of the target node to the third temporary variable pNode; Loop through and check if the third temporary variable pNode is empty; If the third temporary variable pNode is determined to be empty, the update of the parent node ends. If it is determined that the third temporary variable pNode is not empty, then the sub-file array fileNodes of the third temporary variable pNode is traversed and the current selection status of the sub-files is obtained; and the sub-folder array folderNodes of the third temporary variable pNode is traversed and the current selection status of the sub-folders is obtained. When the current selection status of the subfile or subfolder is all selected, the third temporary variable pNode is updated to the selected state; when the current selection status of the subfile is not selected, the third temporary variable pNode is updated to the unselected state; when the current selection status of the subfile is partially selected, the third temporary variable pNode is updated to the half-selected state. Assign the parent node of the third temporary variable pNode to the third temporary variable pNode, and continue to loop to check whether the third temporary variable pNode is empty, until it is determined that the third temporary variable pNode is empty.

2. The method for updating the node state of a tree structure according to claim 1, characterized in that, The tree structure for creating the dataset includes: Create a tree node structure named parentNode for the dataset, and use the tree node structure to store the parent nodes in the dataset; Create a first array folderNodes, and use the first array folderNodes to store the folder nodes in the dataset; Create a second array fileNodes, and use the first array fileNodes to store the file nodes in the dataset; Create a Boolean variable isExpanded, and use the Boolean variable isExpanded to store whether the nodes in the tree structure are expanded.

3. The method for updating the node state of a tree structure according to claim 2, characterized in that, The user-based node selection operation utilizes the main thread to update the current selection state of the target node, and based on the updated selection state, uses multiple sub-threads to update child nodes level by level downwards and / or update parent nodes level by level upwards, including: If the target node is currently selected in the "select all" state, then update the target node's current selection state to "unselected". If the target node is currently unchecked, then update the target node to be selected. The child nodes of the target node are updated accordingly based on the updated check status; and the parent node of the target node is updated accordingly based on the updated check status.

4. The node state update method for a tree structure according to claim 3, characterized in that, When it is determined that the subfolder is not expanded, the subfolder is added to the node set nodeSet, and the file nodes and / or folder nodes under the subfolder are traversed to synchronously update the selected status, including: Create a second temporary variable dispatchNode, traverse the node set nodeSet to extract individual file nodes and / or folder nodes, and assign the file nodes and / or folder nodes to the second temporary variable dispatchNode; Loop through and check if the second temporary variable dispatchNode is empty; When it is determined that the second temporary variable dispatchNode is not empty, the check status of the file node and / or folder node of the second temporary variable dispatchNode is updated, and the stack operation is performed after the update is completed. Perform a pop operation on the data stack and assign the popped data to the second temporary variable dispatchNode; When the second temporary variable dispatchNode is determined to be empty, the loop ends and the traversal of the node set nodeSet stops.

5. The method for updating the node state of a tree structure according to claim 2, characterized in that, Also includes: Create an NSOutlineView instance; Set the TreeNode node in the tree structure as the data source for the NSOutlineView instance; The `reloadData` function in the `NSOutlineView` instance is called to load the display interface, and the user's selection of the tree structure nodes is received based on the display interface.

6. A node state update device for a tree structure, characterized in that, include: A structure creation unit is used to create a tree structure for the dataset; wherein the tree structure includes the nodes corresponding to each level of the dataset files; An operation response unit is used to respond to a user's node selection operation on the tree structure and determine the corresponding target node and the child nodes and / or parent nodes of the target node. The node update unit is used to update the current selection status of the target node based on the user's node selection operation using the main thread, and to update the child nodes downwards and / or the parent nodes upwards using multiple sub-threads according to the updated selection status. The parent-child update unit includes: The data stack creation unit is used to create a data stack, a first temporary variable node, and a node set nodeSet, respectively, assign the target node to the first temporary variable node, and use the node set nodeSet to store the unexpanded subfolder nodes of the first temporary variable node. The first loop judgment unit is used to make loop judgments on the first temporary variable node; The first determination unit is used to end the update of the child node if it determines that the first temporary variable node is empty. The second determination unit is used to, if the first temporary variable node is determined to be not empty, traverse the file array fileNodes of the first temporary variable node and update the check status of all corresponding sub-files; and traverse the folder array folderNodes of the first temporary variable node and update the check status of all corresponding sub-folders, and determine whether each sub-folder is expanded. The data stack addition unit is used to add the subfolder to the data stack when it is determined that the subfolder has been expanded. The set addition unit is used to add the subfolder to the node set nodeSet when it is determined that the subfolder is not expanded, and to traverse the file nodes and / or folder nodes under the subfolder to update the check status synchronously. The first pop assignment unit is used to pop data from the data stack and assign the popped data to the first temporary variable node. Then, it continues to loop to check whether the first temporary variable node is empty until the first temporary variable node is empty. The parent-child update unit also includes: The node assignment unit is used to create a third temporary variable pNode and assign the parent node of the target node to the third temporary variable pNode; The third loop judgment unit is used to repeatedly judge whether the third temporary variable pNode is empty; The third determination unit is used to end the update of the parent node if the third temporary variable pNode is determined to be empty. The fourth determination unit is used to, if the determination is that the third temporary variable pNode is not empty, traverse the sub-file array fileNodes of the third temporary variable pNode and obtain the current selection status of the sub-files; and traverse the sub-folder array folderNodes of the third temporary variable pNode and obtain the current selection status of the sub-folders. The variable update unit is used to update the third temporary variable pNode to the selected state when the current selection state of the subfile or subfolder is fully selected; to update the third temporary variable pNode to the unselected state when the current selection state of the subfile is unselected; and to update the third temporary variable pNode to the partially selected state when the current selection state of the subfile is partially selected. The termination determination unit is used to assign the parent node of the third temporary variable pNode to the third temporary variable pNode, and continue to loop to determine whether the third temporary variable pNode is empty, until it is determined that the third temporary variable pNode is empty.

7. A computer device, characterized in that, The system includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the node state update method for a tree structure as described in any one of claims 1 to 5.

8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the node state update method for a tree structure as described in any one of claims 1 to 5.

Citation Information

Patent Citations

  • Hierarchical structure tree node searching method, electronic equipment and medium

    CN117150095A

  • Managing distributed hierarchical data

    WO2007137875A1