A data storage method, device, computer equipment and storage medium
By generating a temporary array within the circular array and updating the data pointer, the storage problem of fixed-field circular arrays when the data volume fluctuates is solved, enabling seamless data migration and expansion, ensuring data consistency and security, and improving storage efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- PING AN TECH (SHENZHEN) CO LTD
- Filing Date
- 2024-08-21
- Publication Date
- 2026-06-16
AI Technical Summary
Fixed-field circular arrays cannot store data of varying sizes, resulting in wasted space or the need for complex data migration operations when data volume fluctuates, affecting data storage efficiency and integrity.
By copying a circular array to generate a temporary array, storing the data and updating the data pointers, data consistency and security are ensured, enabling seamless data migration and expansion.
It effectively solves the storage problem of fixed-field circular arrays when the data volume fluctuates, maintains data integrity, simplifies the transition of storage structure, and improves the flexibility and efficiency of data storage.
Smart Images

Figure CN119202319B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of big data technology, specifically relating to a data storage method, apparatus, computer equipment, and storage medium. Background Technology
[0002] A fixed-field circular array is a data structure that combines the characteristics of arrays and circular queues. In this storage method, each element of the array is designed to be of a fixed size to store a specific type of data field. When data is added to the array, the stored data fills the array space sequentially, and when the end of the array is reached, it cycles back to the beginning of the array to continue storing data. Fixed-field circular arrays are suitable for scenarios that require frequent insertion and deletion operations and do not have a high need to retain old data, such as buffer management and real-time data processing.
[0003] However, fixed-field circular arrays also have some drawbacks. For example, because the size of each field is fixed, they cannot store data of varying sizes, which limits their application scenarios. When the amount of data to be stored is much smaller than the total capacity of the array, the remaining space will be wasted, especially when the system's data volume fluctuates greatly. When more data needs to be stored, if the fixed-size array is full, it may be necessary to overwrite data or reallocate a larger array for data migration. The former will result in data loss, while the latter increases the complexity and cost of the operation. Summary of the Invention
[0004] The purpose of this application is to provide a data storage method, apparatus, computer device, and storage medium, aiming to provide a method for changing the capacity of a cyclic array to achieve flexible data storage.
[0005] To address the aforementioned technical problems, this application provides a data storage method, employing the following technical solution:
[0006] A data storage method, applied to a circular array in a database storage structure, includes:
[0007] Receive data storage instructions and determine the amount of data to be stored and the remaining storage space of the circular array;
[0008] When the amount of data to be stored exceeds the storage capacity of the circular array, the circular array is copied to generate a temporary circular array.
[0009] The data to be stored is stored in a temporary circular array until the temporary circular array is full, and the unstored data is stored in the circular array.
[0010] Receive the storage update instruction, point the data pointer to the temporary circular array, and delete the circular array.
[0011] Furthermore, the circular array is configured with a matching index array. When the amount of data to be stored exceeds the storage capacity of the circular array, the circular array is copied to generate a temporary circular array. This also includes:
[0012] Copy the index array of the circular array to obtain a temporary index array, where the temporary index array matches the temporary circular array;
[0013] Clear the data stored in the circular array and update the index array.
[0014] Furthermore, the data to be stored is stored in a temporary circular array until the temporary circular array is full, and any unstored data is stored in the circular array. Specifically, this includes:
[0015] The starting position of the data to be stored in the temporary circular array is determined based on the temporary index array, thus obtaining the first data starting position;
[0016] Set the database pointer to a temporary circular array, and start filling the temporary circular array with data to be stored, starting from the first data position, until the temporary circular array is full.
[0017] Determine the remaining amount of data to be stored, point the data pointer to the circular array, and start from the initial storage position of the circular array to fill the remaining amount of data to be stored into the circular array in sequence until the storage of the data to be stored is completed.
[0018] Furthermore, after setting the database's data pointer to a temporary circular array, and sequentially filling the temporary circular array with data to be stored, starting from the first data position, until the temporary circular array is full, the process also includes:
[0019] Determine if the remaining amount of data to be stored is greater than the data storage capacity of the circular array;
[0020] When the remaining amount of data to be stored is greater than the data storage capacity of the circular array, the cleared circular array is copied to generate a new circular array.
[0021] Furthermore, before receiving the storage update instruction, pointing the data pointer to the temporary circular array, and deleting the circular array, the following steps are also included:
[0022] Receive a data read instruction and determine the storage location of the data to be read in the database. The data read instruction carries a data read location identifier.
[0023] When the data to be read is stored in a circular array or a temporary circular array, the data to be read is extracted and copied from the circular array or the temporary circular array based on the data reading position identifier, the first data reading result is generated, and the first data reading result is output.
[0024] When the data to be read is stored in both a circular array and a temporary circular array, the position of the data reading position marker in the temporary circular array is determined, and the first data segment to be read is obtained from the temporary circular array. The position of the data reading position marker in the circular array is determined, and the second data segment to be read is obtained from the circular array. The second data reading result is generated based on the first and second data segments to be read, and the second data reading result is output.
[0025] Furthermore, the data read position identifier includes a data read start bit and a data read end bit. The position of the data read position identifier in the temporary circular array is determined, and a first data segment to be read is obtained from the temporary circular array. The position of the data read position identifier in the circular array is determined, and a second data segment to be read is obtained from the circular array. A second data read result is generated based on the first and second data segments to be read, and the second data read result is output. Specifically, this includes:
[0026] When the start position of the data to be read is located in the temporary circular array and the end position of the data to be read is located in the circular array, the first data segment to be read is determined based on the temporary index array and the start position of the data to be read, and the second data segment to be read is determined based on the index array and the end position of the data to be read.
[0027] When the start position of the data to be read is located in the circular array and the end position of the data to be read is located in the temporary circular array, the first data segment to be read is determined based on the index array and the start position of the data to be read, and the second data segment to be read is determined based on the temporary index array and the end position of the data to be read.
[0028] Combine the first data segment to be read and the second data segment to be read to generate the second data reading result, and output the second data reading result.
[0029] Furthermore, after receiving the data storage instruction and determining the amount of data to be stored and the remaining storage space of the circular array, the process also includes:
[0030] When the amount of data to be stored is less than or equal to the storage capacity of the circular array, the starting position of the data to be stored in the circular array is determined based on the index array to obtain the second starting position of the data;
[0031] Point the data pointer to the circular array, and starting from the second data position, fill the circular array with the data to be stored one by one until the data to be stored is stored.
[0032] To address the aforementioned technical problems, this application also provides a data storage device, which employs the following technical solution:
[0033] A data storage device that performs the data storage method as described above, the data storage method being applied to a circular array in a database storage structure, the data storage device comprising:
[0034] The storage instruction receiving module is used to receive data storage instructions and determine the amount of data to be stored and the storage capacity of the circular array;
[0035] The first array copying module is used to copy the circular array and generate a temporary circular array when the amount of data to be stored is greater than the storage capacity of the circular array.
[0036] The data storage module is used to store the data to be stored in a temporary circular array until the temporary circular array is full, and to store the unstored data to be stored into the circular array.
[0037] The storage update instruction module is used to receive storage update instructions, point the data pointer to the temporary circular array, and delete the circular array.
[0038] To address the aforementioned technical problems, this application also provides a computer device that employs the following technical solution:
[0039] A computer device includes a memory and a processor, the memory storing computer-readable instructions, the processor executing the computer-readable instructions to implement the steps of the data storage method as described in any of the preceding claims.
[0040] To address the aforementioned technical problems, this application also provides a computer-readable storage medium, employing the technical solution described below:
[0041] A computer-readable storage medium storing computer-readable instructions that, when executed by a processor, implement the steps of the data storage method as described in any one of the above descriptions.
[0042] Compared with the prior art, the embodiments of this application have the following main advantages:
[0043] This invention relates to a data storage method, apparatus, computer equipment, and storage medium, belonging to the field of big data technology. The data storage method is applied to circular arrays in database storage structures. Unlike traditional storage schemes that simply reject new data or overwrite old data when the amount of data to be stored exceeds the capacity of the current circular array, this application adopts a strategy of copying the original circular array to a temporary array. This preserves the integrity of the original array data, ensures data consistency and security, and efficiently handles the continuous storage needs of large amounts of data, avoiding data loss or processing interruptions due to capacity limitations. After partial data storage is completed in the temporary circular array, the remaining data is added to the original circular array in an orderly manner, achieving seamless data migration and expansion. Furthermore, by updating data pointers and deleting the old circular array, a smooth transition of the storage structure is achieved, reducing the waste of system resources and simplifying the logic of subsequent data access. Attached Figure Description
[0044] To more clearly illustrate the solutions in this application, the accompanying drawings used in the description of the embodiments of this application will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0045] Figure 1 An exemplary system architecture diagram is shown, in which this application can be applied;
[0046] Figure 2 A flowchart of one embodiment of the data storage method according to this application is shown;
[0047] Figure 3 A schematic diagram of the structure of an embodiment of a data storage device according to this application is shown;
[0048] Figure 4 A schematic diagram of the structure of one embodiment of a computer device according to this application is shown. Detailed Implementation
[0049] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains; the terminology used herein in the specification of the application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application; the terms "comprising" and "having," and any variations thereof, in the specification, claims, and foregoing drawings of this application, are intended to cover non-exclusive inclusion. The terms "first," "second," etc., in the specification, claims, or foregoing drawings of this application are used to distinguish different objects, not to describe a particular order.
[0050] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0051] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings.
[0052] like Figure 1 As shown, system architecture 100 may include terminal device 101, network 102, and server 103. Terminal device 101 may be a laptop 1011, tablet 1012, or mobile phone 1013. Network 102 is used as a medium to provide a communication link between terminal device 101 and server 103. Network 102 may include various connection types, such as wired, wireless communication links, or fiber optic cables.
[0053] Users can use terminal device 101 to interact with server 103 via network 102 to receive or send messages, etc. Various communication client applications can be installed on terminal device 101, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social media platform software, etc.
[0054] Terminal device 101 can be various electronic devices with a display screen and support web browsing. In addition to laptops 1011, tablets 1012, or mobile phones 1013, terminal device 101 can also be an e-book reader, MP3 player (Moving Picture Experts Group Audio Layer III), MP4 player (Moving Picture Experts Group Audio Layer IV), laptop computer, and desktop computer, etc.
[0055] Server 103 can be a server that provides various services, such as a backend server that provides support for the pages displayed on terminal device 101.
[0056] It should be noted that the data storage method provided in this application embodiment is generally executed by a server / terminal device, and correspondingly, the data storage device is generally located in the server / terminal device.
[0057] It should be understood that Figure 1 The number of terminal devices, networks, and servers shown is merely illustrative; the system can have any number of terminal devices, networks, and servers depending on implementation needs.
[0058] Continue to refer to Figure 2 The diagram illustrates a flowchart of an embodiment of the data storage method according to this application. Embodiments of this application can acquire and process relevant data based on artificial intelligence technology. Artificial intelligence (AI) is a theory, method, technology, and application system that uses digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to obtain optimal results.
[0059] Foundational artificial intelligence technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, operating / interactive systems, and mechatronics. AI software technologies mainly include computer vision, robotics, biometrics, speech processing, natural language processing, and machine learning / deep learning. The data storage method includes the following steps:
[0060] S201: Receive data storage instruction and determine the amount of data to be stored and the remaining storage space of the circular array.
[0061] A circular array is a special data structure where the elements are positioned cyclically within the array. When an index reaches the end of the array, the next element moves back to the beginning. In a circular array, the modulo operator (%) is used to map the indices to the correct positions. For example, if you have a circular array of length n, the indices will start from 0, then 1, 2, ..., n-1, and then start from 0 again, and so on.
[0062] Circular arrays are configured with corresponding index arrays, which can be used to indirectly achieve the effect of circular indexing. For example, consider a circular array `arr` of length 5, with elements [a, b, c, d, e]. When configuring the index array, a strategy can be designed to simulate the access pattern of circular indexing. For instance, an index array `indices` can be created, containing a series of configured index values (such as [0, 1, 2, 3, 4]), and then the elements in `arr` can be accessed according to the order in `indices`, thus achieving a specific access pattern.
[0063] Specifically, after receiving a data storage instruction, the system first assesses the amount of data to be stored and the remaining capacity of the current circular array. By comparing the amount of data to be stored with the remaining capacity of the current circular array, the system determines the direction of subsequent operations. For example, if the data to be stored is a batch of log information, the system first calculates the total size of the logs and compares it with the remaining space in the circular array. If there is enough remaining space, the data is stored directly; if not, an array copy operation is triggered to expand the data storage capacity, ensuring effective planning and resource allocation before data storage.
[0064] S202, when the amount of data to be stored is greater than the storage capacity of the circular array, the circular array is copied to generate a temporary circular array.
[0065] Specifically, when the amount of data to be stored exceeds the storage capacity of the circular array, a strategy is adopted to copy the original circular array to generate a temporary array, improving the flexibility and security of data processing. The copying operation ensures that the data in the original array is not corrupted or lost during the expansion process. For example, in a video playback application, if the cached video segments exceed the capacity of the circular buffer, the system will copy the contents of the current buffer to a new temporary buffer to make room for new video segments, thus preserving not only the old data but also preparing for the addition of new data.
[0066] S203, store the data to be stored in the temporary circular array until the temporary circular array is full, and store the unstored data to be stored into the circular array.
[0067] Specifically, the temporary circular array continues to store data until it is full. Once the temporary circular array is full, the remaining data to be stored is stored in the original circular array according to a predetermined strategy (such as overwriting the oldest data or selecting overwrite based on priority), ensuring data integrity and order. For example, in a real-time data acquisition system, when the temporary buffer is full, new data points are added to the beginning of the original buffer, overwriting the oldest data points, thereby maintaining the real-time and up-to-date nature of the data.
[0068] S204: Receive the storage update instruction, point the data pointer to the temporary circular array, and delete the circular array.
[0069] Specifically, once the temporary circular array is fully utilized, the system achieves a seamless switch in storage structure by updating the data pointer and deleting the original circular array. This simplifies subsequent data access logic and reduces system resource consumption. For example, in the data recording of IoT devices, once new data is completely written to the temporary array and confirmed to be correct, the system updates the data pointer to point to the temporary array and deletes the old circular array. This ensures that all subsequent data accesses can directly locate the latest dataset. Deleting the circular array marks the successful completion of the data storage cycle and prepares for the next round of data storage.
[0070] In the above embodiments, this application discloses a data storage method belonging to the field of big data technology. This data storage method is applied to circular arrays in a database storage structure. Unlike traditional storage schemes that simply reject new data or overwrite old data when the amount of data to be stored exceeds the capacity of the current circular array, this application adopts a strategy of copying the original circular array to a temporary array. This preserves the integrity of the original array data, ensures data consistency and security, and efficiently handles the continuous storage needs of large amounts of data, avoiding data loss or processing interruptions due to capacity limitations. After partial data storage is completed in the temporary circular array, the remaining data is added to the original circular array in an orderly manner, achieving seamless data migration and expansion. Furthermore, by updating data pointers and deleting the old circular array, a smooth transition of the storage structure is achieved, reducing the waste of system resources and simplifying the logic of subsequent data access.
[0071] Furthermore, the circular array is configured with a matching index array. When the amount of data to be stored exceeds the storage capacity of the circular array, the circular array is copied to generate a temporary circular array. This also includes:
[0072] Copy the index array of the circular array to obtain a temporary index array, where the temporary index array matches the temporary circular array;
[0073] Clear the data stored in the circular array and update the index array.
[0074] In this embodiment, a synchronous update mechanism for the index array is further introduced. When the amount of data to be stored exceeds the capacity of the circular array, not only is the circular array copied to generate a temporary circular array for continued storage, but the index array is also copied to generate a temporary index array to match the temporary circular array number. Subsequently, the data in the original circular array is cleared, and the index array is updated to reflect the new data storage state, providing an accurate index basis for subsequent data operations.
[0075] This step ensures that the data index and the data itself remain consistent during the expansion process, avoiding the loss of data accessibility due to expansion operations, and effectively maintaining the consistency of the data structure and index, thereby improving the flexibility and reliability of data management.
[0076] Furthermore, the data to be stored is stored in a temporary circular array until the temporary circular array is full, and any unstored data is stored in the circular array. Specifically, this includes:
[0077] The starting position of the data to be stored in the temporary circular array is determined based on the temporary index array, thus obtaining the first data starting position;
[0078] Set the database pointer to a temporary circular array, and start filling the temporary circular array with data to be stored, starting from the first data position, until the temporary circular array is full.
[0079] Determine the remaining amount of data to be stored, point the data pointer to the circular array, and start from the initial storage position of the circular array to fill the remaining amount of data to be stored into the circular array in sequence until the storage of the data to be stored is completed.
[0080] In this embodiment, firstly, the starting position of the data in the temporary circular array is accurately located using a temporary index array, ensuring that the data to be stored is stored in the temporary circular array, thus achieving the orderliness and accuracy of data storage. Subsequently, by using the sequential movement of the data pointer, the data to be stored is continuously filled into the temporary circular array until its capacity is saturated. For the remaining unstored data, the data pointer is switched to the original circular array, and storage continues from its initial position, effectively utilizing the remaining space of the original array.
[0081] For example, consider an initial circular array `arr` with a capacity of 5, currently storing the following data (indexed from 0): `arr = [0, 1, 2, 3, 4]`. There is also an index array `indices` matching `arr`, used to record a specific order or logical position of the data in `arr`: `indices = [0, 1, 2, 3, 4]`. Now, a new batch of data to be stored [5, 6, 7, 8, 9, 10] is received, exceeding the current capacity of `arr`. Following the above approach, first, `arr` and `indices` are copied to a temporary circular array `temp_arr = [0', 1', 2', 3', 4']` and a temporary index array `temp_indices = [0', 1', 2', 3', 4']`. Then, the starting position for storing the new data in `temp_arr` is determined (here, it's assumed to start from index 0, because `temp_arr` is newly created and either empty or can be overwritten). Next, the data pointer is set to the temporary circular array temp_arr, and new data [5,6,7,8,9] is filled in sequentially starting from index 0, i.e., temp_arr = [5,6,7,8,9]. After temp_arr is filled, the remaining amount of data to be stored is determined to be 1 (i.e., the number 10). Finally, the data pointer is set to the circular array arr, and the remaining data to be stored (10) is filled into arr starting from its initial position (index 0), at which point arr = [10,1',2',3',4'].
[0082] This step enables efficient allocation and storage of data exceeding the capacity of the original array between the temporary circular array and the original circular array, which not only optimizes data storage efficiency but also ensures data integrity and continuity.
[0083] Furthermore, after setting the database's data pointer to a temporary circular array, and sequentially filling the temporary circular array with data to be stored, starting from the first data position, until the temporary circular array is full, the process also includes:
[0084] Determine if the remaining amount of data to be stored is greater than the data storage capacity of the circular array;
[0085] When the remaining amount of data to be stored is greater than the data storage capacity of the circular array, the cleared circular array is copied to generate a new circular array.
[0086] In this embodiment, when processing data storage that exceeds the capacity of the current circular array, after the temporary circular array is full, the system first assesses whether the amount of remaining data to be stored still exceeds the capacity of the original circular array. If it does exceed the capacity of the original circular array, further expansion measures are taken, namely, copying the cleared original circular array to generate one or more new circular arrays, until the new circular array and the original circular array can accommodate the amount of remaining data to be stored, so as to provide more storage space.
[0087] It should be noted that if the amount of data to be stored exceeds the capacity of the original circular array, the cleared original circular array needs to be copied to generate one or more new circular arrays. At this time, the database simultaneously contains the original circular array, the temporary circular array, and the new circular array. When storing data, the priority order of the above circular arrays is: temporary circular array, new circular array, and original circular array.
[0088] This step ensures that the system can respond flexibly even when large amounts of data arrive continuously. By constantly generating new circular arrays to store data, it avoids storage failures caused by data overflow, effectively improving the flexibility and scalability of data storage. It is particularly suitable for scenarios that require continuous, large-scale data processing.
[0089] Furthermore, before receiving the storage update instruction, pointing the data pointer to the temporary circular array, and deleting the circular array, the following steps are also included:
[0090] Receive a data read instruction and determine the storage location of the data to be read in the database. The data read instruction carries a data read location identifier.
[0091] When the data to be read is stored in a circular array or a temporary circular array, the data to be read is extracted and copied from the circular array or the temporary circular array based on the data reading position identifier, the first data reading result is generated, and the first data reading result is output.
[0092] When the data to be read is stored in both a circular array and a temporary circular array, the position of the data reading position marker in the temporary circular array is determined, and the first data segment to be read is obtained from the temporary circular array. The position of the data reading position marker in the circular array is determined, and the second data segment to be read is obtained from the circular array. The second data reading result is generated based on the first and second data segments to be read, and the second data reading result is output.
[0093] In this embodiment, the system receives data read commands and parses the location identifiers they carry, enabling it to accurately locate the storage position of the data to be read in a circular array or a temporary circular array. For data storage in a single array, the required data is directly extracted and copied from that array, achieving fast read and output. However, when data is distributed across two arrays due to an expansion strategy, the system intelligently determines the location identifiers, retrieves data in segments from both the temporary circular array and the circular array, and then merges them to generate a complete data read result.
[0094] This step not only ensures the accuracy and integrity of data retrieval, but also improves the flexibility and efficiency of data processing. Especially when dealing with large-scale, dynamically changing datasets, it can significantly reduce data access latency and errors, and improve user experience and system stability.
[0095] Furthermore, the data read position identifier includes a data read start bit and a data read end bit. The position of the data read position identifier in the temporary circular array is determined, and a first data segment to be read is obtained from the temporary circular array. The position of the data read position identifier in the circular array is determined, and a second data segment to be read is obtained from the circular array. A second data read result is generated based on the first and second data segments to be read, and the second data read result is output. Specifically, this includes:
[0096] When the start position of the data to be read is located in the temporary circular array and the end position of the data to be read is located in the circular array, the first data segment to be read is determined based on the temporary index array and the start position of the data to be read, and the second data segment to be read is determined based on the index array and the end position of the data to be read.
[0097] When the start position of the data to be read is located in the circular array and the end position of the data to be read is located in the temporary circular array, the first data segment to be read is determined based on the index array and the start position of the data to be read, and the second data segment to be read is determined based on the temporary index array and the end position of the data to be read.
[0098] Combine the first data segment to be read and the second data segment to be read to generate the second data reading result, and output the second data reading result.
[0099] In this embodiment, when a data read operation spans both a temporary circular array and the original circular array, the system intelligently determines the start and end positions of the read data. It then flexibly utilizes both the temporary and original index arrays to identify the data segments to be read from each array, combines these two data segments into a complete read result, and outputs it to the user. The start and end positions of the read operation determine which index array is used to locate the data; the temporary index array is used for the temporary circular array, while the original index array is used for the original circular array, ensuring accurate data location.
[0100] The system uses a temporary index array and a starting bit to determine the first data segment to be read. It then searches for the data position in the temporary index array corresponding to the starting bit and extracts data from that position until it reaches the boundary between the temporary and original circular arrays or the internal logic breakpoint of the read operation. Similarly, if the starting bit is located in the original circular array, the system uses the index array and the starting bit to determine the first data segment to be read.
[0101] When the terminating bit is located in the original circular array, the index array and the data read termination bit are used to determine the second data segment to be read. The system is able to accurately locate the terminating bit from the original circular array and extract the data from the start boundary to the terminating bit. Similarly, if the terminating bit is located in a temporary index array, the temporary index array and the data read termination bit are used to determine the second data segment to be read.
[0102] Suppose we have an original circular array `arr` and a temporary circular array `temp_arr`, as well as their respective index arrays `index` and `temp_index`, as shown in the example below:
[0103] The circular array arr = [f, g, h, 3, 4], and the index array indexes = [0, 1, 2, 3, 4];
[0104] Temporary circular array temp_arr = [a,b,c,d,e], temporary index array temp_indexes = [0',1',2',3',4'];
[0105] Now, there is a data read instruction that requires reading from position 2' to the end of position 2. Position 2' is in `temp_arr`, and position 2 is in `arr`. Find the physical position corresponding to position 2' in `temp_indices`, and extract data from that position in `temp_arr` until the end of `temp_arr`, obtaining the first data segment to be read [c,d,e]. Since reading from position 2' to position 2 requires crossing an array, reading must continue in `arr`. Find the physical position corresponding to position 2 in `indices`, and extract data from the first data storage bit of `arr` (i.e., `indices` position 0) until the physical position corresponding to `indices` position 2 in `arr`, obtaining the second data segment to be read [f,g,h]. Finally, merge the first data segment [c,d,e] and the second data segment [f,g,h] to generate the second data read result [c,d,e,f,g,h].
[0106] This step ensures that the required data segments can be accurately located and extracted regardless of the data distribution. This not only improves the flexibility of data processing but also guarantees data consistency and integrity, avoiding read errors or omissions caused by scattered data storage. In applications requiring frequent cross-array data access, this solution can significantly improve data processing efficiency and user experience.
[0107] Furthermore, after receiving the data storage instruction and determining the amount of data to be stored and the remaining storage space of the circular array, the process also includes:
[0108] When the amount of data to be stored is less than or equal to the storage capacity of the circular array, the starting position of the data to be stored in the circular array is determined based on the index array to obtain the second starting position of the data;
[0109] Point the data pointer to the circular array, and starting from the second data position, fill the circular array with the data to be stored one by one until the data to be stored is stored.
[0110] In this embodiment, firstly, by accurately calculating the relationship between the amount of data to be stored and the remaining space in the circular array, data overflow or space waste is avoided. When the amount of data is suitable for or less than the remaining space, the index array is directly used to locate the starting point for data insertion, i.e., the second data start position, ensuring that the data is stored in an ordered and continuous manner in the circular array. Subsequently, by directly manipulating the data pointer, data is sequentially filled from the specified position until all the data to be stored is safely and efficiently stored in the circular array, effectively improving the efficiency and accuracy of data processing.
[0111] In this embodiment, the data storage method operates on an electronic device (e.g., Figure 1 The server shown can receive instructions or acquire data via wired or wireless connection. It should be noted that the aforementioned wireless connection methods may include, but are not limited to, 3G / 4G connections, WiFi connections, Bluetooth connections, WiMAX connections, Zigbee connections, UWB (ultra-wideband) connections, and other currently known or future wireless connection methods.
[0112] It should be emphasized that, to further ensure the privacy and security of the data to be stored, the data can also be stored in a node of a blockchain.
[0113] The blockchain referred to in this application is a novel application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanisms, and encryption algorithms. Essentially, a blockchain is a decentralized database, a chain of data blocks linked together using cryptographic methods. Each data block contains information about a batch of network transactions, used to verify the validity of the information (anti-counterfeiting) and generate the next block. A blockchain can include an underlying blockchain platform, a platform product service layer, and an application service layer.
[0114] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by instructing related hardware through computer-readable instructions. These computer-readable instructions can be stored in a computer-readable storage medium. When executed, the computer-readable instructions can include the processes of the embodiments of the above methods. The aforementioned storage medium can be a non-volatile storage medium such as a magnetic disk, optical disk, or read-only memory (ROM), or random access memory (RAM).
[0115] It should be understood that although the steps in the flowcharts of the accompanying figures are shown sequentially as indicated by the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the accompanying figures may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the sub-steps or stages of other steps.
[0116] Further reference Figure 3 As a response to the above Figure 2 To implement the method shown, this application provides an embodiment of a data storage device, which is similar to... Figure 2 Corresponding to the method embodiments shown, this device can be specifically applied to various electronic devices.
[0117] like Figure 3 As shown, the data storage device 300 described in this embodiment executes the data storage method as described in the above embodiment. The data storage method is applied to a circular array in a database storage structure. The data storage device 300 includes:
[0118] The storage instruction receiving module 301 is used to receive data storage instructions and determine the amount of data to be stored and the storage capacity of the circular array;
[0119] The first array copying module 302 is used to copy the circular array to generate a temporary circular array when the amount of data to be stored is greater than the storage capacity of the circular array.
[0120] The first data storage module 303 is used to store the data to be stored in the temporary circular array until the temporary circular array is filled, and to store the unstored data to be stored into the circular array.
[0121] The storage update instruction module 304 is used to receive storage update instructions, point the data pointer to the temporary circular array, and delete the circular array.
[0122] Furthermore, the data storage device 300 also includes:
[0123] The index array copying module is used to copy the index array of a circular array to obtain a temporary index array, wherein the temporary index array matches the temporary circular array;
[0124] The circular array clearing module is used to clear the data stored in the circular array and update the index array.
[0125] Furthermore, the first data storage module 303 specifically includes:
[0126] The first data position determination unit is used to determine the starting position of the data to be stored in the temporary circular array based on the temporary index array, and obtain the first data start position;
[0127] The first data storage unit is used to point the database data pointer to the temporary circular array, and starting from the first data position, fill the temporary circular array with the data to be stored in turn until the temporary circular array is full.
[0128] The second data storage unit is used to determine the remaining amount of data to be stored, point the data pointer to the circular array, and fill the remaining amount of data to be stored into the circular array sequentially from the initial storage position of the circular array until the storage of the data to be stored is completed.
[0129] Furthermore, the data storage device 300 also includes:
[0130] The storage capacity judgment module is used to determine whether the remaining amount of data to be stored is greater than the data storage capacity of the circular array;
[0131] The second array copying module is used to copy the cleared circular array and generate a new circular array when the remaining amount of data to be stored is greater than the data storage capacity of the circular array.
[0132] Furthermore, the data storage device 300 also includes:
[0133] The read location determination module is used to receive data read instructions and determine the storage location of the data to be read in the database. The data read instructions carry a data read location identifier.
[0134] The first data reading module is used to extract and copy the data to be read from the circular array or temporary circular array based on the data reading position identifier when the data to be read is stored in the circular array or temporary circular array, generate the first data reading result, and output the first data reading result.
[0135] The second data reading module is used to determine the position of the data reading position marker in the temporary circular array when the data to be read is stored in both the circular array and the temporary circular array, and to obtain the first data segment to be read from the temporary circular array, determine the position of the data reading position marker in the circular array, and to obtain the second data segment to be read from the circular array, generate the second data reading result based on the first and second data segments to be read, and output the second data reading result.
[0136] Furthermore, the data reading position identifier includes a data read start bit and a data read end bit. The second data reading module specifically includes:
[0137] A unit is used to determine a first data segment to be read based on a temporary index array and a data start position, and to determine a second data segment to be read based on an index array and a data end position, when the data start position is located in a temporary circular array and the data end position is located in a circular array.
[0138] A unit is used to determine the first data segment to be read based on the index array and the start position of the data to be read, and to determine the second data segment to be read based on the temporary index array and the end position of the data to be read when the start position of the data to be read is located in the circular array and the end position of the data to be read is located in the temporary circular array.
[0139] The data reading combination unit is used to combine the first data segment to be read and the second data segment to be read to generate a second data reading result, and output the second data reading result.
[0140] Furthermore, the data storage device 300 also includes:
[0141] The second data position determination unit is used to determine the starting position of the data to be stored in the circular array based on the index array when the amount of data to be stored is less than or equal to the storage capacity of the circular array, and obtain the second data start position.
[0142] The second data storage module is used to point the data pointer to the circular array, and starting from the second data position, fill the circular array with the data to be stored in sequence until the storage of the data to be stored is completed.
[0143] In the above embodiments, this application discloses a data storage device, belonging to the field of big data technology. The data storage method is applied to a circular array in a database storage structure. Compared with traditional storage schemes that simply reject new data or overwrite old data when the amount of data to be stored exceeds the capacity of the current circular array, this application adopts a strategy of copying the original circular array to a temporary array. This preserves the integrity of the original array data, ensures data consistency and security, and can efficiently handle the continuous storage needs of large amounts of data, avoiding data loss or processing interruption due to capacity limitations. After partial data storage is completed in the temporary circular array, the remaining data is added to the original circular array in an orderly manner, realizing seamless data migration and expansion. In addition, by updating data pointers and deleting the old circular array, a smooth transition of the storage structure is achieved, reducing the waste of system resources and simplifying the logic of subsequent data access.
[0144] To address the aforementioned technical problems, embodiments of this application also provide a computer device. Please refer to [link / reference needed]. Figure 4 , Figure 4 This is a basic structural block diagram of the computer device in this embodiment.
[0145] The computer device 4 includes a memory 41, a processor 42, and a network interface 43 that are interconnected via a system bus. It should be noted that only the computer device 4 with components 41-43 is shown in the figure; however, it should be understood that it is not required to implement all the shown components, and more or fewer components can be implemented alternatively. Those skilled in the art will understand that the computer device described here is a device capable of automatically performing numerical calculations and / or information processing according to pre-set or stored instructions. Its hardware includes, but is not limited to, microprocessors, application-specific integrated circuits (ASICs), programmable gate arrays (FPGAs), digital signal processors (DSPs), embedded devices, etc.
[0146] The computer device can be a desktop computer, laptop, handheld computer, or cloud server, etc. The computer device can interact with the user via a keyboard, mouse, remote control, touchpad, or voice control.
[0147] The memory 41 includes at least one type of readable storage medium, including flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 41 may be an internal storage unit of the computer device 4, such as the hard disk or memory of the computer device 4. In other embodiments, the memory 41 may also be an external storage device of the computer device 4, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the computer device 4. Of course, the memory 41 may also include both the internal storage unit and its external storage device of the computer device 4. In this embodiment, the memory 41 is typically used to store the operating system and various application software installed on the computer device 4, such as computer-readable instructions for data storage methods. In addition, the memory 41 can also be used to temporarily store various types of data that have been output or will be output.
[0148] In some embodiments, the processor 42 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chip. The processor 42 is typically used to control the overall operation of the computer device 4. In this embodiment, the processor 42 is used to execute computer-readable instructions stored in the memory 41 or to process data, for example, to execute computer-readable instructions for the data storage method.
[0149] The network interface 43 may include a wireless network interface or a wired network interface, which is typically used to establish communication connections between the computer device 4 and other electronic devices.
[0150] In the above embodiments, this application discloses a computer device belonging to the field of big data technology. The data storage method is applied to a circular array in a database storage structure. Compared with traditional storage schemes that simply reject new data or overwrite old data when the amount of data to be stored exceeds the capacity of the current circular array, this application adopts a strategy of copying the original circular array to a temporary array. This preserves the integrity of the original array data, ensures data consistency and security, and can efficiently handle the continuous storage needs of large amounts of data, avoiding data loss or processing interruption due to capacity limitations. After partial data storage is completed in the temporary circular array, the remaining data is added to the original circular array in an orderly manner, realizing seamless data migration and expansion. In addition, by updating data pointers and deleting the old circular array, a smooth transition of the storage structure is achieved, reducing the waste of system resources and simplifying the logic of subsequent data access.
[0151] This application also provides another embodiment, namely, providing a computer-readable storage medium storing computer-readable instructions that can be executed by at least one processor to cause the at least one processor to perform the steps of the data storage method described above.
[0152] In the above embodiments, this application discloses a computer-readable storage medium belonging to the field of big data technology. The data storage method is applied to a circular array in a database storage structure. Compared with traditional storage schemes that simply reject new data or overwrite old data when the amount of data to be stored exceeds the capacity of the current circular array, this application adopts a strategy of copying the original circular array to a temporary array. This preserves the integrity of the original array data, ensures data consistency and security, and can efficiently handle the continuous storage needs of large amounts of data, avoiding data loss or processing interruption due to capacity limitations. After partial data storage is completed in the temporary circular array, the remaining data is added to the original circular array in an orderly manner, realizing seamless data migration and expansion. In addition, by updating data pointers and deleting the old circular array, a smooth transition of the storage structure is achieved, reducing the waste of system resources and simplifying the logic of subsequent data access.
[0153] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0154] This application can be used in a wide variety of general-purpose or special-purpose computer system environments or configurations. Examples include: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics devices, network PCs, minicomputers, mainframe computers, and distributed computing environments including any of the above systems or devices. This application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform specific tasks or implement specific abstract data types. This application can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0155] Obviously, the embodiments described above are only some embodiments of this application, not all embodiments. The accompanying drawings show preferred embodiments of this application, but do not limit the patent scope of this application. This application can be implemented in many different forms; rather, the purpose of providing these embodiments is to provide a more thorough and comprehensive understanding of the disclosure of this application. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing specific embodiments, or make equivalent substitutions for some of the technical features. Any equivalent structures made using the content of this application's specification and drawings, directly or indirectly applied to other related technical fields, are similarly within the scope of patent protection of this application.
Claims
1. A data storage method, characterized in that, The data storage method is applied to circular arrays in a database storage structure, including: Receive data storage instructions and determine the amount of data to be stored and the remaining storage space of the circular array; When the amount of data to be stored is greater than the storage capacity of the circular array, the circular array is copied to generate a temporary circular array; The data to be stored is stored in the temporary circular array until the temporary circular array is full, and the unstored data to be stored is stored in the circular array. Receive a storage update instruction, point the data pointer to the temporary circular array, and delete the circular array; The circular array is configured with a matching index array. When the amount of data to be stored exceeds the storage capacity of the circular array, the circular array is copied to generate a temporary circular array. The method further includes: Copy the index array of the circular array to obtain a temporary index array, wherein the temporary index array matches the temporary circular array; Clear the data stored in the circular array and update the index array; Before receiving the storage update instruction, pointing the data pointer to the temporary circular array, and deleting the circular array, the process also includes: Receive a data read instruction and determine the storage location of the data to be read in the database, wherein the data read instruction carries a data read location identifier; When the data to be read is stored in the circular array or the temporary circular array, the data to be read is extracted and copied from the circular array or the temporary circular array based on the data reading position identifier, a first data reading result is generated, and the first data reading result is output. When the data to be read is stored in both the circular array and the temporary circular array, the position of the data reading position identifier in the temporary circular array is determined, and a first data segment to be read is obtained from the temporary circular array. The position of the data reading position identifier in the circular array is determined, and a second data segment to be read is obtained from the circular array. A second data reading result is generated based on the first data segment to be read and the second data segment to be read, and the second data reading result is output.
2. The data storage method as described in claim 1, characterized in that, The data to be stored is stored in the temporary circular array until the temporary circular array is full, and any unstored data is then stored in the circular array. Specifically, this includes: Based on the temporary index array, the starting position of the data to be stored in the temporary circular array is determined to obtain the first data starting position; Point the data pointer to the temporary circular array, and starting from the first data position, fill the temporary circular array with the data to be stored in sequence until the temporary circular array is full; Determine the remaining amount of the data to be stored, point the data pointer to the circular array, and start from the initial storage position of the circular array to fill the remaining amount of the data to be stored into the circular array sequentially until the storage of the data to be stored is completed.
3. The data storage method as described in claim 2, characterized in that, After setting the data pointer to the temporary circular array and sequentially filling the temporary circular array with the data to be stored, starting from the first data position, until the temporary circular array is full, the method further includes: Determine whether the remaining amount of the data to be stored is greater than the data storage capacity of the circular array; When the remaining amount of data to be stored is greater than the data storage capacity of the circular array, the cleared circular array is copied to generate a new circular array.
4. The data storage method as described in claim 1, characterized in that, The data read position identifier includes a data read start bit and a data read end bit. The position of the data read position identifier in the temporary circular array is determined, and a first data segment to be read is obtained from the temporary circular array. The position of the data read position identifier in the circular array is determined, and a second data segment to be read is obtained from the circular array. A second data read result is generated based on the first and second data segments to be read, and the second data read result is output. Specifically, this includes: When the start bit of the read data is located in the temporary circular array and the end bit of the read data is located in the circular array, the first data segment to be read is determined based on the temporary index array and the start bit of the read data, and the second data segment to be read is determined based on the index array and the end bit of the read data. When the start position of the read data is located in the circular array and the end position of the read data is located in the temporary circular array, the first data segment to be read is determined based on the index array and the start position of the read data, and the second data segment to be read is determined based on the temporary index array and the end position of the read data. The first data segment to be read and the second data segment to be read are combined to generate the second data reading result, and the second data reading result is output.
5. The data storage method as described in claim 1, characterized in that, After receiving the data storage instruction and determining the amount of data to be stored and the remaining storage space of the circular array, the process also includes: When the amount of data to be stored is less than or equal to the storage capacity of the circular array, the starting position of the data to be stored in the circular array is determined based on the index array to obtain the second data starting position; The data pointer is pointed to the circular array, and starting from the second data position, the data to be stored is sequentially filled into the circular array until the storage of the data to be stored is completed.
6. A data storage device, characterized in that, The data storage device performs the data storage method as described in any one of claims 1 to 5, the data storage method being applied to a circular array in a database storage structure, and the data storage device comprising: The storage instruction receiving module is used to receive data storage instructions and determine the amount of data to be stored and the storage capacity of the circular array; The first array copying module is used to copy the circular array to generate a temporary circular array when the amount of data to be stored is greater than the storage capacity of the circular array. The data storage module is used to store the data to be stored in the temporary circular array until the temporary circular array is full, and to store the unstored data to be stored into the circular array. The storage update instruction module is used to receive a storage update instruction, point the data pointer to the temporary circular array, and delete the circular array.
7. A computer device, characterized in that, The device includes a memory and a processor, wherein the memory stores computer-readable instructions, and the processor executes the computer-readable instructions to implement the steps of the data storage method as described in any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-readable instructions, which, when executed by a processor, implement the steps of the data storage method as described in any one of claims 1 to 5.