Data storage method and device and storage medium
By building an abstract syntax tree and generating an index table, the problem of low storage and parsing of ISP parameters in the prior art is solved, and more efficient and accurate data loading is achieved.
Patent Information
- Application Number
- CN202411993482.5
- 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
The prior art requires large flash space and memory space when storing and analyzing ISP parameters, and the parsing process takes a long time, resulting in low loading efficiency and accuracy of structure variable data.
By obtaining the source code structure data to be stored, an abstract syntax tree is constructed, and the structure variables of each node are encoded, a unique index entry is generated, forming a differentiated storage of the index table and the source code structure data.
It effectively reduces the flash space required to store structure variable data, and quickly finds the required data through the index table when data is loaded, reducing the memory space and parsing time required to analyze structure variable data, and improving data loading efficiency and accuracy.
Smart Images

Figure CN120030195A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of data storage, and in particular to a data storage method, device and storage medium. Background Art
[0002] In the field of Image Signal Processing (ISP) technology, there are hundreds of ISP debuggable parameters. These ISP parameters will be stored in the device's flash after debugging. The flash will be loaded and applied to obtain the corresponding image when the device is powered on next time. At present, the ISP parameters in the program are described using C language structure variables. The general practice is to write the structure variables into the flash in binary form to form a bin file and store it. The bin file in the flash is directly called the next time it is used. However, when the structure variables are changed, the entire bin file cannot be used.
[0003] Currently, the structure variables are serialized into json format, and the variable name is used as the key for storage and appended to the back of the bin file. When loading, if the structure variables are found to be changed compared to the previous ones, the json file behind the bin file is parsed to restore the available parameters. However, this method has the problem of consuming a large flash space when storing ISP parameters and a large memory space and a long time when parsing.
[0004] Therefore, how to reduce the flash space required for storing structure variable data and reduce the memory space and parsing time required for parsing structure variable data is a problem that needs to be solved urgently. Summary of the invention
[0005] The main purpose of the present application is to provide a data storage method, device and storage medium, which aims to reduce the flash space required for storing structure variable data and reduce the memory space and parsing time required for parsing structure variable data, thereby improving the efficiency and accuracy of loading structure variable data.
[0006] In a first aspect, the present application provides a data storage method, the data storage method comprising the following steps:
[0007] Acquire source code structure data to be stored, wherein the source code structure data includes a plurality of structure variables;
[0008] Based on the syntax structure of the source code structure data, an abstract syntax tree is constructed for each structure variable to obtain a data abstract syntax tree;
[0009] Performing structure variable encoding on the structure variable of each node of the data abstract syntax tree to obtain a unique index entry for each structure variable, wherein the index entry is used to describe the node structure information;
[0010] An index table composed of a plurality of index entries and source code structure data are stored separately, wherein the index table is used to describe the position of each structure data in the source code structure data.
[0011] In a second aspect, the present application also provides a terminal device, comprising a processor, a memory, and a computer program stored in the memory and executable by the processor, wherein when the computer program is executed by the processor, the steps of the data storage method as described above are implemented.
[0012] In a third aspect, the present application further provides a computer-readable storage medium, on which a computer program is stored, wherein when the computer program is executed by a processor, the steps of the data storage method as described above are implemented.
[0013] The present application provides a data storage method, device and storage medium. The present application obtains source code structure data to be stored, wherein the source code structure data includes multiple structure variables; then, based on the syntax structure of the source code structure data, an abstract syntax tree is constructed for each structure variable, so that the data abstract syntax tree can be accurately obtained; the structure variable of each node of the data abstract syntax tree is encoded as a structure variable, so that each structure variable has a unique index entry, and the index entry is used to describe the node structure information; then, an index table composed of multiple index entries and the source code structure data are distinguished and stored, and the index table is used to describe the position of each structure data in the source code structure data. In the present application, by distinguishing and storing an index table composed of multiple index entries and the source code structure data, the flash space required for storing the structure variable data can be effectively reduced, and the required structure variable data can be quickly found through the index table when the data is loaded, effectively reducing the memory space and parsing time required for parsing the structure variable data, thereby improving the loading efficiency and accuracy of the structure variable data. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0015] Figure 1A schematic diagram of a data storage method provided in an embodiment of the present application;
[0016] Figure 2 for Figure 1 A schematic flow chart of sub-steps of a data storage method in FIG.
[0017] Figure 3 A schematic diagram of a structure of a syntax tree of a structure variable provided in an embodiment of the present application;
[0018] Figure 4 Another structural diagram of the syntax tree of the structure variable provided in the embodiment of the present application;
[0019] Figure 5 A schematic diagram of the structure of an index entry provided in an embodiment of the present application;
[0020] Figure 6 Another structural diagram of the syntax tree of the structure variable provided in the embodiment of the present application;
[0021] Figure 7 Another structural diagram of the syntax tree of the structure variable provided in the embodiment of the present application;
[0022] Figure 8 A schematic diagram of a structure in which the structure variables and index table provided in the embodiment of the present application are stored respectively;
[0023] Fig. 9 A schematic diagram of the data loading process provided in the embodiment of the present application;
[0024] Fig.10 A schematic block diagram of a data storage device provided in an embodiment of the present application;
[0025] Fig.11 A schematic block diagram of the structure of a terminal device provided in an embodiment of the present application.
[0026] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0027] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0028] The flowcharts shown in the accompanying drawings are only examples and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps may also be decomposed, combined or partially merged, so the actual execution order may change according to actual conditions.
[0029] In the field of Image Signal Processing (ISP) technology, there are hundreds of ISP debuggable parameters. These ISP parameters will be stored in the device's flash after debugging. The flash will be loaded and applied to obtain the corresponding image when the device is powered on next time. At present, the ISP parameters in the program are described using C language structure variables. The general practice is to write the structure variables into the flash in binary form to form a bin file and store it. The bin file in the flash is directly called the next time it is used. However, when the structure variables are changed, the entire bin file cannot be used.
[0030] Currently, the structure variables are serialized into json format, and the variable name is used as the key for storage and appended to the back of the bin file. When loading, if the structure variables are found to be changed compared to the previous ones, the json file behind the bin file is parsed to restore the available parameters. However, this method has the problem of consuming a large flash space when storing ISP parameters and a large memory space and a long time when parsing.
[0031] To solve the above problems, the embodiment of the present application provides a data storage method, device and storage medium. The data storage method includes: obtaining source code structure data to be stored, wherein the source code structure data includes multiple structure variables; constructing an abstract syntax tree for each structure variable based on the syntax structure of the source code structure data to obtain a data abstract syntax tree; encoding the structure variable of each node of the data abstract syntax tree to obtain a unique index entry for each structure variable, wherein the index entry is used to describe the node structure information; distinguishing and storing an index table composed of multiple index entries and the source code structure data, wherein the index table is used to describe the position of each structure data in the source code structure data.
[0032] Among them, the data storage method can be applied to terminal devices, which can be electronic devices such as mobile phones, tablet computers, laptops, desktop computers, personal digital assistants and wearable devices.
[0033] In conjunction with the accompanying drawings, some embodiments of the present application are described in detail below. In the absence of conflict, the following embodiments and features in the embodiments can be combined with each other.
[0034] Please refer to Figure 1 , Figure 1 A flowchart of a data storage method provided in an embodiment of the present application.
[0035] like Figure 1 As shown, the data storage method includes steps S101 to S104.
[0036] Step S101: Acquire source code structure data to be stored, wherein the source code structure data includes a plurality of structure variables.
[0037] The source code structure data to be stored is source code data used for image loading, and the source code structure data includes a plurality of structure variables.
[0038] In some embodiments, source code structure data to be stored is obtained, the source code structure data including a plurality of structure variables. The source code structure data for image loading is obtained and pre-stored in the terminal device to facilitate image loading efficiency and accuracy.
[0039] It should be noted that the source code structure data is a structure parameter header file (Header File).
[0040] Step S102: construct an abstract syntax tree for each structure variable based on the syntax structure of the source code structure data to obtain a data abstract syntax tree.
[0041] The data abstract syntax tree is constructed based on the syntax structure of the source code structure data, and each node of the data abstract syntax tree includes a structure variable.
[0042] In some embodiments, the source code structure data is preprocessed by gcc to obtain the preprocessed source code structure data intermediate file, and a syntax tree is constructed for each structure variable in the source code structure data intermediate file to obtain a data abstract syntax tree. Based on the syntax structure, an abstract syntax tree is constructed for each structure variable, and the data abstract syntax tree can be accurately obtained, thereby greatly improving the accuracy of the structure variable data storage.
[0043] It should be noted that the gcc preprocessing includes but is not limited to preprocessing, compiling, assembling and linking processes, and the source code structure data intermediate file is the .i file corresponding to the structure parameter header file.
[0044] Exemplarily, a syntax tree is constructed for each structure variable in the source code structure data intermediate file to obtain a data abstract syntax tree by obtaining a preset pycparser module, and constructing a syntax tree for each structure variable based on the syntax structure in the source code structure data intermediate file to obtain a data abstract syntax tree, wherein the data abstract syntax tree includes multiple nodes, and each node includes a structure variable.
[0045] Step S103: perform structure variable encoding on the structure variable of each node of the data abstract syntax tree to obtain a unique index entry for each structure variable, wherein the index entry is used to describe the node structure information.
[0046] The index entry is used to describe the node structure information, and the index entry of each node is unique.
[0047] In some embodiments, Figure 2 As shown, step S103 includes sub-steps S1031 and S1032.
[0048] Sub-step S1031 : assigning number information to the structure variable of each node according to the structural relationship of the data abstract syntax tree, and obtaining an initial index entry of each structure variable.
[0049] The initial index entry includes an ID, a variable index number, a space size occupied by the variable, and a space size of a single entity of the variable.
[0050] In some embodiments, the child nodes of the same parent node are numbered in sequence according to the structural relationship of the data abstract syntax tree, the ID of each child node under each parent node is obtained, and the ID of each child node is determined as the ID of the structure variable of the current node. By numbering the child nodes of the same parent node in sequence through the structural relationship, the ID of each structure variable can be accurately obtained.
[0051] For example, Figure 3As shown, the data abstract syntax tree includes structure variables foo-a, structure variables foo-b, structure variables foo-c, structure variables foo-d, structure variables foo-e, structure variables foo-f, structure variables foo-g, structure variables foo-h, structure variables foo-j, structure variables foo-i, structure variables foo-k, structure variables foo-l, structure variables foo-m and structure variables foo-n. Among them, structure variable foo-a is the root node, and the structure variable foo-a is numbered to obtain the ID of structure variable foo-a is 0. Structure variables foo-b, structure variables foo-h and structure variable foo-i are child nodes of the same parent node, then the structure variables foo-b, structure variables foo-h and structure variables foo-i are numbered to obtain the ID of structure variable foo-b is 0, the ID of structure variable foo-h is 1 and the ID of structure variable foo-i is 2.
[0052] If the structure variables foo-c, foo-e and foo-g are child nodes of the same parent node, then the structure variables foo-c, foo-e and foo-g are numbered, and the ID of the structure variable foo-c is 0, the ID of the structure variable foo-e is 1, and the ID of the structure variable foo-g is 2. If the structure variable foo-j does not have a structure variable with the same parent node, then the structure variable foo-j is numbered, and the ID of the structure variable foo-j is 0.
[0053] The structure variables foo-k and foo-l are child nodes of the same parent node. When encoding the structure variables foo-k and foo-l, the ID of the structure variable foo-k is 0, and the ID of the structure variable foo-l is 1. The structure variables foo-m and foo-n are child nodes of the same parent node. When encoding the structure variables foo-m and foo-n, the ID of the structure variable foo-m is 0, and the ID of the structure variable foo-l is 1.
[0054] It should be noted that the ID of this structure variable is self-incrementing, non-transitive, and locally unique. Among them, the self-incrementing property is that in a non-leaf node, it increases one by one from 0 in the order of definition of the child nodes. If a node is deleted in a subsequent version, the ID is still retained and is no longer assigned to other nodes. The non-transitive property is that the ID of a node only depends on the order in which it is defined in the parent node, and the change of the child node will not cause the change of the ID of the node itself. The local uniqueness is that the uniqueness of the ID is only reflected in the adjacent sibling nodes, and the IDs of the upper and lower layers are not related.
[0055] It should be noted that the ID generation of the structure variable is related to the variable name, data type and array size information. It is understandable that the ID corresponding to the variable name, data type and array size is unique. For example, the ID corresponding to the structure variable with variable name A, quantity type int and array size of 8 bytes is 3. After deleting the structure variable with ID 3, the structure variable with variable name A, quantity type int and array size of 8 bytes is obtained again, and the ID assigned to the structure variable is 3.
[0056] It is understandable that Figure 3 Encode the various structure variables in Figure 4 The data abstract syntax tree is shown.
[0057] In some embodiments, the variable index number of the structure variable of each node is determined respectively according to the structural relationship of the data abstract syntax tree. The variable index number of each structure variable can be accurately obtained through the structural relationship of each node in the data abstract syntax tree.
[0058] In some embodiments, it is determined whether the node where the structure variable is located is a leaf node, where the leaf node is a node without child nodes; if the node of the structure variable is a leaf node, the variable index number of the structure variable is set to 1. According to whether the node of the structure variable is a leaf node, the variable index number of the structure variable at each leaf node can be accurately determined.
[0059] In some embodiments, it is determined whether the node where the structure variable is located is a leaf node; if the node where the structure variable is located is a non-leaf node, all subordinate nodes of the node where the structure variable is located are obtained to obtain the number of subordinate nodes of the node; the sum of the number of subordinate nodes plus one is used as the variable index number of the structure variable of the node. When the node where the structure variable is located is a non-leaf node, the variable index number of the structure variable of the node can be accurately determined based on all subordinate nodes of the node.
[0060] For example, Figure 4 As shown, the structure variable foo-c is a leaf node, so the variable index number of the structure variable foo-c is 1; similarly, the structure variable foo-d, the structure variable foo-f, the structure variable foo-g, the structure variable foo-l, the structure variable foo-m and the structure variable foo-n are all leaf nodes, so the variable index numbers of the structure variable foo-d, the structure variable foo-f, the structure variable foo-g, the structure variable foo-l, the structure variable foo-m and the structure variable foo-n are all 1.
[0061] For example, Figure 4As shown, the structure variable foo-a is a non-leaf node, and all its subordinate nodes include the structure variables foo-b, foo-c, foo-d, foo-e, foo-f, foo-g, foo-h, foo-j, foo-i, foo-k, foo-l, foo-m, and foo-n. Then the variable index number of the structure variable foo-a is 14.
[0062] Exemplarily, such as Figure 4 As shown, the structure variable foo-b is a non-leaf node, and all its subordinate nodes include the structure variables foo-c, foo-d, foo-e, foo-f, and foo-g. Then the variable index number of the structure variable foo-b is 6.
[0063] Exemplarily, such as Figure 4 As shown, the structure variable foo-e is a non-leaf node, and all its subordinate nodes include the structure variables foo-d and foo-f. Then the variable index number of the structure variable foo-e is 3. The structure variable foo-h is a non-leaf node, and all its subordinate nodes include the structure variables foo-j, foo-m, and foo-n. Then the variable index number of the structure variable foo-h is 4.
[0064] Exemplarily, such as Figure 4 As shown, the structure variable foo-j is a non-leaf node, and all its subordinate nodes include the structure variables foo-m and foo-n. Then the variable index number of the structure variable foo-j is 3. The structure variable foo-i is a non-leaf node, and all its subordinate nodes include the structure variables foo-k and foo-l. Then the variable index number of the structure variable foo-i is 3.
[0065] In some embodiments, based on a preset memory capacity measurement function, the memory size of the structure variables of each node is calculated to obtain the space size occupied by the variables of the structure variables of each node. The preset memory capacity measurement function can be selected according to the actual situation, and the present invention does not make specific limitations thereon. For example, the preset memory capacity measurement function can be the sizeof function. By calculating the memory size of the structure variables of each node through the preset memory capacity measurement function, the space size occupied by the variables of the structure variables of each node can be accurately obtained.
[0066] In some embodiments, the space size of a single entity of each structure variable is determined based on the space size occupied by the variables of each structure variable; based on the space size occupied by the variables of each structure variable, the space size of a single entity of each structure variable can be accurately obtained.
[0067] In some embodiments, it is determined whether a structure variable is an array variable. If the structure variable is an array variable, the space occupied by the structure variable is divided by the length of the structure variable array variable, and the resulting value is determined as the space size of a single entity of the structure variable.
[0068] In some embodiments, it is determined whether the structure variable is an array variable. If the structure variable is not an array variable, the space occupied by the structure variable is divided by one, and the resulting value is determined as the space size of a single entity of the structure variable.
[0069] In some embodiments, the ID of each structure variable, the number of variable indexes, the size of the space occupied by the variable, and the size of the space of a single entity of the variable are integrated to obtain the initial index entry of each structure variable. By integrating the ID of the structure variable, the number of variable indexes, the size of the space occupied by the variable, and the size of the space of a single entity of the variable, the initial index entry of the structure variable can be accurately obtained.
[0070] For example, the following two structure variables have a nested relationship:
[0071] Typedef struct_child {
[0072] int child_var1; / / ID=0,leaf
[0073] int child_var2; / / ID=1,leaf
[0074] }child;
[0075] typedef struct_parent{
[0076] int parent_var1; / / ID=0, leaf
[0077] Child parent_var2; / / ID=1, no-leaf
[0078] int parent_var3; / / D=3, leaf
[0079] }Parent;
[0080] Construct the data abstract syntax tree and initial index entries for the structure variables to generate Figure 5 The initial index entry table shown, where offset represents the variable index number, size represents the space occupied by the variable, and unitsize represents the space size of a single entity of the variable.
[0081] Sub-step S1032: Encode the initial index entry of each structure variable to obtain a unique index entry for each structure variable.
[0082] In some embodiments, the initial index entry of each structure variable is binary-encoded to obtain a unique index entry for each structure variable. By encoding the initial index entry in machine language, a unique index entry for each structure variable can be accurately obtained.
[0083] Step S104: Separately store the index table composed of the plurality of index entries and the source code structure data, wherein the index table is used to describe the position of each structure data in the source code structure data.
[0084] In some embodiments, the index entry of the node of the data abstract syntax tree is used as the starting point, and the index entry of each node in the data abstract syntax tree is traversed and combined in sequence to obtain the index table, and the index table composed of multiple index entries and the source code structure data are stored separately, and the index table is used to describe the position of each structure data in the source code structure data. The index table describing the source code structure data and the source code structure data are stored separately, which can effectively reduce the storage space required for storing structure variable data. When loading data, the required structure variable data can be quickly found through the index table, which effectively reduces the memory space and parsing time required for parsing the structure variable data, thereby improving the efficiency and accuracy of loading the structure variable data.
[0085] It should be noted that the storage method of the index table and the source code structure data can be set according to the actual situation, and the embodiment of the present invention does not specifically limit this. For example, when the index table and the source code structure data are stored in the same file, the index table is stored in the front part of the file, and the source code structure data is stored in the back part. For another example, when the index table and the source code structure data are stored in different files, the index table is stored in the first file, and the source code structure data is stored in the adjacent second file.
[0086] In some embodiments, a structure variable deletion instruction is obtained, and a target index entry in the index table is determined according to the structure variable deletion instruction; the structure variable of the target index entry in the index table is deleted and the ID of the target index entry is retained. By deleting the structure variable of the target index entry in the index table and retaining the ID of the target index entry, the purpose of deleting the structure variable is achieved, and the uniqueness of the ID is guaranteed.
[0087] Exemplarily, a structure variable deletion instruction is obtained, and the structure variable deletion instruction is to indicate that Figure 4 Delete the structure variable foo-f in , delete the structure variable foo-f, and keep the ID of the structure variable foo-f, and get the following Figure 6 The structure variable syntax tree diagram is shown.
[0088] In some embodiments, a newly added structure variable is obtained, and the position of the newly added node of the newly added structure variable in the data abstract syntax tree is determined; according to the position of the newly added node in the data abstract syntax tree, the parent node of the newly added structure variable is determined, and the IDs of the subordinate child nodes of the parent node are obtained; the ID of the newly added structure variable is incremented according to the IDs of the subordinate child nodes to obtain the ID of the newly added structure variable; the variable index number of the newly added structure variable, the space size occupied by the variable and the space size of a single entity of the variable are determined, and the index entry of the newly added structure variable is generated according to the ID of the newly added structure variable, the variable index number, the space size occupied by the variable and the space size of a single entity of the variable; the index entry of the parent node of the newly added structure variable is updated, and the index entry of the newly added structure variable is updated to the index table.
[0089] Exemplarily, a newly added structure variable foo-u is obtained, and the position of the newly added node of the newly added structure variable foo-u in the data abstract syntax tree is determined; according to the position of the newly added node in the data abstract syntax tree, the parent node of the newly added structure variable foo-u is determined to be the structure variable foo-i, and the IDs of the subordinate child nodes of the parent node structure variable foo-i are obtained, including ID0 and ID1; the ID of the newly added structure variable foo-u is incremented according to the IDs of the subordinate child nodes, and the ID of the newly added structure variable is 2; the following is obtained: Figure 7The structure variable syntax tree diagram shown. Determine the variable index number, the space occupied by the variable, and the space size of a single entity of the variable of the newly added structure variable foo-u, and generate the index entry of the newly added structure variable foo-u according to the ID of the newly added structure variable, the variable index number, the space occupied by the variable, and the space size of a single entity of the variable; update the index entry of the parent node foo-i of the newly added structure variable, and update the index entry of the newly added structure variable foo-u to the index table.
[0090] For example, Figure 8 As shown, an index table consisting of a plurality of index entries is stored in an index table file 11, and source code structure data is stored in a structure parameter file 12. By storing the index table and source code structure data in different files, the space required for storing structure variable data can be effectively reduced, and the required structure variable data can be quickly found through the index table when data is loaded.
[0091] In some embodiments, a data loading request is obtained, which includes the ID of a request structure variable of data to be loaded, and the ID of the first index entry in the index table is matched according to the structure of the data abstract syntax tree to determine whether the ID of the first index entry is the same as the ID of the request structure variable. If not, jump to the adjacent index entry to continue matching; if it is determined that the ID of the first index entry is the same as the ID of the request structure variable, enter the child node of the first index entry to determine whether the child node of the first index entry is a non-leaf node; if the child node of the first index entry is a leaf node, read the index entry of the child node of the first index entry, and determine the index entry as a target index entry; according to the target index entry, obtain the source code structure data from the file storing the source code structure data. If the child node of the first index entry is not a leaf node, determine whether the ID of the index entry of the child node is the same as the ID of the requested structure variable. If not, jump to the adjacent index entry to continue matching; determine whether the ID of the index entry of the child node is the same as the ID of the requested structure variable, determine whether the child node of the child node is a non-leaf node, if the child node of the child node is a leaf node, read the index entry of the child node of the child node, and determine the index entry as the target index entry. If the child node of the child node is a non-leaf node, return to the step of determining whether the ID of the index entry of the child node is the same as the ID of the requested structure variable, until the target index entry is obtained, and obtain the source code structure data from the file storing the source code structure data according to the target index entry.
[0092] For example, Fig. 9As shown, two pointers pentry and pdata are defined, pentry points to the head of the index table, and pdata points to the head of the source code structure data. Starting from the first index entry (node, entry), compare whether the node ID matches the request ID. If not, pentry jumps to the next node position (pentry+=pentry->offset); otherwise, entry+=1, enter the child node, and then determine whether the current node is a non-leaf node. If it is a non-leaf node, enter the next layer; if it is a leaf node, read pdata to the corresponding position of the structure variable, and execute the entire query process cyclically to obtain the source code structure data corresponding to the structure variable.
[0093] By generating an index table, the structure variable data can be accurately described. When the structure variable data is added or deleted, only the changed structure variables need to be modified, and other unchanged structure data can still be used normally. When loading data, the index table can accurately query the structure variables to be loaded, reducing the memory space and parsing time required for parsing the structure variable data.
[0094] The data storage method provided by the above embodiment obtains source code structure data to be stored, and the source code structure data includes multiple structure variables; then, based on the syntax structure of the source code structure data, an abstract syntax tree is constructed for each structure variable, so that the data abstract syntax tree can be accurately obtained; the structure variable of each node of the data abstract syntax tree is encoded with a structure variable to obtain a unique index entry for each structure variable, and the index entry is used to describe the node structure information; then, the index table composed of the multiple index entries and the source code structure data are distinguished and stored, and the index table is used to describe the position of each structure data in the source code structure data. In the present application, by storing the index table describing the source code structure data and the source code structure data in different files respectively, the flash space required for storing the structure variable data can be effectively reduced, and the required structure variable data can be quickly found through the index table when the data is loaded, which effectively reduces the memory space and parsing time required for parsing the structure variable data, thereby improving the loading efficiency and accuracy of the structure variable data.
[0095] See also Fig.10 , Fig.10 A schematic block diagram of a data storage device provided in an embodiment of the present application.
[0096] like Fig.10 As shown, the data storage device 200 includes an acquisition module 210, a generation module 220, an encoding module 230 and a storage module 240, wherein:
[0097] The acquisition module 210 is used to acquire source code structure data to be stored, wherein the source code structure data includes a plurality of structure variables;
[0098] The generating module 220 is used to construct an abstract syntax tree for each structure variable based on the syntax structure of the source code structure data to obtain a data abstract syntax tree;
[0099] The encoding module 230 is used to perform structure variable encoding on the structure variable of each node of the data abstract syntax tree to obtain a unique index entry for each structure variable, wherein the index entry is used to describe the node structure information;
[0100] The storage module 240 is used to distinguish and store the index table composed of a plurality of index entries and the source code structure data, wherein the index table is used to describe the position of each structure data in the source code structure data.
[0101] In some embodiments, the encoding module 230 is further configured to:
[0102] Assigning number information to the structure variable of each node according to the structural relationship of the data abstract syntax tree to obtain an initial index entry of each structure variable;
[0103] The initial index entry of each structure variable is encoded to obtain a unique index entry for each structure variable.
[0104] In some embodiments, the encoding module 230 is further configured to:
[0105] According to the structural relationship of the data abstract syntax tree, the child nodes of the same parent node are numbered in sequence to obtain the ID of each child node under each parent node, and the ID of each child node is determined as the ID of the structure variable of the current node;
[0106] Determine the variable index number of the structure variable of each node according to the structural relationship of the data abstract syntax tree;
[0107] Calculate the memory size of the structure variable of each node based on a preset memory capacity measurement function to obtain the space occupied by the structure variable of each node;
[0108] Determine the space size of a single entity of each structure variable according to the space size occupied by the variable of each structure variable;
[0109] The ID of each structure variable, the variable index number, the space occupied by the variable and the space size of a single entity of the variable are integrated to obtain an initial index entry of each structure variable.
[0110] In some embodiments, the encoding module 230 is further configured to:
[0111] Determine whether the node where the structure variable is located is a leaf node, and the leaf node is a node that has no child nodes;
[0112] If the node where the structure variable is located is a leaf node, the variable index number of the structure variable is set to 1.
[0113] In some embodiments, the encoding module 230 is further configured to:
[0114] If the node where the structure variable is located is a non-leaf node, obtain all subordinate nodes of the node where the structure variable is located to obtain the number of subordinate nodes of the node;
[0115] The sum of the number of subordinate nodes plus one is used as the variable index number of the structure variable of this node.
[0116] In some embodiments, the data storage device 200 is further used for:
[0117] The index entry of the node of the data abstract syntax tree is taken as the starting point, and the index entry of each node in the data abstract syntax tree is traversed and combined in sequence to obtain the index table.
[0118] In some embodiments, the data storage device 200 is further used for:
[0119] Obtaining a structure variable deletion instruction, and determining a target index entry in the index table according to the structure variable deletion instruction;
[0120] The structure variable of the target index entry in the index table is deleted and the ID of the target index entry is retained.
[0121] In some embodiments, the data storage device 200 is further used for:
[0122] Acquire a newly added structure variable, and determine the position of a newly added node of the newly added structure variable in the data abstract syntax tree;
[0123] Determine the parent node of the newly added structure variable according to the position of the newly added node in the data abstract syntax tree, and obtain the IDs of each child node under the parent node;
[0124] Increment the ID of the newly added structure variable according to the ID of each subordinate child node to obtain the ID of the newly added structure variable;
[0125] Determine the variable index number, the space size occupied by the variable, and the space size of a single entity of the variable of the newly added structure variable, and generate an index entry of the newly added structure variable according to the ID, variable index number, the space size occupied by the variable, and the space size of a single entity of the variable;
[0126] The index entry of the parent node of the newly added structure variable is updated, and the index entry of the newly added structure variable is updated to the index table.
[0127] It should be noted that those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the above-mentioned data storage device can refer to the corresponding process in the aforementioned data storage method embodiment, and will not be repeated here.
[0128] See also Fig.11 , Fig.11 A schematic block diagram of the structure of a terminal device provided in an embodiment of the present application.
[0129] like Fig.11 As shown, the terminal device 300 includes a processor 302 and a memory 303 connected via a system bus 301, wherein the memory may include a storage medium and an internal memory.
[0130] The storage medium can store a computer program. The computer program includes program instructions, and when the program instructions are executed, the processor can execute any data storage method.
[0131] The processor 302 is used to provide computing and control capabilities to support the operation of the entire terminal device.
[0132] The internal memory provides an environment for the operation of the computer program in the storage medium. When the computer program is executed by the processor, the processor can execute any data storage method.
[0133] Those skilled in the art will understand that Fig.11 The structure shown in the figure is only a block diagram of a partial structure related to the scheme of the present application, and does not constitute a limitation on the terminal device to which the scheme of the present application is applied. The specific terminal device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0134] It should be understood that the processor 302 may be a central processing unit (CPU), and the processor may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Among them, the general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0135] In one embodiment, the processor 302 is used to run a computer program stored in the memory to implement the following steps:
[0136] Acquire source code structure data to be stored, wherein the source code structure data includes a plurality of structure variables;
[0137] Based on the syntax structure of the source code structure data, an abstract syntax tree is constructed for each structure variable to obtain a data abstract syntax tree;
[0138] Performing structure variable encoding on the structure variable of each node of the data abstract syntax tree to obtain a unique index entry for each structure variable, wherein the index entry is used to describe the node structure information;
[0139] An index table composed of a plurality of index entries and source code structure data are stored separately, wherein the index table is used to describe the position of each structure data in the source code structure data.
[0140] In one embodiment, when implementing the structure variable encoding of the structure variable of each node of the data abstract syntax tree to obtain a unique index entry for each structure variable, the processor is used to implement:
[0141] Assigning number information to the structure variable of each node according to the structural relationship of the data abstract syntax tree to obtain an initial index entry of each structure variable;
[0142] The initial index entry of each structure variable is encoded to obtain a unique index entry for each structure variable.
[0143] In one embodiment, the initial index entry includes an ID, a variable index number, a space size occupied by the variable, and a space size of a single entity of the variable. When the processor assigns numbering information to the structure variable of each node according to the structural relationship of the data abstract syntax tree to obtain the initial index entry of each structure variable, it is used to implement:
[0144] According to the structural relationship of the data abstract syntax tree, the child nodes of the same parent node are numbered in sequence to obtain the ID of each child node under each parent node, and the ID of each child node is determined as the ID of the structure variable of the current node;
[0145] Determine the variable index number of the structure variable of each node according to the structural relationship of the data abstract syntax tree;
[0146] Calculate the memory size of the structure variable of each node based on a preset memory capacity measurement function to obtain the space occupied by the structure variable of each node;
[0147] Determine the space size of a single entity of each structure variable according to the space size occupied by the variable of each structure variable;
[0148] The ID of each structure variable, the variable index number, the space occupied by the variable and the space size of a single entity of the variable are integrated to obtain an initial index entry of each structure variable.
[0149] In one embodiment, when the processor implements the step of respectively determining the variable index number of the structure variable of each node according to the structural relationship of the data abstract syntax tree, it is configured to implement:
[0150] Determine whether the node where the structure variable is located is a leaf node, and the leaf node is a node that has no child nodes;
[0151] If the node where the structure variable is located is a leaf node, the variable index number of the structure variable is set to 1.
[0152] In one embodiment, after implementing the step of determining whether the node where the structure variable is located is a leaf node, the processor is further configured to implement:
[0153] If the node where the structure variable is located is a non-leaf node, obtain all subordinate nodes of the node where the structure variable is located to obtain the number of subordinate nodes of the node;
[0154] The sum of the number of subordinate nodes plus one is used as the variable index number of the structure variable of this node.
[0155] In one embodiment, the processor is further configured to implement:
[0156] The index entry of the node of the data abstract syntax tree is taken as the starting point, and the index entry of each node in the data abstract syntax tree is traversed and combined in sequence to obtain the index table.
[0157] In one embodiment, the processor is further configured to implement:
[0158] Obtaining a structure variable deletion instruction, and determining a target index entry in the index table according to the structure variable deletion instruction;
[0159] The structure variable of the target index entry in the index table is deleted and the ID of the target index entry is retained.
[0160] In one embodiment, the processor is further configured to implement:
[0161] Acquire a newly added structure variable, and determine the position of a newly added node of the newly added structure variable in the data abstract syntax tree;
[0162] Determine the parent node of the newly added structure variable according to the position of the newly added node in the data abstract syntax tree, and obtain the IDs of each child node under the parent node;
[0163] Increment the ID of the newly added structure variable according to the ID of each subordinate child node to obtain the ID of the newly added structure variable;
[0164] Determine the variable index number, the space size occupied by the variable, and the space size of a single entity of the variable of the newly added structure variable, and generate an index entry of the newly added structure variable according to the ID, variable index number, the space size occupied by the variable, and the space size of a single entity of the variable;
[0165] The index entry of the parent node of the newly added structure variable is updated, and the index entry of the newly added structure variable is updated to the index table.
[0166] It should be noted that technicians in the relevant field can clearly understand that for the convenience and brevity of description, the specific working process of the terminal device described above can refer to the corresponding process in the aforementioned data storage method embodiment, and will not be repeated here.
[0167] An embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. The computer program includes program instructions. The method implemented when the program instructions are executed can refer to the various embodiments of the data storage method of the present application.
[0168] The computer-readable storage medium may be an internal storage unit of the terminal device described in the foregoing embodiment, such as a hard disk or memory of the terminal device. The computer-readable storage medium may be non-volatile or volatile. The computer-readable storage medium may also be an external storage device of the terminal device, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (SecureDigital, SD) card, a flash card (Flash Card), etc., equipped on the terminal device.
[0169] It should be understood that the terms used in this application specification are only for the purpose of describing specific embodiments and are not intended to limit the application. As used in this application specification, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.
[0170] It should also be understood that the term "and / or" used in the present specification refers to any combination of one or more of the associated listed items and all possible combinations, including these combinations. It should be noted that, in this article, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "including a..." does not exclude the presence of other identical elements in the process, method, article or system including the element.
[0171] The serial numbers of the embodiments of the present application are for description only and do not represent the advantages and disadvantages of the embodiments. The above description is only a specific implementation mode of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in the present application, and these modifications or replacements should be included in the protection scope of the present application.
Claims
1. A data storage method, characterized in that: include: Acquire source code structure data to be stored, wherein the source code structure data includes a plurality of structure variables; Based on the syntax structure of the source code structure data, an abstract syntax tree is constructed for each structure variable to obtain a data abstract syntax tree; Performing structure variable encoding on the structure variable of each node of the data abstract syntax tree to obtain a unique index entry for each structure variable, wherein the index entry is used to describe the node structure information; An index table composed of a plurality of index entries and source code structure data are stored separately, wherein the index table is used to describe the position of each structure data in the source code structure data.
2. The data storage method according to claim 1, characterized in that: The step of encoding the structure variable of each node of the data abstract syntax tree to obtain a unique index entry for each structure variable includes: Assigning number information to the structure variable of each node according to the structural relationship of the data abstract syntax tree to obtain an initial index entry of each structure variable; The initial index entry of each structure variable is encoded to obtain a unique index entry for each structure variable.
3. The data storage method according to claim 2, characterized in that: The initial index entry includes an ID, a variable index number, a space size occupied by the variable, and a space size of a single entity of the variable; assigning number information to the structure variable of each node according to the structural relationship of the data abstract syntax tree to obtain an initial index entry for each structure variable, including: According to the structural relationship of the data abstract syntax tree, the child nodes of the same parent node are numbered in sequence to obtain the ID of each child node under each parent node, and the ID of each child node is determined as the ID of the structure variable of the current node; Determine the variable index number of the structure variable of each node according to the structural relationship of the data abstract syntax tree; Calculate the memory size of the structure variable of each node based on a preset memory capacity measurement function to obtain the space occupied by the structure variable of each node; Determine the space size of a single entity of each structure variable according to the space size occupied by the variable of each structure variable; The ID of each structure variable, the variable index number, the space occupied by the variable and the space size of a single entity of the variable are integrated to obtain an initial index entry of each structure variable.
4. The data storage method according to claim 3, characterized in that: The step of determining the variable index number of the structure variable of each node according to the structural relationship of the data abstract syntax tree comprises: Determine whether the node where the structure variable is located is a leaf node, and the leaf node is a node that has no child nodes; If the node where the structure variable is located is a leaf node, the variable index number of the structure variable is set to 1.
5. The data storage method according to claim 4, characterized in that: After determining whether the node where the structure variable is located is a leaf node, the method further includes: If the node where the structure variable is located is a non-leaf node, obtain all subordinate nodes of the node where the structure variable is located to obtain the number of subordinate nodes of the node; The sum of the number of subordinate nodes plus one is used as the variable index number of the structure variable of this node.
6. The data storage method according to claim 1, characterized in that: The method further comprises: The index entry of the node of the data abstract syntax tree is taken as the starting point, and the index entry of each node in the data abstract syntax tree is traversed and combined in sequence to obtain the index table.
7. The data storage method according to any one of claims 1 to 6, characterized in that: The method further comprises: Obtaining a structure variable deletion instruction, and determining a target index entry in the index table according to the structure variable deletion instruction; The structure variable of the target index entry in the index table is deleted and the ID of the target index entry is retained.
8. The data storage method according to any one of claims 1 to 6, characterized in that: The method further comprises: Acquire a newly added structure variable, and determine the position of a newly added node of the newly added structure variable in the data abstract syntax tree; Determine the parent node of the newly added structure variable according to the position of the newly added node in the data abstract syntax tree, and obtain the IDs of each child node under the parent node; Increment the ID of the newly added structure variable according to the ID of each subordinate child node to obtain the ID of the newly added structure variable; Determine the variable index number, the space size occupied by the variable, and the space size of a single entity of the variable of the newly added structure variable, and generate an index entry of the newly added structure variable according to the ID, variable index number, the space size occupied by the variable, and the space size of a single entity of the variable; The index entry of the parent node of the newly added structure variable is updated, and the index entry of the newly added structure variable is updated to the index table.
9. A terminal device, characterized in that: The terminal device comprises a processor, a memory, and a computer program stored in the memory and executable by the processor, wherein when the computer program is executed by the processor, the steps of the data storage method according to any one of claims 1 to 8 are implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein when the computer program is executed by a processor, the steps of the data storage method according to any one of claims 1 to 8 are implemented.