Node state determination method, apparatus, device, and storage medium

By flattening the tree-like data structure and using the number of selected child nodes to determine the state of the parent node, the problem of low computational efficiency in existing technologies is solved, achieving efficient node state updates and improved user experience.

CN114417071BActive Publication Date: 2026-05-12BEIJING BAIDU NETCOM SCI & TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
BEIJING BAIDU NETCOM SCI & TECH CO LTD
Filing Date
2022-01-29
Publication Date
2026-05-12

AI Technical Summary

Technical Problem

In tree-based data structures, existing technologies require traversing and calculating all nodes of the entire tree to determine the selected state of the target node, resulting in low computational efficiency and a poor user experience.

Method used

By flattening the tree data structure, node information is stored as a list of multiple tree depth levels. The selection status of the parent node is determined by the number of selected child nodes of the target node, thus recursively updating the selection status of ancestor nodes without traversing the entire tree.

Benefits of technology

It improves the efficiency of calculating the selected state of tree data, reduces calculation lag, and enhances the user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114417071B_ABST
    Figure CN114417071B_ABST
Patent Text Reader

Abstract

The present disclosure provides a node state determination method, device and equipment and storage medium, relates to the technical field of data processing, in particular to the field of data structure and cloud service. The specific implementation scheme is: in the case that the selected state of a target node in tree data changes, based on the selected state of the target node, the number of selected child nodes of the parent node of the target node is determined; based on the number of selected child nodes of the parent node of the target node, the selected state of the parent node of the target node is determined. According to the technology of the present disclosure, the calculation efficiency of determining the selected state of the tree data can be improved, and the phenomenon of calculation lag can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of data processing technology, and more particularly to the fields of data structures and cloud services. Background Technology

[0002] In the field of data processing, using tree data structures for data storage is an important means of managing one-to-many relationships between data. A tree data structure expresses hierarchical relationships between data. It uses branching relationships to define the hierarchy. Each node may have multiple child nodes, and each child node has only one parent node. The node with an empty parent node is the root node. Each tree data structure has only one root node. When selecting or deselecting a non-root node in a tree data structure, the selection state of all nodes needs to be recursively calculated. Summary of the Invention

[0003] This disclosure provides a method, apparatus, device, and storage medium for determining node status.

[0004] According to one aspect of this disclosure, a method for determining a node state is provided, comprising:

[0005] In response to a change in the selection state of a target node in the tree data, obtain the first selection state after the change;

[0006] Based on the first selected state, determine the number of selected child nodes of the parent node of the target node;

[0007] Based on the number of selected nodes, determine the second selected state of the parent node.

[0008] According to another aspect of this disclosure, a node state determination apparatus is provided, comprising:

[0009] The first selection state acquisition module is used to acquire the changed first selection state in response to a change in the selection state of the target node in the tree data.

[0010] The child node selection count determination module is used to determine the number of selected child nodes of the parent node of the target node based on the first selection state.

[0011] The second selection state determination module is used to determine the second selection state of the parent node based on the number of selections.

[0012] According to another aspect of this disclosure, an electronic device is provided, comprising:

[0013] At least one processor; and

[0014] The memory is communicatively connected to the at least one processor; wherein,

[0015] The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the methods in any embodiment of this disclosure.

[0016] According to another aspect of this disclosure, a non-transitory computer-readable storage medium is provided storing computer instructions for causing a computer to perform the methods of any embodiment of this disclosure.

[0017] According to another aspect of this disclosure, a computer program product is provided, including a computer program / instructions that, when executed by a processor, implement the methods of any embodiment of this disclosure.

[0018] According to the technology disclosed herein, when the selection state of a target node changes, it is only necessary to find the parent node of the target node and update the selection state of the parent node by updating the selection count of its child nodes. In this way, the selection state update of the ancestor nodes of the target node can be recursively implemented without traversing and calculating all nodes in the entire tree, which greatly improves the calculation efficiency of determining the selection state of tree data and reduces the phenomenon of calculation lag.

[0019] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description

[0020] The accompanying drawings are provided to better understand this solution and do not constitute a limitation of this disclosure. Wherein:

[0021] Figure 1 This is a schematic diagram of a tree-like data structure;

[0022] Figure 2 This is a flowchart illustrating a node state determination method according to an embodiment of the present disclosure. Figure 1 ;

[0023] Figure 3A and Figure 3B It shows the Figure 1 The structural form of tree data before and after flattening the tree data;

[0024] Figure 4 This is a flowchart illustrating a node state determination method according to an embodiment of the present disclosure. Figure 2 ;

[0025] Figure 5 This is a flowchart of a node state determination method according to an embodiment of the present disclosure;

[0026] Figure 6 This is a schematic diagram of a node state determination device according to an embodiment of the present disclosure. Figure 1 ;

[0027] Figure 7 This is a schematic diagram of a node state determination device according to an embodiment of the present disclosure. Figure 2 ;

[0028] Figure 8 This is a block diagram of an electronic device used to implement the node state determination method of the embodiments of this disclosure. Detailed Implementation

[0029] The exemplary embodiments of this disclosure are described below with reference to the accompanying drawings, including various details of the embodiments to aid understanding, and should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this disclosure. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.

[0030] Tree-based data structures can clearly and explicitly express the hierarchical relationships between data. Cloud service providers often use tree-based data structures for data storage when designing solutions for intelligent finance, intelligent healthcare, and other applications. Specifically, for any node in a tree structure with child nodes, there are three selection states: selected, partially selected, and unselected, depending on the selection status of its child nodes. To determine the selection state of a target node, it is necessary to calculate the selection state of each child node of the target node in turn, and then determine the selection state of the target node based on the selection states of its child nodes.

[0031] by Figure 1 For example, when determining the selection state of node M, it is necessary to calculate the selection states of nodes O, P, and Q sequentially. Since node P also has child nodes R and S, calculating the selection state of node P requires calculating the selection states of nodes R and S. Therefore, for the entire tree data structure, when a node is selected or deselected by the user, to determine the change in the overall selection state of the tree data structure due to the user's operation, it is necessary to traverse all nodes in the entire tree and calculate their selection states.

[0032] Figure 2 This is a flowchart illustrating a node state determination method according to an embodiment of the present disclosure, including:

[0033] S210, in response to a change in the selection state of the target node in the tree data, obtain the first selection state after the change;

[0034] S220, based on the first selected state, determine the number of selected child nodes of the parent node of the target node;

[0035] S230, based on the number of selected nodes, determines the second selected state of the parent node.

[0036] According to the above method, when the selection state of the target node changes, it is only necessary to determine the number of selected child nodes of the target node's parent node based on the selected state of the target node after the change. The selection state of the parent node is updated by updating the number of selected child nodes. Thus, the selection state of the target node's ancestor nodes can be updated recursively without traversing and calculating all nodes in the entire tree. This greatly improves the calculation efficiency of determining the selection state of tree data, reduces the phenomenon of calculation lag, and enhances the user experience.

[0037] Specifically, in step S210, the situations in which the selection state of the target node in the tree data changes include:

[0038] Received a selection state toggle command for the target node; and / or,

[0039] The current selection status of the target node, determined based on the number of selected child nodes of the target node, is different from the selection status of the target node determined in the previous case.

[0040] Optionally, the selected state toggle instruction may be triggered by, for example, an operation that selects or deselects a target node by the user.

[0041] For example, the change in the selected state of the target node may be due to the user's selection or deselection operation, or it may be due to the target node's descendant nodes changing their selected state based on the user's operation, thus causing the target node's child nodes to be selected or deselected, and the target node's selected state will also change accordingly.

[0042] Optionally, before step S210, the tree-structured data can be flattened to obtain tree data stored in list form. Figure 3A and Figure 3B The following are examples of the methods used to demonstrate ... Figure 1 The structural form of tree data before and after flattening.

[0043] Figure 3B The tree data, stored as a list, includes information about at least one node corresponding to each of the multiple tree depths. In practical applications, the information for each node in the at least one node may include information about its child nodes and the number of selected child nodes.

[0044] Compared to Figure 3A The original structure of the tree-like data in the Chinese database stores the data. Figure 3BBased on the different tree depths of each node in the tree data, the information of nodes at different tree depths is stored in tables at different levels. Each node's information includes its own data, information about its child nodes, and the number of selected child nodes, but may not include information about its parent node.

[0045] For example, Figure 3B The data structure of each node is shown below:

[0046]

[0047] Here, childrenCheckedNum represents the number of child nodes selected, and children represents the child node information, which may include the identifier of each child node.

[0048] By using the above embodiments to flatten the tree data, the overall tree data is transformed into node information stored in multiple lists at different tree depth levels. This can improve the efficiency of data query and data calculation, and change the inherent structural form of each node in the tree data. The number of selected child nodes can be stored and maintained in the information of each node, making it convenient to calculate the selection status of each node by the number of selected child nodes.

[0049] For example, such as Figure 4 As shown, the method for determining the node state in the above embodiments further includes:

[0050] S410, determine the second tree depth of the parent layer based on the first tree depth of the target node;

[0051] S420, determine the parent node in the parent layer based on the depth of the second tree.

[0052] According to the above exemplary method, the node information of the target node's parent node stores the child node information. The parent level is the level where the target node's parent node resides, and the parent level is one level above the target node. Therefore, based on the first tree depth corresponding to the target node, the second tree depth corresponding to the target node's parent node, i.e., the tree depth of the parent level, can be determined. By traversing each node in the parent level's list and using the child node information stored in the parent level's node information, the target node's parent node can be determined. It is evident that in the above exemplary method, it is not necessary to obtain the parent node from the parent node information of each node. Therefore, a tree data flattened into a list format can be used to switch between selected and selected states of each node, thereby improving data processing efficiency.

[0053] By utilizing the tree depth information corresponding to the node and the child node information contained in each flattened node information through the above embodiments, the list level of the target node's parent node can be quickly determined and the parent node of the target node can be determined by traversing.

[0054] For example, such as Figure 5 As shown, step S230 includes:

[0055] S531, determine the second selection state based on the total number of child nodes of the parent node and the number of selected nodes.

[0056] By comparing the total number of child nodes with the number of selected child nodes, the second selection state of the target node's parent node can be accurately determined.

[0057] Specifically, in step S531, when the selection state of the target node changes, the method for determining the second selection state of the target node's parent node is as follows:

[0058] If the number of selected items is 0, the second selection state is determined to be unselected;

[0059] If the number of selected items equals the total number of items, the second selection state is determined to be selected;

[0060] If the number of selected items is greater than 0 and less than the total number, the second selected state is determined to be half-selected.

[0061] Since each node in the tree data has three states: selected, unselected, and partially selected, and the node information of each node after flattening includes child node information and the number of selected child nodes, by comparing the total number of child nodes with the number of selected child nodes, the selection state of each node can be accurately determined as selected, unselected, or partially selected.

[0062] Optionally, with Figure 1 Taking tree data as an example, using the node state determination method disclosed herein, the following steps are taken: Figure 1 The tree depth is named in levels 0-5. To determine the selection status of node M, it is only necessary to compare the number of selected child nodes and the total number of child nodes in the node information of node M, without having to calculate nodes O, P, and Q in level 4. When the user selects or deselects node O in level 4, it is only necessary to compare the number of selected child nodes and the total number of child nodes of each node in tree depths of 0-3 to determine the change in the overall selection status of the tree data structure due to the user operation, without having to calculate nodes in tree depths of 4-5.

[0063] Using the method described in the above embodiments, when the selection state of a target node changes, it is only necessary to determine and update the number of selected child nodes of the target node's parent node based on the target node's selection state, and then determine the selection state of the target node's parent node based on the number of selected child nodes of the target node's parent node. Therefore, based on the user's command to switch the selection state of a target node in the tree data, the selection state of the entire tree data can be updated by performing calculations only at the tree depth level before the target node's tree depth level, without having to traverse and calculate all nodes in the entire tree. This greatly improves the computational efficiency of determining the selection state of tree data, reduces computational lag, and enhances the user experience.

[0064] The specific settings and implementation methods of the embodiments of this application have been described above from different perspectives. Using the method provided in the above embodiments, after flattening the tree data, the overall tree data is transformed into node information stored in multiple lists at different tree depth levels, improving the efficiency of data querying and data calculation. Simultaneously, the number of selected child nodes is stored and maintained in each node's information. The selection status of a node can be determined simply by comparing the number of selected child nodes with the total number of child nodes. This eliminates the need to traverse and calculate all nodes in the tree when determining changes in the overall selection status of the tree data structure due to user operations, saving time spent on traversal calculations, significantly reducing the possibility of computational lag, and providing a better user experience.

[0065] Figure 6 This is a schematic diagram of a node state determination device according to an embodiment of the present application. The device includes:

[0066] The first selection state acquisition module 610 is used to acquire the changed first selection state in response to a change in the selection state of the target node in the tree data.

[0067] The child node selection quantity determination module 620 is used to determine the selection quantity of the child nodes of the parent node of the target node based on the first selection state.

[0068] The second selection state determination module 630 is used to determine the second selection state of the parent node based on the number of selections.

[0069] Figure 7 This is another embodiment of the node state determination device provided in this disclosure. The device includes a first selection state acquisition module 710, a child node selection quantity determination module 720, and a second selection state determination module 730. The functions of the first selection state acquisition module 610, the child node selection quantity determination module 620, and the second selection state determination module 630 in the above embodiment are the same, and will not be described in detail here.

[0070] For example, such as Figure 7As shown, the device also includes:

[0071] The tree depth determination module 740 is used to determine the second tree depth of the parent layer based on the first tree depth of the target node.

[0072] The parent node determination module 750 determines the parent node from the nodes of the parent layer based on the depth of the second tree.

[0073] Optionally, such as Figure 7 As shown, the second selected state determination module 730 includes:

[0074] The state determination unit 731 is used to determine the second selection state based on the total number of child nodes of the parent node and the number of selected nodes.

[0075] Specifically, the state determination unit 731 is used for:

[0076] If the number of selected items is 0, the second selection state is determined to be unselected;

[0077] If the number of selected items equals the total number of items, the second selection state is determined to be selected;

[0078] If the number of selected items is greater than 0 and less than the total number, the second selected state is determined to be half-selected.

[0079] For example, in the node state determination device of the above embodiment, the tree data includes information of at least one node corresponding to each of the plurality of tree depths, and the information of each node in the at least one node includes the child node information of each node and the number of child nodes selected.

[0080] The functions of each unit, module, or sub-module in the devices of this disclosure embodiment can be found in the corresponding descriptions in the above method embodiments, and they have corresponding beneficial effects, which will not be repeated here.

[0081] The acquisition, storage, and application of user personal information involved in the technical solution disclosed herein comply with the provisions of relevant laws and regulations and do not violate public order and good morals.

[0082] According to embodiments of this disclosure, this disclosure also provides an electronic device, a readable storage medium, and a computer program product.

[0083] Figure 8A schematic block diagram of an example electronic device 800 that can be used to implement embodiments of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure described and / or claimed herein.

[0084] like Figure 8 As shown, device 800 includes a computing unit 801, which can perform various appropriate actions and processes based on a computer program stored in read-only memory (ROM) 802 or a computer program loaded from storage unit 808 into random access memory (RAM) 803. RAM 803 may also store various programs and data required for the operation of device 800. The computing unit 801, ROM 802, and RAM 803 are interconnected via bus 804. Input / output (I / O) interface 805 is also connected to bus 804.

[0085] Multiple components in device 800 are connected to I / O interface 805, including: input unit 806, such as keyboard, mouse, etc.; output unit 807, such as various types of monitors, speakers, etc.; storage unit 808, such as disk, optical disk, etc.; and communication unit 809, such as network card, modem, wireless transceiver, etc. Communication unit 809 allows device 800 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0086] The computing unit 801 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 801 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 801 performs the various methods and processes described above, such as the node state determination method. For example, in some embodiments, the node state determination method may be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 808. In some embodiments, part or all of the computer program may be loaded and / or installed on device 800 via ROM 802 and / or communication unit 809. When the computer program is loaded into RAM 803 and executed by the computing unit 801, one or more steps of the node state determination method described above may be performed. Alternatively, in other embodiments, the computing unit 801 may be configured to perform the node state determination method by any other suitable means (e.g., by means of firmware).

[0087] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.

[0088] The program code used to implement the methods of this disclosure may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.

[0089] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0090] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).

[0091] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as a data server), or computing systems that include middleware components (e.g., an application server), or computing systems that include frontend components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with embodiments of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., a communication network). Examples of communication networks include local area networks (LANs), wide area networks (WANs), and the Internet.

[0092] Computer systems can include clients and servers. Clients and servers are generally located far apart and typically interact via communication networks. Client-server relationships are created by computer programs running on the respective computers and having a client-server relationship with each other. Servers can be cloud servers, servers in distributed systems, or servers incorporating blockchain technology.

[0093] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this disclosure can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this disclosure can be achieved, and this is not limited herein.

[0094] The specific embodiments described above do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this disclosure should be included within the scope of protection of this disclosure.

Claims

1. A method for determining the state of a node, comprising: The tree-structured data is flattened to obtain tree data stored in list form; wherein, the tree data includes a list of nodes corresponding to multiple tree depth levels, and the information of each node persistently stores the information of its child nodes and the number of selected child nodes. In response to determining that the selection state of the target node in the tree data has changed, the first selection state after the change is obtained; Based on the first selected state, determine and update the number of selected child nodes stored in the information of the parent node of the target node; Based on the updated number of selected child nodes, determine the second selection state of the parent node; The method further includes: Based on the first tree depth of the target node, determine the second tree depth of the parent layer; Based on the second tree depth, the parent node is determined from the nodes in the parent layer by using the child node information stored in the node information of each node in the parent layer.

2. The method according to claim 1, wherein, Determining the second selection state of the parent node based on the updated number of selected child nodes includes: The second selection state is determined based on the total number of child nodes of the parent node and the number of selected child nodes.

3. The method according to claim 2, wherein, Determining the second selection state based on the total number of child nodes of the parent node and the number of selected child nodes includes: If the number of selected child nodes is equal to 0, the second selection state is determined to be unselected; If the number of selected child nodes equals the total number, the second selection state is determined to be selected; If the number of selected child nodes is greater than 0 and less than the total number, the second selection state is determined to be half-selected.

4. A node state determination device, comprising: The preprocessing module is used to flatten the tree-structured data to obtain tree data stored in list form; wherein, the tree data includes a list of nodes corresponding to multiple tree depth levels, and the information of each node persistently stores the information of its child nodes and the number of selected child nodes. The first selection state acquisition module is used to acquire the changed first selection state in response to determining that the selection state of the target node in the tree data has changed. The child node selection quantity determination module is used to determine and update the child node selection quantity stored in the information of the parent node of the target node based on the first selection state. The second selection state determination module is used to determine the second selection state of the parent node based on the updated number of selected child nodes; The device further includes: The tree depth determination module is used to determine the second tree depth of the parent layer based on the first tree depth of the target node; The parent node determination module is used to determine the parent node from the nodes in the parent layer based on the depth of the second tree and by using the child node information stored in the node information of each node in the parent layer.

5. The apparatus according to claim 4, wherein, The second selected status determination module includes: The state determination unit is used to determine the second selection state based on the total number of child nodes of the parent node and the number of selected child nodes.

6. The apparatus according to claim 5, wherein, The state determination unit is specifically used for: If the number of selected child nodes is equal to 0, the second selection state is determined to be unselected; If the number of selected child nodes equals the total number, the second selection state is determined to be selected; If the number of selected child nodes is greater than 0 and less than the total number, the second selection state is determined to be half-selected.

7. An electronic device, comprising: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-3.

8. A non-transitory computer-readable storage medium storing computer instructions, wherein, The computer instructions are used to cause the computer to perform the method according to any one of claims 1-3.

9. A computer program product comprising a computer program / instructions that, when executed by a processor, implement the method according to any one of claims 1-3.