Tree structure data storage method, data storage system and terminal equipment

By storing the data to be stored and its version information of each node of the tree structure data in the first data file and storing the offset in the second data file, the problem that tree structure data storage in the prior art depends on database performance is solved, and more efficient storage and query are achieved.

CN120030014APending Publication Date: 2025-05-23HANGZHOU HIGH-TECH ZONE (BINJIANG) INSTITUTE OF BLOCKCHAIN & DATA SECURITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411998959.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-31
Publication Date
2025-05-23

AI Technical Summary

Technical Problem

In the prior art, the storage of tree structure data depends on the read and write performance of the database, resulting in insufficiency of storage.

Method used

By acquiring the data to be stored for each node in the tree structure data, the offset of each node is determined, and the data and its version information are stored in the first data file, and the offset is stored in the second data file to reduce communication with the database.

Benefits of technology

The storage efficiency and query efficiency of tree structure data are improved, so that data storage no longer depends on the read and write performance of the database.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120030014A_ABST
    Figure CN120030014A_ABST
Patent Text Reader

Abstract

The invention discloses a tree structure data storage method, a data storage system and terminal equipment, and the method comprises the steps: obtaining to-be-stored data of each node in tree structure data, determining an offset corresponding to each node, and storing the to-be-stored data of each node and first version information in a first data file according to the offset, the offset corresponding to each node is stored in a second data file, so that the tree structure data of all versions can be stored through the first data file, and the offsets corresponding to all versions can be stored through the second data file; when the tree structure data of the target version is queried, the target offset corresponding to the target version is determined through the second data file, and the tree structure data of the target version is queried from the first data file through the target offset, so that the situation that data is stored through an interface communicating with a database is reduced. The data storage efficiency does not depend on the read-write performance of the database, and the storage efficiency of the tree structure data is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of data processing technology, and in particular, relates to a tree structure data storage method, a data storage system and a terminal device. Background Art

[0002] Tree structure data is non-linear data consisting of one or more nodes, including a root node at the top level and child nodes directly connected to the root node. When the data of a child node in the tree structure data changes, the root node in the tree structure data will be updated to obtain the tree structure data after each data change, that is, there will be different versions of the tree structure data.

[0003] In order to query different versions of tree structure data, it is necessary to store each version of the tree structure data and perform version management on all the tree structure data. Currently, each version of the tree structure data can be stored in a database, and each version of the tree structure data can be version managed through the database.

[0004] However, to store tree structure data in a database, the data needs to be stored through an interface that communicates with the database, so that the efficiency of data storage depends on the read and write performance of the database, resulting in a problem of low storage efficiency. Summary of the invention

[0005] The embodiments of the present application provide a tree structure data storage method, a data storage system and a terminal device, aiming to solve the problem that the existing tree structure data storage depends on the read and write performance of the database and has low storage efficiency.

[0006] In a first aspect, an embodiment of the present application provides a method for storing tree structure data, the method comprising:

[0007] Get the data to be stored for each node in the tree structure data;

[0008] Determine an offset corresponding to each of the nodes, and store the data to be stored and the first version information of the tree structure data of each of the nodes in a first data file according to the offset;

[0009] The offset corresponding to each node is stored in a second data file, so that when querying the tree structure data of the target version, the target offset corresponding to the target version is determined through the second data file, and the target offset is used to query the tree structure data of the target version from the first data file.

[0010] In a possible implementation manner of the first aspect, determining the offset corresponding to each of the nodes includes:

[0011] Determine the data length of the data to be stored at any of the nodes;

[0012] According to the data length, an offset corresponding to the node is determined.

[0013] In a possible implementation manner of the first aspect, storing the data to be stored and the first version information of the tree structure data of each node in a first data file according to the offset includes:

[0014] Determine the target position of each node in the first data file according to the offset corresponding to each node;

[0015] The data to be stored of each of the nodes and the first version information of the tree structure data are stored in the target location.

[0016] In a possible implementation manner of the first aspect, the node includes a root node and multiple child nodes, the offset includes an offset of the child node and an offset of the root node, the root node is connected to each of the child nodes respectively, and determining a target position of each of the nodes in the first data file according to the offset includes:

[0017] Determine a first target position of the child node in the first data file according to the offset of the child node, and store the to-be-stored data of the child node and the first version information of the tree structure data in the first target position;

[0018] According to the offset of the root node, a second target position of the root node in the first data file is determined, and the data to be stored of the root node, the first version information, and the offset of each child node are stored in the second target position.

[0019] In a possible implementation manner of the first aspect above, the method further includes:

[0020] When a data change operation is triggered, generating second version information corresponding to the data change operation;

[0021] Generate a second child node according to the changed data corresponding to the data change operation, and update the data stored in the root node to obtain an updated root node; wherein the second child node is a child node newly added based on the data change operation;

[0022] Determine the offset of the second child node, and store the data of the second child node and the second version information at a third target location of the first data file according to the offset of the second child node;

[0023] The offset of the updated root node is determined, and according to the offset of the updated root node, the data of the updated root node, the second version information, and the offset of each of the second child nodes are stored in a fourth target position of the first data file.

[0024] In a possible implementation manner of the first aspect, storing the to-be-stored data of the updated root node, the second version information, and the offset of the second child node at a fourth target location of the first data file according to the offset of the updated root node includes:

[0025] When the data change operation is triggered and a first child node exists, the data stored in the updated root node, the second version information, the offset of each first child node, and the offset of each second child node are stored in a fourth target position of the first data file according to the offset of the updated root node; wherein the first child node is a child node whose data has not been changed among multiple child nodes of the tree structure data.

[0026] In a possible implementation manner of the first aspect above, the method further includes:

[0027] The updated offset of the root node is stored in the second data file.

[0028] In a second aspect, an embodiment of the present application provides a data storage system, the system comprising tree structure data and a first data file and a second data file, wherein:

[0029] A first data file is used to store data of all nodes in each version of tree structure data; wherein different versions of tree structure data are stored in different storage spaces in the first data file, and data of different nodes of the same version are stored in different storage locations in the first data file, the nodes include child nodes and root nodes, the data of the child nodes include actual data of the child nodes and version information of the child nodes, and the data of the root nodes include actual data of the root nodes, version information of the root nodes, and offsets of all the child nodes in the same version;

[0030] The second data file is used to store the offset corresponding to each version of the tree structure data, where the offset corresponding to the tree structure data is the offset between the storage position where the tree structure data is stored in the first data file and the starting position of the first data file.

[0031] In a third aspect, an embodiment of the present application provides a storage device for tree structure data, the device comprising:

[0032] An acquisition module is used to acquire the data to be stored in each node in the tree structure data;

[0033] A storage module is used to determine the offset corresponding to each of the nodes, and according to the offset, store the data to be stored and the first version information of the tree structure data of each node in a first data file; the offset corresponding to each of the nodes is stored in a second data file, so that when querying the tree structure data of the target version, the target offset corresponding to the target version is determined through the second data file, and the target offset is used to query the tree structure data of the target version from the first data file.

[0034] In a fourth aspect, an embodiment of the present application provides a terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the method for storing tree structure data provided in the first aspect above is implemented.

[0035] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program. When the computer program is run on a computer, the computer executes the tree structure data storage method provided in the first aspect.

[0036] In a sixth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method for storing tree structure data provided in the first aspect above is implemented.

[0037] It can be understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here.

[0038] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:

[0039] In an embodiment of the present application, by obtaining the data to be stored of each node in the tree structure data, determining the offset corresponding to each node, and based on the offset, storing the data to be stored of each node and the first version information of the tree structure data in the first data file, and storing the offset corresponding to each node in the second data file, it is possible to store all versions of the tree structure data through the first data file, and store the offsets corresponding to all versions through the second data file, thereby reducing the situation of storing data through an interface that communicates with a database, so that the efficiency of data storage does not need to rely on the read and write performance of the database, improving the storage efficiency of the tree structure data, and determining the target offset corresponding to the target version through the second data file when querying the tree structure data of the target version, and querying the tree structure data of the target version from the first data file through the target offset, thereby improving the query efficiency of the tree structure data. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] Figure 1 It is a flowchart of a method for storing tree structure data provided by an embodiment of the present application;

[0041] Figure 2 It is a flowchart of another method for storing tree structure data provided by an embodiment of the present application;

[0042] Figure 3 It is a structural schematic diagram of a data storage system provided by an embodiment of the present application;

[0043] Figure 4 is a schematic diagram of an example of a first data file and a second data file provided in an embodiment of the present application;

[0044] Figure 5 It is a structural diagram of a storage device for tree structure data provided by an embodiment of the present application;

[0045] Figure 6 It is a structural block diagram of a terminal device provided in one embodiment of the present application. DETAILED DESCRIPTION

[0046] In order to make the technical problems, technical solutions and beneficial effects to be solved by the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0047] Tree structure data is non-linear data consisting of one or more nodes, including a root node at the top level and child nodes directly connected to the root node.

[0048] When the data of a child node in the tree structure data changes, the root node in the tree structure data will be updated to obtain the tree structure data after each data change, and then the data of the root node can be verified to verify whether other child nodes have changed.

[0049] Based on the characteristics of the above-mentioned tree structure data, tree structure data can be applied to blockchain scenarios. Specifically, each block in the blockchain can verify whether the data of each child node in the entire block has been tampered with by storing and verifying the data of the root node, thereby improving the efficiency and security of data verification in the blockchain.

[0050] In order to meet the needs of users, the tree structure data needs to be modified and updated from time to time. During the data modification or update process, misoperation, system failure, illegal operation, etc. may occur, which may lead to data leakage, data loss, or even data corruption. Therefore, it is necessary to record the tree structure data obtained after each modification or update, that is, it is necessary to record each version of the tree structure data to restore the tree structure data in the event of data leakage, data loss, or even data corruption.

[0051] Currently, each version of the tree structure data can be stored in a database, and the database can be used to perform version management on each version of the tree structure data.

[0052] However, to store tree structure data in a database, the data needs to be stored through an interface that communicates with the database, so that the efficiency of data storage depends on the read and write performance of the database, resulting in a problem of low storage efficiency.

[0053] Furthermore, when a certain version of tree structure data needs to be queried, data query needs to be performed through an interface that communicates with the database. That is, the efficiency of reading tree structure data also depends on the read and write performance of the database, and there is also the problem of low reading efficiency.

[0054] Based on this, the present application provides a method for storing tree structured data, which obtains the data to be stored of each node in the tree structured data, determines the offset corresponding to each node, and stores the data to be stored of each node and the first version information of the tree structured data in a first data file according to the offset, and stores the offset corresponding to each node in a second data file, thereby being able to store all versions of the tree structured data through the first data file, and store the offset of each version of the tree structured data in the first data file through the second data file, reducing the situation of storing data through an interface that communicates with a database, so that the efficiency of data storage does not need to rely on the read and write performance of the database, improving the storage efficiency of the tree structured data, and providing the offset of the target version of the tree structured data in the first data file when querying the target version of the tree structured data, so as to read the target version of the data from the first data file through the offset, thereby improving the query efficiency of the tree structured data.

[0055] See also Figure 1 , Figure 1 A flowchart of a method for storing tree structure data provided by an embodiment of the present application is shown, which may specifically include the following steps:

[0056] Step 101, obtaining the data to be stored in each node in the tree structure data.

[0057] Among them, the tree structure can be a recursive data structure formed by multiple nodes organized hierarchically, the tree structure data can be data of a recursive data structure formed by multiple nodes organized hierarchically, each node can be a basic unit constituting the tree structure, each node can include the data to be stored in the node, and the data to be stored can be the actual data that needs to be stored in the node.

[0058] In actual applications, when any terminal device needs to apply tree structure data, it can generate tree structure data and store the generated tree structure data, so that when the tree structure data needs to be stored, it can obtain the tree structure data currently needed to be stored and determine the data to be stored for each node in the tree structure data that needs to be stored.

[0059] The terminal device may be a mobile terminal, a computer, a server or other device capable of applying tree structure data.

[0060] Specifically, the tree structure data may include multiple nodes, and the nodes in the tree structure data may include a root node and at least one child node. The root node may be a node at the top level in the tree structure, specifically represented as the starting point in the traversal path of the tree structure data. The child node may be a node directly or indirectly connected to the root node, specifically including a parent node and a leaf node. The leaf node may be a child node at the bottom level in the tree structure, that is, a node at the terminal of the tree structure, specifically represented as the end point in the traversal path of the tree structure data, and the parent node may be a node at an intermediate level in the tree structure, and the intermediate level may be a hierarchical structure between the top level and the bottom level in the tree structure, that is, the parent node may be a child node among all child nodes except the leaf node.

[0061] As an example, the tree structure may include only the top level, and in this case the tree structure includes only the root node. In another example, the tree structure may include only the top level and the bottom level, and in this case the tree structure includes only the root node and the leaf nodes.

[0062] Exemplarily, the tree structure data may include node 1, node 11, node 12, node 13, node 111, node 121, and node 122. Among them, node 1 can be directly connected to node 11, node 12, and node 13, node 11 can be directly connected to node 111, node 12 can be directly connected to node 121 and node 122, and node 1 can be directly or indirectly connected to each node, that is, it is the root node at the top level of the tree structure data, node 13, node 111, node 121, and node 122 can be the end point of any traversal path when traversing the tree structure data starting from node 1, that is, it is the leaf node at the bottom level of the tree structure data, and node 11 and node 12 can be the parent node at the middle level of the tree structure data.

[0063] Among them, any traversal path when traversing the tree structure data starting from node 1 includes the path from node 1 via node 11 to node 111, from node 1 via node 12 to node 121, from node 1 via node 12 to node 122, and from node 1 to node 13.

[0064] In a specific implementation, the actual information that needs to be stored in each node may be the information in the application scenario where the tree structure data needs to be applied. For example, when the tree structure data is applied in a blockchain scenario, the actual information that needs to be stored in each node may be transaction information related to block transactions or encryption keys used for identity authentication in the blockchain, and when the tree structure data is applied in a file management scenario, the actual information that needs to be stored in each node may be the file name of each file or the identifier of each project, and other information.

[0065] Step 102, determining the offset corresponding to each node, and storing the data to be stored of each node and the first version information of the tree structure data in the first data file according to the offset.

[0066] Among them, the offset can be the offset between the position where the node's to-be-stored data is stored in the first data file and the starting address of the first data file stored in the storage space of the terminal device. The first data file can be a file used to store the data of each node, specifically a file that stores the to-be-stored data of each node. The first version information can be the version information of the tree structure data that needs to be stored at the current moment. The version information can be used to identify the tree structure data at different moments. The data of different versions of the tree structure data will also be different, that is, the version information of the tree structure data at different moments will also be different.

[0067] After obtaining the data to be stored of each node, the version information of the tree structure data that needs to be stored at the current moment can be determined, that is, the first version information, and based on the data to be stored of each node, the offset corresponding to each node can be determined. Then, the data to be stored of each node and the first version information of the tree structure data can be stored in the first data file according to the offset corresponding to each node.

[0068] In practical applications, a first data file for storing the data to be stored of each node can be predetermined, and then a storage area for storing the first data file can be allocated in the storage space of the terminal device to store the first data file in the corresponding storage area, and the starting address of the storage area in the storage space of the terminal device can be determined. For each node in the tree structure data, the offset corresponding to the node can be determined based on the data to be stored of the node and the starting address of the storage area of ​​the first data file, that is, the offset between the location where the data to be stored of the node is stored and the starting address of the storage area is determined, and then the data to be stored and the first version information of the node can be stored in the first data file based on the offset corresponding to the node, so that the data to be stored and the first version information of all nodes in the tree structure data can be stored in the first data file.

[0069] In a specific implementation, since the tree structure data can be modified or updated, the modified or updated tree structure data is different from the tree structure data before the modification or update, that is, multiple versions of the tree structure data are generated. Therefore, when the tree structure data is stored at any time, the version information used to identify the current time and the data to be stored for each node at the current time are stored in the first data file, so that the data of each node at all times can be stored in the first data file, that is, each version of the data to be stored can be stored in the first data file. Then, when it is necessary to query the tree structure data of the target version, the first data file is traversed to find the data to be stored whose version information is the target version, thereby realizing the operation of storing and reading any version of the tree structure data without relying on the database, reducing the situation of storing or reading data through the interface that communicates with the database, and improving the storage efficiency and query efficiency of the tree structure data.

[0070] In an embodiment of the present application, determining the offset corresponding to each node in step 102 may include the following steps.

[0071] Determine the data length of the data to be stored in any node, and determine the offset corresponding to the node based on the data length.

[0072] The data length may represent the number of bits occupied when storing or transmitting data.

[0073] After obtaining the data to be stored of each node, for any node, the data length of the data to be stored of the node can be determined, and then the offset corresponding to the node can be determined according to the data length of the data to be stored of the node, thereby obtaining the offset corresponding to each node.

[0074] In practical applications, the number of bits occupied by storing the data to be stored in each node in the first data file can be determined, that is, the data length of the data to be stored, and the storage order of each node in the first data file can be planned. Then, the offset of each node can be determined according to the storage order of each node and the data length of the data to be stored in each node.

[0075] Specifically, the storage order can be the order in which the data to be stored of each node is stored, wherein the first data to be stored is generally stored at the starting address of the storage area of ​​the first data file, that is, the offset corresponding to the first node to be stored is 0, and for any node except the first node to be stored, all nodes stored before the node can be determined according to the planned storage order, as well as the data length of the stored data of each node stored before the node, and the data length of the stored data of each node stored before the node is summed, and the sum of the data length of the stored data of each node stored before the node is obtained, which is the offset corresponding to the node.

[0076] Exemplarily, the tree structure data may include node a, node b and node c, wherein the data length of the data to be stored in node a may be 6 bits, the data length of the data to be stored in node b may be 12 bits, and the data length of the data to be stored in node c may be 16 bits, and the first node to be stored in the storage order of the tree structure data is node a, the second node to be stored is node c, and the third node to be stored is node b. Based on this, it can be determined that the nodes stored before node c only include node a, and the data length of node a is 6 bits, then the offset corresponding to node c can be determined to be 6 bits, and it can be determined that the nodes stored before node b include node a and node c, and the data length of node a is 6 bits, and the data length of node c is 16 bits, then the offset corresponding to node b can be determined to be the sum of the data length of node a and the data length of node c, which is 22 bits.

[0077] In one embodiment of the present application, tree structure data over a period of time in the past can also be obtained, that is, all nodes and data of each node over a period of time in the past can be obtained, and the maximum data length can be determined from the data of all nodes over a period of time in the past. Then, based on the maximum data length, a storage area can be allocated from the first data file for the data to be stored at each node at the current moment, and the length of each storage area is the maximum data length of all nodes over the period of time in the past.

[0078] Specifically, when the data length of the data to be stored of a certain node at the current moment is less than the length of the allocated storage area, the data to be stored of the node can be supplemented so that the data length of the supplemented data to be stored is consistent with the length of the storage area. When the data length of the data to be stored of a certain node at the current moment is greater than the length of the allocated storage area, the storage area of ​​each node can be reallocated according to the data length of the node.

[0079] After allocating the storage area of ​​each node, for any node, the number of nodes stored before the node can be determined based on the planned storage order, and the offset corresponding to the node can be determined based on the number and the length of the storage area, thereby obtaining the offset corresponding to each node.

[0080] Exemplarily, the tree structure data may include node a, node b and node c, and the maximum data length of the data of all nodes in the past period of time may be 16 bits, and thus a storage area with a length of 16 bits may be allocated to node a, node b and node c. In the storage order of the tree structure data, the first node to be stored is node a, the second node to be stored is node c, and the third node to be stored is node b. It can be determined that the number of nodes stored before node c is 1, that is, the offset corresponding to node c is 16 bits, and the number of nodes stored before node b is 2, that is, the offset corresponding to node b is 32 bits.

[0081] In an embodiment of the present application, in step 102, storing the data to be stored of each node and the first version information of the tree structure data in the first data file according to the offset may include the following steps:

[0082] According to the offset corresponding to each node, the target position of each node in the first data file is determined, and the data to be stored of each node and the first version information of the tree structure data are stored in the target position.

[0083] The target location may be a location where the data to be stored is stored in the first data file.

[0084] After obtaining the offset of each node, for any node, the target position and the starting address of the target position for storing the data to be stored in the first data file for the node can be determined according to the offset corresponding to the node and the starting address of the storage area of ​​the first data file, and the data to be stored in the node can be stored in the first data file starting from the starting address of the target position of the node.

[0085] Step 103: Store the offset corresponding to each node in the second data file, so that when querying the tree structure data of the target version, the target offset corresponding to the target version can be determined through the second data file.

[0086] Among them, the second data file can be a file used to store the offset corresponding to each node, the target version can be the version that the user needs to query, the target offset can be the offset of the target version in the second data file, and the target offset can be used to query the tree structure data of the target version from the first data file.

[0087] After obtaining the offset corresponding to each node, the offset corresponding to each node may be stored in the second data file.

[0088] In actual applications, the offset corresponding to each node at the current moment can be stored in the second data file. Specifically, the offset corresponding to each node can be added to the end of the second data file, that is, the offset of the current version is added to the end of the second data file, so that the offset of each version in the second data file is stored in the order of version iteration. Then, when the user needs to query the tree structure data of the target version, the target offset corresponding to the target version can be determined through the second data file. Specifically, the offset corresponding to the target version in the second data file can be determined based on the order of version iteration, and then the data of each node in the target version can be found from the first data file based on the determined target offset.

[0089] In an embodiment of the present application, by obtaining the data to be stored of each node in the tree structure data, determining the offset corresponding to each node, and based on the offset, storing the data to be stored of each node and the first version information of the tree structure data in the first data file, and storing the offset corresponding to each node in the second data file, it is possible to store all versions of the tree structure data through the first data file, and store the offsets corresponding to all versions through the second data file, thereby reducing the situation of storing data through an interface that communicates with a database, so that the efficiency of data storage does not need to rely on the read and write performance of the database, improving the storage efficiency of the tree structure data, and determining the target offset corresponding to the target version through the second data file when querying the tree structure data of the target version, and querying the tree structure data of the target version from the first data file through the target offset, thereby improving the query efficiency of the tree structure data.

[0090] See also Figure 2 , Figure 2 A flowchart of another method for storing tree structure data provided by an embodiment of the present application is shown, which may specifically include the following steps:

[0091] Step 201, obtaining the data to be stored in each node in the tree structure data.

[0092] Step 202: determine the offset corresponding to each node.

[0093] The node includes a root node and multiple child nodes, the offset includes the offset of the child node and the offset of the root node, and the root node is connected to each child node respectively.

[0094] For the related descriptions of step 201 to step 202, please refer to step 101 to step 102, and they will not be repeated here.

[0095] Step 203: determine a first target position of the child node in the first data file according to the offset of the child node, and store the data to be stored of the child node and the first version information of the tree structure data in the first target position.

[0096] The first target location may be a location where the data to be stored of the child node is stored in the first data file.

[0097] After obtaining the offset of the child node, for any child node, the first target position where the child node is stored in the first data file and the starting address of the storage area of ​​the first data file can be determined based on the offset corresponding to the child node and the starting address of the storage area of ​​the first data file, and then the data to be stored and the first version information of the tree structure data of the child node can be stored in the first data file starting from the starting address, so that the data to be stored and the first version information of the tree structure data of each child node can be stored in the first data file.

[0098] It should be understood that since the offset corresponding to each child node is different, the first target position of each child node in the first data file will also be different, that is, the data to be stored of each child node can be stored in different positions in the first data file.

[0099] Step 204: determine the second target position of the root node in the first data file according to the offset of the root node, and store the data to be stored, the first version information and the offset of each child node of the root node in the second target position.

[0100] The second target location may be a location where the data to be stored of the root node is stored in the first data file.

[0101] After obtaining the offset of the root node, the second target position where the root node is stored in the first data file and the starting address of the second target position can be determined based on the offset corresponding to the root node and the starting address of the storage area of ​​the first data file, and then the data to be stored of the root node, the first version information of the tree structure data and the offset of each child node can be stored in the first data file starting from the starting address.

[0102] Step 205: Store the offset corresponding to each node in the second data file, so that when querying the tree structure data of the target version, the target offset corresponding to the target version can be determined through the second data file.

[0103] After obtaining the offset of each child node and the offset of the root node, the offset of each child node and the offset of the root node can be stored in the second data file. Then, when the tree structure data of the target version needs to be queried, the target offset of the target version can be extracted from the second data file, which can specifically include the offset of each child node and the offset of the root node in the target version, and the data of each node in the target version can be found from the first data file based on the extracted offset, which is the tree structure data of the target version.

[0104] As an example, only the offset of the root node can be stored in the second data file, so that when the tree structure data of the target version needs to be queried, the offset of the root node in the target version can be extracted from the second data file, and the data of the root node in the target version can be found from the first data file based on the offset of the root node. Since the data of the root node in the first data file includes not only the data to be stored in the root node and the version information of the tree structure data, but also the offset of each child node in the version information, the offset of each child node in the target version can be obtained, and the data of each child node in the target version can be found from the first data file based on the offset of each child node.

[0105] Based on this, the second data file only needs to store the offset of the root node in each version, without storing the offset of each node, thereby reducing the amount of data stored in the second data file and the number of times data is read from the second data file, thereby improving the efficiency of storing and reading tree structure data.

[0106] In an embodiment of the present application, the following steps may also be included:

[0107] When a data change operation is triggered, second version information corresponding to the data change operation is generated, the first version information is updated to obtain the second version information, a second child node is generated according to the changed data corresponding to the data change operation, and the data stored in the root node is updated to obtain an updated root node, the offset of the second child node is determined, and according to the offset of the second child node, the data of the second child node and the second version information are stored in a third target position of the first data file, the offset of the updated root node is determined, and according to the offset of the updated root node, the data of the updated root node, the second version information and the offset of each second child node are stored in a fourth target position of the first data file.

[0108] The data change operation may be an operation for changing the data of any node in the tree structure data. Usually, the data change operation may be an operation for changing the tree structure data in the first version information. The second version information may be the version information of the tree structure data after the data change operation is performed. The second version information may be used to identify the tree structure data after the tree structure data of the first version information is changed. The changed data may be the data that needs to be changed in the tree structure data. The second child node may be a child node newly added based on the data change operation. The third target location may be the location of the data of the second child node stored in the first data file. The fourth target location may be the location of the data of the updated root node stored in the first data file.

[0109] After the tree structure data of the first version information is stored in the first data file, it is possible to detect in real time whether a data change operation on the tree structure data of the first version information is triggered, and when the triggered data change operation is detected, generate the second version information corresponding to the data change operation. At the same time, the change data of the data change operation can be determined, that is, the data that needs to be changed in the tree structure data in the data change operation can be determined, and a second child node can be generated based on the change data of the data change operation.

[0110] In actual applications, the nodes in the first version information that need to undergo data changes can be determined based on the data change operation, and a corresponding second child node can be generated. Then, the data of the nodes in the first version information that need to undergo data changes can be updated with the changed data of the data change operation, that is, the data of the generated second child node, and the second child node can be a node in the tree structure data of the second version information.

[0111] After obtaining at least one second child node, the data of the root node in the first version information can be updated according to the data of all the second child nodes to obtain an updated root node and the data of the updated root node, which is the root node in the second version information.

[0112] After obtaining at least one second child node and an updated root node, the offset of each second child node and the offset of the updated new root node can be determined according to the data length of the data of each second child node and the data length of the data of the updated root node, and then based on the offset, it can be determined that the data of the second child node is stored at the third target location of the first data file, and that the data of the updated root node is stored at the fourth target location of the first data file, so that the data of the second child node and the second version information are stored at the third target location of the first data file, and the data of the updated root node, the second version information and the offset of each second child node are stored at the fourth target location of the first data file.

[0113] Exemplarily, the first data file may include tree structure data with version information v1, wherein the tree structure data with version information v1 may include root node 1, child node 11 and child node 12, and a triggered data change operation is detected, and the data change operation is an operation of performing a data change on the tree structure data with version information v1, specifically, an operation of changing child node 11 in the tree structure data with version information v1, thereby generating second version information with version information v2, and at the same time, generating a second child node 21 corresponding to the second version information, and updating the data of child node 11 in version information v1 according to the changed data of the data change operation, to obtain the updated data, i.e., the second child node 21 , and updates the data of the root node 1 in the version information v1 according to the data of the second child node 21, to obtain the updated root node, that is, the root node 2 in the second version information, and then the tree structure data with the version information v2 can be obtained, and the tree structure data with the version information v2 can include the root node 2 and the second child node 21, and the tree structure data with the version information v2 is stored in the target position in the first data file, so that after the data change operation is performed, the first data file stores the tree structure data with the version information v1 and the tree structure data with the version information v2, that is, the first data file stores the data of the root node 1, the child node 11, the child node 12, the root node 2 and the second child node 21.

[0114] It should be understood that the data of a node in the tree structure data may include the actual data of the node and the version information of the tree structure data.

[0115] Specifically, when the tree structure data needs to be updated or the user needs to change the tree structure data based on his own needs, the data change operation is triggered.

[0116] In an embodiment of the present application, when a data change operation is triggered and there is a first child node, the following steps may also be included:

[0117] When a data change operation is triggered and a first child node exists, the data stored in the updated root node, the second version information, the offset of each first child node, and the offset of each second child node are stored in a fourth target position of the first data file according to the offset of the updated root node.

[0118] The first child node may be a child node whose data has not been changed among multiple child nodes of the tree structure data.

[0119] After triggering the data change operation, it is also possible to detect whether there are any unchanged child nodes in the tree structure data of the first version information, that is, to detect whether there is a first child node that has not changed when the data change operation performs a data change on the tree structure data of the first version information. When it is detected that there is a first child node, the offset of the updated root node is stored, and the data stored in the updated root node, the second version information, the offset of each first child node, and the offset of each second child node are stored in the fourth target position of the first data file.

[0120] Exemplarily, the first data file may include tree structure data with version information v1, wherein the tree structure data with version information v1 may include root node 1, child node 11 and child node 12, and the data change operation is an operation to change child node 11 in the tree structure data with version information v1, thereby generating second version information with version information v2, and at the same time, generating a second child node 21 corresponding to the second version information, and updating the data of child node 11 in the tree structure data with version information v1 according to the changed data of the data change operation, that is, the data of the second child node 21, and updating the data of root node 1 in the tree structure data with version information v1 according to the data of the second child node 21, to obtain an updated root node, that is, root node 2 in the second version information, and further determining that child node 12 in the tree structure data with version information v1 that is not changed in the data change operation is the first child node , and then the tree structure data with version information v2 can be obtained, and the tree structure data with version information v2 can include root node 2, second child node 21, and child node 12. When the tree structure data with version information v2 is stored in the target position of the first data file, in addition to storing the updated data stored in the root node, the second version information and the offset of each second child node in the first data file, the offset of child node 12 is also stored, and there is no need to repeatedly store child node 12. When the tree structure data with version information v2 needs to be queried later, the data of the root node with version information v2 in the first data file is queried, and the offset of child node 12 is determined from the data of the root node with version information v2, so as to query the data of child node 12 in the first data file based on the offset of child node 12, so that the tree structure data with version information v2 can be queried.

[0121] In an embodiment of the present application, the following steps may also be included:

[0122] The updated offset of the root node is stored in the second data file.

[0123] After the offset of the updated root node is updated, the updated offset of the root node may be stored in the second data file.

[0124] In practical applications, the offset of the updated root node may be added to the end of the second data file.

[0125] In an embodiment of the present application, by obtaining the data to be stored of each node in the tree structure data, determining the offset corresponding to each node, determining the first target position of the child node in the first data file according to the offset of the child node, and storing the data to be stored of the child node and the first version information of the tree structure data in the first target position, determining the second target position of the root node in the first data file according to the offset of the root node, and storing the data to be stored, the first version information of the root node and the offset of each child node in the second target position, so that the data of each child node and the data of the root node can be stored in the corresponding position in the first data file, and the offset of the root node in each version of the tree structure data is stored through the second data file, reducing the situation of storing data through an interface that communicates with a database, so that the efficiency of data storage does not need to rely on the read and write performance of the database, improving the storage efficiency of the tree structure data, and determining the target offset corresponding to the target version through the second data file when querying the tree structure data of the target version, querying the tree structure data of the target version from the first data file through the target offset, and improving the query efficiency of the tree structure data.

[0126] Reference Figure 3 , Figure 3 A schematic diagram of the structure of a data storage system provided by an embodiment of the present application is shown. Figure 3 As shown, the data storage system may include tree structure data and a first data file 31 and a second data file 32, wherein:

[0127] The first data file 31 can be used to store data of all nodes in each version of the tree structure data.

[0128] Among them, different versions of tree structure data are stored in different storage spaces in the first data file, and the data of different nodes of the same version are stored in different storage locations in the first data file. The nodes include child nodes and root nodes. The data of child nodes include the actual data of the child nodes and the version information of the child nodes. The data of root nodes include the actual data of the root node, the version information of the root node and the offsets of all child nodes in the same version.

[0129] For details, see Figure 4 , Figure 4 FIG. 1 shows an example schematic diagram of a first data file and a second data file provided by an embodiment of the present application. Figure 4 As shown, the first data file may include tree structure data with version information v1 and tree structure data with version information v2.

[0130] The tree structure data with version information v1 may include child node 11, child node 12 and root node 1, the data of child node 11 may include version information v1 of the tree structure data and actual data of child node 11, the data of child node 12 may include version information v1 of the tree structure data and actual data of child node 12, the data of root node 1 may include version information v1 of the tree structure data, offset 1 of child node 11, offset 2 of child node 12 and actual data of root node 1. The tree structure data with version information v2 may include child node 12, child node 21, child node 22 and root node 2, the data of child node 21 may include version information v2 of the tree structure data and actual data of child node 21, the data of child node 22 may include version information v2 of the tree structure data and actual data of child node 22, the data of root node 2 may include version information v2 of the tree structure data, offset 2 of child node 12, offset 4 of child node 21, offset 5 of child node 22 and actual data of root node 2.

[0131] The second data file 32 may be used to store the offset corresponding to each version of the tree structure data, where the offset corresponding to the tree structure data is the offset between the storage position where the tree structure data is stored in the first data file and the starting position of the first data file.

[0132] Specifically, the second data file 32 may only store the offset of the root node in each version.

[0133] like Figure 4 As shown, the second data file may include an offset 3 of a root node whose version information is v1 and an offset 6 of a root node whose version information is v2.

[0134] As an example, the tree structure data with version information v1 may include child node 11, child node 12 and root node 1. When the tree structure data with version information v1 needs to be stored, the data to be stored of each node in the tree structure data with version information v1 can be obtained, that is, the actual data of child node 11, child node 12 and root node 1 can be obtained, and then the offset corresponding to each node can be determined according to the data length of the actual data of each node, such as determining the offset 1 of child node 11, the offset 2 of child node 12 and the offset 3 of root node 1, and then the storage of each node can be determined based on the offset corresponding to each node. In the target position of the first data file, for child node 11, the actual data of child node 11 and version information v1 can be stored in the target position corresponding to child node 11; for child node 12, the actual data of child node 12 and version information v1 can be stored in the target position corresponding to child node 12; and for root node 1, the actual data of root node 1, version information v1, offset 1 of child node 11 and offset 2 of child node 12 can be stored in the target position corresponding to root node 1, and offset 3 of root node 1 can be stored in the second data file, so that tree structure data with version information v1 can be stored.

[0135] As an example, when it is necessary to change the data of child node 11 in the tree structure data with version information v1, the data change operation is triggered, the second version information with version information v2 is generated, and the second child node, i.e., child node 21, is generated, and the actual data of child node 11 is updated with the changed data of the data change operation to obtain the actual data of child node 21, and then the above method can be used to determine the offset and target position of child node 21, and the actual data of child node 21 and version information v2 are stored in the target position corresponding to child node 21. In addition, the data change operation can also include the operation of adding new data, and the data change operation can also include the new data related to the operation of adding new data, and then the data change operation can be responded to, and child node 22 can be generated according to the new data, and the new data can be the actual data of child node 22, and then the above method can be used to determine the offset and target position of child node 22, and the actual data of child node 22 and version information v2 are stored in the target position corresponding to child node 22. At the same time, the actual data of the root node 1 in the tree structure data with version information v1 can also be updated based on all second child nodes, that is, the root node 1 is updated based on child nodes 21 and 22 to obtain the actual data of the root node 2, and the data change operation does not change the data of the child node 12 in the tree structure data with version information v1, then the child node 12 can be the first child node, and then the above method can be used to determine the offset of the root node 2 and its target position, and the actual data of the root node 2, version information v2, offset 2 of the child node 12, offset 4 of the child node 21 and offset 5 of the child node are stored in the target position corresponding to the root node 2, and the offset 6 of the root node 2 is stored in the second data file, so that the tree structure data with version information v1 can be updated to obtain the tree structure data with version information v2, and the tree structure data with version information v2 can be stored.

[0136] Reference Figure 5 , Figure 5 A schematic diagram of a tree structure data storage device provided by an embodiment of the present application is shown, which may specifically include the following modules:

[0137] The acquisition module 501 is used to acquire the data to be stored in each node in the tree structure data;

[0138] The storage module 502 is used to determine the offset corresponding to each node, and store the first version information of the data to be stored and the tree structure data of each node in the first data file according to the offset; the offset corresponding to each node is stored in the second data file, so that when querying the tree structure data of the target version, the target offset corresponding to the target version is determined through the second data file, and the target offset is used to query the tree structure data of the target version from the first data file.

[0139] In one implementation, the storage module 502 may be specifically used for:

[0140] Determine the data length of the data to be stored in any node;

[0141] According to the data length, determine the offset corresponding to the node.

[0142] In one implementation, the storage module 502 may be specifically used for:

[0143] Determine the target position of each node in the first data file according to the offset corresponding to each node;

[0144] The data to be stored of each node and the first version information of the tree structure data are stored in the target location.

[0145] In one implementation, the node includes a root node and multiple child nodes, the offset includes the offset of the child node and the offset of the root node, the root node is connected to each child node respectively, and the storage module 502 can be specifically used for:

[0146] According to the offset, determine the target position of each node in the first data file, including:

[0147] Determine a first target position of the child node in the first data file according to the offset of the child node, and store the data to be stored of the child node and the first version information of the tree structure data in the first target position;

[0148] According to the offset of the root node, a second target position of the root node in the first data file is determined, and the data to be stored of the root node, the first version information, and the offset of each child node are stored in the second target position.

[0149] In one implementation, the above device further includes the following modules:

[0150] An update module, used to generate second version information corresponding to the data change operation when a data change operation is triggered; generate a second child node according to the change data corresponding to the data change operation, and update the data stored in the root node to obtain an updated root node; wherein the second child node is a child node newly added based on the data change operation;

[0151] In one implementation, the storage module 502 may also be used for:

[0152] Determine the offset of the second child node, and based on the offset of the second child node, store the data of the second child node and the second version information in the third target location of the first data file; determine the offset of the updated root node, and based on the offset of the updated root node, store the data of the updated root node, the second version information and the offset of each second child node in the fourth target location of the first data file.

[0153] In one implementation, the storage module 502 may also be used for:

[0154] When a data change operation is triggered and a first child node exists, the data stored in the updated root node, the second version information, the offset of each first child node, and the offset of each second child node are stored in a fourth target position of the first data file according to the offset of the updated root node; wherein the first child node is a child node in which the data of multiple child nodes of the tree structure data has not been changed.

[0155] In one implementation, the storage module 502 may also be used for:

[0156] The updated offset of the root node is stored in the second data file.

[0157] In an embodiment of the present application, by obtaining the data to be stored of each node in the tree structure data, determining the offset corresponding to each node, and based on the offset, storing the data to be stored of each node and the first version information of the tree structure data in the first data file, and storing the offset corresponding to each node in the second data file, it is possible to store all versions of the tree structure data through the first data file, and store the offsets corresponding to all versions through the second data file, thereby reducing the situation of storing data through an interface that communicates with a database, so that the efficiency of data storage does not need to rely on the read and write performance of the database, improving the storage efficiency of the tree structure data, and determining the target offset corresponding to the target version through the second data file when querying the tree structure data of the target version, and querying the tree structure data of the target version from the first data file through the target offset, thereby improving the query efficiency of the tree structure data.

[0158] It should be noted that the information interaction, execution process and other contents between the above-mentioned devices are based on the same concept as the method embodiment of the present application. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.

[0159] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.

[0160] Reference Figure 6 , Figure 6 A structural block diagram of a terminal device provided by an embodiment of the present application is shown as follows: Figure 6 As shown, an embodiment of the present application also provides a terminal device 61, which includes: at least one processor 611, a memory 612, and a computer program 6121 stored in the memory 612 and executable on the at least one processor 611, and when the processor 611 executes the computer program 6121, the steps in any of the above-mentioned method embodiments are implemented.

[0161] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in any one of the above method embodiments can be implemented.

[0162] An embodiment of the present application provides a computer program product. When the computer program product runs on a mobile terminal, the mobile terminal can implement the steps in the above-mentioned method embodiments when executing the computer program product.

[0163] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may at least include: any entity or device capable of carrying the computer program code to the camera device / terminal device, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electrical carrier signal, a telecommunication signal, and a software distribution medium.

[0164] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.

Claims

1. A method for storing tree structure data, characterized in that: The method comprises: Get the data to be stored for each node in the tree structure data; Determine an offset corresponding to each of the nodes, and store the data to be stored and the first version information of the tree structure data of each of the nodes in a first data file according to the offset; The offset corresponding to each node is stored in a second data file, so that when querying the tree structure data of the target version, the target offset corresponding to the target version is determined through the second data file, and the target offset is used to query the tree structure data of the target version from the first data file.

2. The method for storing tree structure data according to claim 1, characterized in that: The determining the offset corresponding to each of the nodes includes: Determine the data length of the data to be stored at any of the nodes; According to the data length, an offset corresponding to the node is determined.

3. The method for storing tree structure data according to claim 1 or 2, characterized in that: According to the offset, storing the data to be stored of each node and the first version information of the tree structure data in a first data file includes: Determine the target position of each node in the first data file according to the offset corresponding to each node; The data to be stored of each of the nodes and the first version information of the tree structure data are stored in the target location.

4. The method for storing tree structure data according to claim 3, characterized in that: The node includes a root node and a plurality of child nodes, the offset includes an offset of the child node and an offset of the root node, the root node is connected to each of the child nodes respectively, and determining a target position of each of the nodes in the first data file according to the offset includes: Determine a first target position of the child node in the first data file according to the offset of the child node, and store the to-be-stored data of the child node and the first version information of the tree structure data in the first target position; According to the offset of the root node, a second target position of the root node in the first data file is determined, and the data to be stored of the root node, the first version information, and the offset of each child node are stored in the second target position.

5. The method for storing tree structure data according to claim 4, characterized in that: The method further comprises: When a data change operation is triggered, generating second version information corresponding to the data change operation; Generate a second child node according to the changed data corresponding to the data change operation, and update the data stored in the root node to obtain an updated root node; wherein the second child node is a child node newly added based on the data change operation; Determine the offset of the second child node, and store the data of the second child node and the second version information in a third target location of the first data file according to the offset of the second child node; The offset of the updated root node is determined, and according to the offset of the updated root node, the data of the updated root node, the second version information, and the offset of each of the second child nodes are stored in a fourth target position of the first data file.

6. The method for storing tree structure data according to claim 5, characterized in that: According to the offset of the updated root node, storing the to-be-stored data of the updated root node, the second version information, and the offset of the second child node at a fourth target position of the first data file includes: When the data change operation is triggered and a first child node exists, the data stored in the updated root node, the second version information, the offset of each first child node, and the offset of each second child node are stored in a fourth target position of the first data file according to the offset of the updated root node; wherein the first child node is a child node whose data has not been changed among multiple child nodes of the tree structure data.

7. The method for storing tree structure data according to claim 5 or 6, characterized in that: The method further comprises: The updated offset of the root node is stored in the second data file.

8. A data storage system, characterized in that: The system comprises tree structure data and a first data file and a second data file, wherein: A first data file is used to store data of all nodes in each version of tree structure data; wherein different versions of tree structure data are stored in different storage spaces in the first data file, and data of different nodes of the same version are stored in different storage locations in the first data file, the nodes include child nodes and root nodes, the data of the child nodes include actual data of the child nodes and version information of the child nodes, and the data of the root nodes include actual data of the root nodes, version information of the root nodes, and offsets of all the child nodes in the same version; The second data file is used to store the offset corresponding to each version of the tree structure data, where the offset corresponding to the tree structure data is the offset between the storage position where the tree structure data is stored in the first data file and the starting position of the first data file.

9. A terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 7 is implemented.

10. A computer program product, comprising a computer program, characterized in that: When the computer program is executed on a computer, the computer is caused to execute the method according to any one of claims 1 to 7.