Query method for diversified structure data in memory, storage medium, equipment and computer program product
By defining data structures in memory and creating red and black binary tree indexes, using primary key fields and stack space arrays to realize fast query of diversified structure data, the problem of inefficiency of sequential traversal and diversified queries in the existing technology is solved, and efficient data search and traversal is achieved.
Patent Information
- Application Number
- CN202411730657.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-29
- Publication Date
- 2025-04-22
AI Technical Summary
The prior art has problems with inefficiency in sequential traversal and diversified structured data query, especially in the case of imbalances of red and black binary trees and cache misses.
Define different data structures in memory, save the pointers of the data entity to an array in the stack space, create a red and black binary tree index, query it through the primary key field, and use the self-balancing of the red and black binary tree and the fast traversal of the stack space array to achieve a quick search of diversified structure data.
Determine the query results through a unique primary key field, ensure the consistency and accuracy of the query results, reduce the query time complexity, improve the search speed, and achieve fast traversal through array traversal of O(1) time complexity.
Smart Images

Figure CN119862205A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of structured data query, and in particular to a query method, storage medium, device and computer program product for diversified structured data in a memory. Background Art
[0002] The existing C++ standard library containers, such as map, are implemented at the bottom by using a red-black binary tree to store the relationship between data primary keys and data entities. However, the red-black binary tree is not ideal in sequential traversal for the following reasons: the red-black tree maintains balance through rotation and color adjustment, but this does not mean that the nodes are physically continuous in storage. Sequential traversal usually requires continuous access to nodes in memory, but the node distribution of the red-black binary tree is random, which means that in sequential traversal, each access to the next node may require jumping to a different location in memory, resulting in an increase in cache misses and a reduction in traversal speed. At the same time, when a large amount of irregular structured data is inserted, the underlying red-black binary tree of the map will be unbalanced, which will affect the query performance of the data.
[0003] The existing method of querying data through a query function requires sorting the data first and then searching for the data according to the query function. However, the search function of the map container itself can only support one custom comparison object. When there are multiple different structured data, it cannot meet the query needs of diversified structured data. Summary of the invention
[0004] In response to the problems existing in the prior art, the present invention provides a query method, storage medium, device and computer program product for diversified structured data in memory, which stores different types of structured data in a structured memory and can realize rapid traversal and search of diversified structured data.
[0005] To achieve the above technical objectives, the present invention adopts the following technical solution: a method for querying diversified structured data in memory, specifically comprising the following steps:
[0006] Step 1: define different data structures in memory according to business needs, store the collected business data in different data structures, save the data entity of each data structure in the heap memory, and save the pointer of the data entity in the array of the stack space; the first field of the data structure is set to long type as the primary key field;
[0007] Step 2: Create a red-black binary tree index based on the pointer of the data entity and the primary key field of the data entity;
[0008] Step 3: Traverse the red-black binary tree index in sequence for the primary key fields of the data to be queried. If the primary key field in the red-black binary tree index is the same as the primary key field of the data to be queried, the query is successful.
[0009] Furthermore, the primary key field of the data entity is a unique value.
[0010] Furthermore, the address of the starting position of the array in the stack space is obtained, and all arrays are sequentially traversed according to the address of the starting position to achieve traversal of all business data.
[0011] Furthermore, in step 3, when the primary key fields of the data to be queried are sequentially traversed through the red-black binary tree index, the traversal starts from the root node of the red-black binary tree.
[0012] Furthermore, if in step 3, after traversing the red-black binary tree index, no red-black binary tree index with the same primary key field as the data to be queried is found, it means that the data to be queried does not exist, and the data to be queried is stored in the data structure in the memory, and the primary key field and the red-black binary tree index are updated.
[0013] Furthermore, the present invention also provides a computer-readable storage medium storing a computer program, wherein the computer program enables a computer to execute the method for querying diversified structured data in a memory.
[0014] Furthermore, the present invention also provides an electronic 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 querying the diversified structured data in the memory is implemented.
[0015] Furthermore, the present invention also provides a computer program product, including a computer program, which implements the method for querying diversified structured data in memory when executed by a processor.
[0016] Compared with the prior art, the present invention has the following beneficial effects: the query method of diversified structure data in the memory of the present invention has a unique value of the primary key field of different structure data entities. When the primary key field of the data to be queried matches the primary key field in the red-black binary tree index, the query result can be uniquely determined to ensure the consistency and accuracy of the query result. At the same time, due to the self-balancing property of the red-black binary tree, the time complexity of the query is low, and the search speed can be improved. By comparing the primary key field, the corresponding node in the red-black binary tree index can be quickly located, so as to quickly obtain the query result; in addition, the present invention adopts the stack space array structure for fast traversal, and can directly access any element in the array by calculating the address of the memory. The time complexity of this access method is O(1), that is, the time required to access an element at any position is constant time. At the same time, the data entity of the heap memory is accessed through the pointer of the data entity, which can avoid indirect reference and copying of data. In summary, the present invention can ensure that different types of structure data are stored in a structure memory, and can realize fast traversal and search of diversified structure data. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 A flowchart of a method for querying diversified structured data in a memory of the present invention;
[0018] Figure 2 Schematic diagram of the memory structure in the present invention. DETAILED DESCRIPTION
[0019] The technical solution of the present invention is further explained below in conjunction with the accompanying drawings.
[0020] like Figure 1 The flowchart of the query method of the diversified structure data in the memory of the present invention comprises the following steps:
[0021] Step 1: Figure 2 , define different data structures in memory according to business needs, store the collected business data in different data structures, save the data entity of each data structure to the heap memory, save the pointer of the data entity to the array in the stack space, and use the pointer of the data entity as the array index; in the present invention, the first field of the data structure is set to long type, so that the value of the pointer offset of 4 bytes of the data entity is the primary key, which is used as the primary key field, and ensures that the primary key field of the data entity is a unique value, which is convenient for comparison in the subsequent data query process.
[0022] Step 2: Create a red-black binary tree index based on the pointer of the data entity and the primary key field of the data entity. Since the memory can ensure that the value of the hexadecimal pointer of the memory address is relatively ordered, combined with the rotation of the tree, the self-balancing of the red-black binary tree can be maintained, reducing the time complexity of the query operation.
[0023] Step 3, traverse the red-black binary tree index in sequence for the primary key field of the data to be queried. Specifically, start traversing from the root node of the red-black binary tree. If there is a primary key field in the red-black binary tree index that is the same as the primary key field of the data to be queried, it means that the query is successful. Since the primary key field is a unique value, when the primary key field of the data to be queried matches the primary key field in the red-black binary tree index, the query result can be uniquely determined to ensure the consistency and accuracy of the query result. At the same time, due to the self-balancing nature of the red-black binary tree, the time complexity of the query is low, which can improve the search speed. By comparing the primary key field, the corresponding node in the red-black binary tree index can be quickly located, thereby quickly obtaining the query result. If the red-black binary tree index is traversed and the red-black binary tree index with the same primary key field as the data to be queried is still not found, it means that the data to be queried does not exist, and the data to be queried is stored in the data structure of the memory, and the primary key field and the red-black binary tree index are updated.
[0024] In a technical solution of the present invention, by obtaining the address of the starting position of the array in the stack space, all arrays are sequentially traversed according to the address of the starting position to achieve traversal of all business data. The stack space array structure is used for fast traversal, and any element in the array can be quickly accessed by directly calculating the address of the memory. The time complexity of this access method is O(1), that is, the time required to access an element at any position is constant time. At the same time, accessing the data entity in the heap memory through the pointer of the data entity can avoid indirect reference and copying of data.
[0025] In a technical solution of the present invention, a computer-readable storage medium is also provided, storing a computer program, wherein the computer program enables a computer to execute the method for querying diversified structured data in a memory.
[0026] In a technical solution of the present invention, an electronic device is also provided, including: 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 querying the diversified structured data in the memory is implemented.
[0027] In a technical solution of the present invention, a computer program product is also provided, including a computer program, and when the computer program is executed by a processor, the method for querying the diversified structured data in the memory is implemented.
[0028] In the embodiments disclosed in the present application, the computer storage medium can be a tangible medium that can contain or store a program for use by or in conjunction with an instruction execution system, device or equipment. The computer storage medium can include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the above. More specific examples of computer storage media can include electrical connections based on one or more lines, portable computer disks, hard disks, random access memories (RAM), read-only memories (ROM), erasable programmable read-only memories (EPROM or flash memory), optical fibers, portable compact disk read-only memories (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the above.
[0029] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed in this application can be implemented in electronic hardware or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0030] The above are only preferred embodiments of the present invention, and the protection scope of the present invention is not limited to the above embodiments. All technical solutions under the concept of the present invention belong to the protection scope of the present invention. It should be pointed out that for ordinary technicians in this technical field, some improvements and modifications without departing from the principle of the present invention should be regarded as the protection scope of the present invention.
Claims
1. A method for querying diversified structured data in memory, characterized in that: The specific steps include: Step 1: define different data structures in memory according to business needs, store the collected business data in different data structures, save the data entity of each data structure in the heap memory, and save the pointer of the data entity in the array of the stack space; the first field of the data structure is set to long type as the primary key field; Step 2: Create a red-black binary tree index based on the pointer of the data entity and the primary key field of the data entity; Step 3: Traverse the red-black binary tree index in sequence for the primary key fields of the data to be queried. If the primary key field in the red-black binary tree index is the same as the primary key field of the data to be queried, the query is successful.
2. A method for querying diversified structured data in memory according to claim 1, characterized in that: The primary key field of the data entity is a unique value.
3. A method for querying diversified structured data in memory according to claim 1, characterized in that: Get the address of the starting position of the array in the stack space, traverse all arrays in sequence according to the address of the starting position, and realize the traversal of all business data.
4. A method for querying diversified structured data in memory according to claim 1, characterized in that: In step 3, when the primary key fields of the data to be queried are traversed sequentially through the red-black binary tree index, the traversal starts from the root node of the red-black binary tree.
5. The method for querying diversified structured data in memory according to claim 1, characterized in that: Step 3: If after traversing the red-black binary tree index, no red-black binary tree index with the same primary key field as the data to be queried is found, it means that the data to be queried does not exist. The data to be queried is stored in the data structure in the memory, and the primary key field and the red-black binary tree index are updated.
6. A computer-readable storage medium storing a computer program, characterized in that: The computer program enables a computer to execute the method for querying diversified structured data in a memory as described in any one of claims 1 to 5.
7. An electronic device, characterized in that: include: 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 querying diversified structured data in a memory as described in any one of claims 1 to 5 is implemented.
8. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the method for querying diversified structure data in a memory as described in any one of claims 1 to 5 is implemented.