Data storage method and device

By using the stored sequence number as a ring arithmetic sequence, the adjacent sequence number difference value is calculated to determine the write point, the problem of inefficient writing in the prior art is solved, and the method of quickly determining the newly written data sequence number is realized, which is suitable for 8 bit, 16-bit processor.

CN115617276BActive Publication Date: 2024-12-20BEIJING TAIYUE TIANCHENG TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202211386897.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-11-07
Publication Date
2024-12-20
Estimated Expiration
2042-11-07

AI Technical Summary

Technical Problem

In the prior art, when the processor stores data in a storage device, it is determined that the write point of newly written data needs to read a large amount of data, resulting in excessive resource usage and low write efficiency.

Method used

By using the stored sequence number as a ring arithmetic sequence, the adjacent sequence number difference value is calculated to determine whether there is a breakpoint. If there is no breakpoint, the sequence number is written as the starting value. If there is a breakpoint, the write sequence number is determined based on the number of breakpoints. Avoid reading all data.

Benefits of technology

It improves the speed of determining the serial number of newly written entry data, shortens processing time, and improves the efficiency of writing data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115617276B_ABST
    Figure CN115617276B_ABST
Patent Text Reader

Abstract

The embodiment of the present application provides a data storage method and device, the method comprising reading the storage sequence numbers of all entry data in a storage device; taking the storage sequence numbers of all entry data as a circular sequence, and calculating the difference between any two adjacent storage sequence numbers in the circular sequence; determining whether there is a breakpoint in the circular sequence according to the difference between any two adjacent storage sequence numbers in the circular sequence; if there is no breakpoint, determining the sequence number of the next entry data written to the storage device as the starting value of the circular arithmetic sequence; if there is a breakpoint, determining the sequence number of the next entry data written to the storage device according to the number of breakpoints. The embodiment of the present application can determine the sequence number of the next entry data written to the storage device based on the relationship between the storage sequence number of the entry data in the storage device and the circular arithmetic sequence, without the need to obtain all the data stored in the storage device, and can increase the speed of determining the sequence number of the newly written entry data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a data storage method and device. Background Art

[0002] When the processor uses a storage device (such as a non-volatile memory) to store data, a large amount of data can be written into the storage device by entries to form entry data, and each entry data has a corresponding sequence number. When the storage device is full, the next data to be written will overwrite the first written data.

[0003] When the processor stores entry data in the storage device, it is necessary to determine the write point of the entry data newly written into the storage device. Methods for determining the write point include: reading all entry data stored in the storage device, sorting all entry data according to the write time point of the entry data, and determining the write point of the entry data newly written into the storage device based on the sorting result.

[0004] However, this method of determining the writing point requires reading a large amount of data from the memory, and this process occupies too many resources, making the data writing time too long and the data writing efficiency low. Summary of the invention

[0005] The embodiments of the present application provide a data storage method and device to solve the problem of low efficiency in writing data.

[0006] In a first aspect, an embodiment of the present application provides a data storage method, comprising: being applied to a storage device, the storage device being used to store at most N entry data, and assigning a storage sequence number to each entry data when each entry data is written to the storage device; wherein the storage sequence number of the i-th entry data differs from the storage sequence number of the i-1-th data entry by a first preset value, and i is less than or equal to N; when the number of data entries written to the memory is N, the N storage sequence numbers corresponding to the N entry data form a circular arithmetic sequence; the method comprises: reading the storage sequence numbers of all entry data in the storage device; taking the storage sequence numbers of all entry data as a circular sequence, and calculating the difference between any two adjacent storage sequence numbers in the circular sequence; determining whether there is a breakpoint in the circular sequence according to the difference between any two adjacent storage sequence numbers in the circular sequence, the breakpoint being a position where the difference between two adjacent storage sequence numbers in the circular sequence is not the first preset value; if there is no breakpoint, determining the sequence number of the next entry data written to the storage device as the starting value of the circular arithmetic sequence; if there is a breakpoint, determining the sequence number of the next entry data written to the storage device according to the number of breakpoints.

[0007] In one achievable manner, the steps of taking the storage sequence numbers of all entry data as a circular sequence and calculating the difference between any two adjacent storage sequence numbers in the circular sequence include: determining the number of storage sequence numbers in the circular sequence; if the number of storage sequence numbers in the circular sequence is greater than 1, looping through the following steps: S1, determining whether the difference between the jth storage sequence number and the j+1th storage sequence number in the circular sequence is equal to a first preset value; if it is equal to the first preset value, executing step S2; if it is not equal to the first preset value, determining that there is a breakpoint between the jth storage sequence number and the j+1th storage sequence number, and executing step S2; wherein the starting value of j is 1; S2, determining whether the j+1th storage sequence number is the last storage sequence number in the circular sequence; if the j+1th storage sequence number is the last storage sequence number in the circular sequence, ending the loop; if the j+1th storage sequence number is not the last storage sequence number in the circular sequence, adding 1 to the value of j and jumping to step S1.

[0008] In an achievable manner, the method further includes: if the number of storage sequence numbers in the circular sequence is equal to 0, determining the sequence number of the next entry data to be written into the storage device as the starting value of the circular arithmetic sequence.

[0009] In one achievable manner, it further includes: if the number of storage sequence numbers in the circular sequence is equal to 1, determining the sequence number of the next entry data written to the storage device to be a first numerical value, the sum of the value of the storage sequence number in the first numerical circular sequence and a first preset value.

[0010] In one implementable method, if breakpoints exist, the sequence number of the next entry data written to the storage device is determined based on the number of breakpoints, including: if the number of breakpoints is equal to 1, the sequence number of the next entry data written to the storage device is determined to be a second value, and the second value is the sum of the previous storage sequence number of the breakpoint position and the first preset value.

[0011] In one achievable manner, if breakpoints exist, the sequence number of the next entry data written to the storage device is determined according to the number of breakpoints, including: if the number of breakpoints is greater than 1, the sequence number of the next entry data written to the storage device is determined to be the starting value of the circular arithmetic progression.

[0012] In one achievable manner, the j+1th storage sequence number in the ring sequence satisfies the following formula:

[0013] A j+1 =(A j +d)%m;

[0014] Among them, A j+1 Indicates the j+1th storage number in the circular sequence; A jrepresents the jth storage number in the circular sequence; represents the difference; % is the modulo operator; m represents the total number of storage numbers in the circular arithmetic sequence.

[0015] In one achievable manner, the n+1th storage sequence number in the annular arithmetic progression satisfies the following formula:

[0016] A n+1 =(A n +d′)%N;

[0017] In the formula, A n+1 A represents the n+1th storage sequence number in the annular arithmetic progression; n represents the nth storage sequence number in the annular arithmetic progression; represents the first preset value; % is the modulo operator; N represents the total number of storage sequences in the annular arithmetic progression.

[0018] In a second aspect, an embodiment of the present application provides a data storage device, the device comprising:

[0019] a reading module, used to read the storage sequence numbers of all the entry data in the storage device; a difference calculation module, used to take the storage sequence numbers of all the entry data as a circular sequence, and calculate the difference between any two adjacent storage sequence numbers in the circular sequence; a breakpoint determination module, used to determine whether there is a breakpoint in the circular sequence according to the difference between any two adjacent storage sequence numbers in the circular sequence, the breakpoint being a position where the difference between two adjacent storage sequence numbers in the circular sequence is not a first preset value;

[0020] The first serial number determination module is used to determine the serial number of the next entry data written to the storage device as the starting value of the circular arithmetic progression if there is no breakpoint; the second serial number determination module is used to determine the serial number of the next entry data written to the storage device according to the number of breakpoints if there is a breakpoint.

[0021] It can be seen from the above technical solutions that the embodiment of the present application provides a data storage method and device, which is applied to a storage device, and the method includes: reading the storage sequence numbers of all entry data in the storage device; taking the storage sequence numbers of all entry data as a ring sequence, and calculating the difference between any two adjacent storage sequence numbers in the ring sequence; determining whether there is a breakpoint in the ring sequence according to the difference between any two adjacent storage sequence numbers in the ring sequence, and the breakpoint is the position where the difference between two adjacent storage sequence numbers in the ring sequence is not a first preset value; if there is no breakpoint, determining the sequence number of the next entry data written to the storage device as the starting value of the ring arithmetic sequence; if there is a breakpoint, determining the sequence number of the next entry data written to the storage device according to the number of breakpoints. The embodiment of the present application can determine the sequence number of the next entry data written to the storage device based on the relationship between the storage sequence number of the entry data in the storage device and the ring arithmetic sequence, without obtaining all the data stored in the storage device, and can improve the speed of determining the sequence number of the newly written entry data. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] Figure 1 A schematic diagram of a circular arithmetic progression provided in an embodiment of the present application;

[0023] Figure 2 A schematic diagram of a data storage method flow chart provided in an embodiment of the present application;

[0024] FIG3( a ) is a schematic diagram of a breakpoint at the end of a circular sequence provided by an embodiment of the present application;

[0025] FIG3( b ) is a schematic diagram of an embodiment of the present application in which endpoints are at the end and the middle of a circular sequence;

[0026] Figure 4 A schematic diagram of a flow chart for calculating the difference between any two adjacent storage sequence numbers provided in an embodiment of the present application;

[0027] Figure 5 A schematic diagram of a process for determining the sequence number of the next entry data to be written according to the number of sequence numbers stored in a circular sequence provided in an embodiment of the present application;

[0028] Figure 6 A schematic diagram of a flow chart for determining the sequence number of the next entry data to be written according to the number of breakpoints provided in an embodiment of the present application;

[0029] Figure 7 A schematic diagram of the structure of a data storage device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0030] In order to enable those skilled in the art to better understand the technical solutions in the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only 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 the field without creative work should fall within the scope of protection of the present application.

[0031] When the processor uses a storage device (such as a non-volatile memory) to store data, a large amount of data can be written into the storage device by entries to form entry data, and each entry data has a corresponding sequence number. When the storage device is full, the next data to be written will overwrite the first written data.

[0032] When the processor stores entry data in the storage device, it is necessary to determine the write point of the entry data newly written into the storage device. Methods for determining the write point include: reading all entry data stored in the storage device, sorting all entry data according to the write time point of the entry data, and determining the write point of the entry data newly written into the storage device based on the sorting result.

[0033] However, this method of determining the writing point requires reading a large amount of data from the memory, and this process occupies too many resources, making the data writing time too long and the data writing efficiency low.

[0034] For example, data storage is often needed in the process of embedded software development. The massive measurement data and log record data generated during the development process can be stored in the memory by entry. However, embedded processors are generally 8-bit or 16-bit processors, and the main frequency of such processors is not high, so the processing speed is slow. In addition, the memory used in embedded software development generally has a low read and write speed, which causes the processor to take a long time to determine the serial number of the entry data newly written to the storage device.

[0035] The embodiment of the present application provides a data storage method, which uses a ring arithmetic progression to describe the sequence number rule of the data entry stored in the memory, and uses the ring arithmetic progression to calculate the sequence number of the new data entry stored in the memory. In this way, the calculation step replaces the traditional steps of reading the content of all stored data and determining the order of data storage, which can improve the speed of determining the sequence number of the newly written data entry, shorten the processing time, and be more efficient.

[0036] Figure 1 Schematic diagram of a circular arithmetic progression provided in an embodiment of the present application. Figure 1As shown, a circular arithmetic sequence is a sequence consisting of a finite number of items, which is used to describe the arrangement relationship of a finite number of items. In a circular arithmetic sequence, the items of the sequence increase from the minimum value to the maximum value, and then change from the maximum value to the minimum value to form a circular arrangement relationship, and the difference between adjacent data is a fixed tolerance d. The general term formula of a circular arithmetic sequence is as follows:

[0037] A n+1 =(A n +d)%m;

[0038] Among them, A n represents the nth term of a circular arithmetic sequence, A n+1 It represents the n+1th term of the annular arithmetic sequence, d is the common difference, % is the modulo operator, m is the total number of terms in the annular arithmetic sequence, 0≤n<m.

[0039] From the above formula, when the value of any term, the common difference d and the total number of terms in the annular arithmetic sequence are known, the value of the next term in the annular arithmetic sequence can be calculated. Figure 1 The annular arithmetic sequence shown has a common difference of 1 and a total number of 12 terms. Each term of the annular arithmetic sequence is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, and these terms are arranged to form a ring. 12 When it is 11, the value of the first term A1 can be calculated using the general formula of the circular arithmetic progression. Specifically, 11=(A1+1)%12, and A1=0 can be obtained by calculation.

[0040] The data storage method provided in the embodiment of the present application can be applied to a storage device, which can be a read-only memory (ROM), a random access memory (RAM) or a flash memory (Flash EEPROM), etc. The storage device can be used to store up to N entry data, and when each entry data is written to the storage device, a sequence number is assigned to each entry data. Specifically, before the entry data is written to the storage device, the maximum number of entry data that can be stored can be set for the storage device, and the specific value of the number can be determined by the capacity of the storage device, the addressing range of the storage device, etc. When the number of entry data written into the storage device is N, it means that the storage device is full. At this time, the entry data written in the N+1th can overwrite the first entry data written first, thereby realizing the function of automatic overwriting of data circular storage.

[0041] For ease of description, two entry data that are adjacent in writing order are referred to as the i-th entry data and the i+1-th entry data, wherein the i-th entry data is the data that is written first in the two entry data that are adjacent in writing order, and the i+1-th entry data is the data that is written later in the two entry data that are adjacent in writing order. The storage sequence number of the i-th entry data differs from the storage sequence number of the i+1-th entry data by a first preset value, and i is less than or equal to N. When the number of entry data written into the memory is N, the N storage sequence numbers corresponding to the N entry data form a circular arithmetic progression. In other words, the N storage sequence numbers can be arranged to form a ring to obtain a circular arithmetic progression, the starting value of the circular arithmetic progression can be 0, the ending value can be N-1, the total number of items is N, and the tolerance is the above-mentioned first preset value. In this way, the circular arithmetic progression can describe the process of storing entry data in the memory in a cycle according to the sequence number.

[0042] In the embodiment of the present application, since the serial number of the entry data generally increases from the starting value when the storage device writes the entry data, the first preset value is a value greater than 0. Preferably, the value of the first preset value can be 1.

[0043] According to the general formula of the annular arithmetic sequence, the n+1th storage number in the annular arithmetic sequence satisfies the following formula:

[0044] A n+1 =(A n +d′)%N;

[0045] In the formula, A n+1 Represents the n+1th storage number in the annular arithmetic sequence; A n represents the nth storage number in the annular arithmetic progression; d' represents the first preset value; % is the modulo operator; and N represents the total number of storage numbers in the annular arithmetic progression.

[0046] It can be understood that after the maximum number of entry data that the storage device can store is determined, the annular arithmetic sequence formed by the storage sequence numbers of the entry data is also formed, and the starting value, ending value, total number of items and tolerance of the annular arithmetic sequence are also determined.

[0047] Figure 2 A schematic diagram of a data storage method flow chart provided in an embodiment of the present application. Figure 2 As shown, the method may include the following steps:

[0048] S101: Read the storage sequence numbers of all entry data in the storage device.

[0049] In order to determine the storage sequence number of the next entry data to be written into the storage device, it is necessary to first determine the storage sequence number of the entry data that has been written into the current storage device.

[0050] The number of storage sequence numbers read may be x. If the storage device currently does not store data, the number of storage sequence numbers read is x = 0. If the storage device currently stores entry data, the range of the number of storage data read is x is 0 < x ≤ N, where N is the maximum number of entry data that can be stored in the storage device.

[0051] It should be supplemented that, in step S101, only the storage sequence numbers of all the entry data need to be read from the storage device, and no entry data needs to be read.

[0052] S102: The storage sequence numbers of all the entry data are taken as a circular sequence, and the difference between any two adjacent storage sequence numbers in the circular sequence is calculated.

[0053] In some implementations, the starting value of the circular sequence may be the minimum value of all the storage sequence numbers read, and the ending value may be the maximum value of all the storage sequence numbers read. These storage sequence numbers are arranged in a sequentially increasing order in the circular sequence.

[0054] In other implementations, the starting value may be any one of all the storage numbers read, and then these storage numbers are arranged in increasing order, with the next digit of the maximum value being the minimum value, until all the storage numbers read are arranged to form the above-mentioned circular sequence.

[0055] For example, the storage sequence numbers of the read entry data are 0, 1, 2, ... y, then 0, 1, 2, ... y can form a circular sequence with a starting value of 0 and an ending value of y.

[0056] S103: Determine whether there is a breakpoint in the circular sequence according to the difference between any two adjacent storage sequence numbers in the circular sequence, where the breakpoint is a position where the difference between any two adjacent storage sequence numbers in the circular sequence is not a first preset value.

[0057] Wherein, the difference between any two adjacent storage numbers in the annular sequence can be calculated based on the general formula of the annular arithmetic sequence. If the calculated difference is equal to the first preset value, it means that the relationship between the two adjacent storage numbers satisfies the arrangement relationship of the annular arithmetic sequence, that is, it conforms to the logical relationship of the storage number set by the storage device. If the calculated difference is not equal to the first preset value, it means that the relationship between the two adjacent storage numbers does not satisfy the arrangement relationship of the annular arithmetic sequence, that is, it does not conform to the logical relationship of the storage number set by the storage device. At this time, the two storage numbers can be determined as a breakpoint.

[0058] There are at least two forms of breakpoints in a circular sequence. The first form is that the breakpoint is at the end of the circular sequence. The second form is that the breakpoint is in the middle and at the end of the circular sequence.

[0059] FIG3(a) is a schematic diagram of a breakpoint at the end of a circular sequence provided by an embodiment of the present application. In FIG3(a), the circular sequence includes z storage numbers, the starting value in the circular sequence is 0, the ending value is z-1, and z<N, where N is the maximum number of entry data that can be stored in the storage device. At this time, the difference between z-1 and 0 is not equal to the first preset value, and z-1 and 0 do not conform to the general formula of the circular arithmetic sequence, that is, there is a breakpoint between z-1 and 0, and the number of breakpoints for the circular sequence is 1.

[0060] FIG3(b) is a schematic diagram of endpoints at the end and the middle of a circular sequence provided by an embodiment of the present application. In FIG3(b), the circular sequence includes 3 storage numbers, the starting value of the circular sequence is 0, the next digit of the starting value is 1, and the ending value is 3, and the number of storage numbers in the circular sequence is 3<N, where N is the maximum number of entry data that can be stored in the storage device. At this time, the difference between 1 and 3 is not equal to the first preset value, and 1 and 3 do not conform to the general formula of the circular arithmetic sequence, that is, there is a breakpoint between 1 and 3. The difference between 3 and 0 is also not equal to the first preset value, and 3 and 0 do not conform to the general formula of the circular arithmetic sequence, that is, there is also a breakpoint between 3 and 0. The number of breakpoints for this circular sequence is 2. Similarly, the circular sequence may also have a situation where the number of breakpoints is greater than 2, which will not be repeated here.

[0061] S104: If there is no breakpoint, determine that the sequence number of the next entry data to be written into the storage device is the starting value of the circular arithmetic progression.

[0062] If there is no breakpoint, it means that the difference between any two adjacent storage numbers in the annular sequence is equal to the first preset value, then the storage numbers of the item data stored in the storage device can form an annular arithmetic sequence, which means that the number of item data stored in the storage device is equal to the maximum number of item data that can be stored in the storage device. Therefore, the number of the item data written into the storage device next is the starting value of the annular arithmetic sequence, that is, the newly written item data will overwrite the item data first stored in the storage device and whose storage number is the starting value.

[0063] S105: If there are breakpoints, determine the sequence number of the next entry data to be written into the storage device according to the number of breakpoints.

[0064] It can be understood that when there are breakpoints in the circular sequence, the circular sequence includes at least the above two forms. For a circular sequence, the number of breakpoints can indicate the position of the breakpoint in the circular sequence, and the position of the breakpoint in the circular sequence can be used to reflect the state of the storage sequence number of the current entry data in the storage device. After knowing the state of the storage sequence number of the current entry data in the storage device, the sequence number of the next entry data written into the storage device can be determined.

[0065] From the above content, it can be seen that the data storage method provided by the embodiment of the present application determines the sequence number of the next entry data written into the storage device based on the relationship between the storage sequence number of the entry data in the storage device and the annular arithmetic progression. It does not need to obtain all the data stored in the storage device. Even if a large amount of data is already stored in the storage device, the sequence number can be quickly determined. The amount of calculation is small, the memory usage is small, and it is suitable for 8-bit, 16-bit and other processors. It can improve the speed of determining the sequence number of the newly written entry data, shorten the processing time, and be more efficient.

[0066] Figure 4 A schematic diagram of a flow chart for calculating the difference between any two adjacent storage sequence numbers provided in an embodiment of the present application.

[0067] In some implementations, the embodiment S102 of the present application may include the following steps:

[0068] S1021: Determine the number of storage sequence numbers in the circular sequence.

[0069] S1022: If the number of stored sequence numbers in the circular sequence is greater than 1, the following steps are executed in a loop:

[0070] S1, determine whether the difference between the jth storage sequence number and the j+1th storage sequence number in the circular sequence is equal to a first preset value; if it is equal to the first preset value, execute step S2; if it is not equal to the first preset value, execute step S3.

[0071] S3, determine whether there is a breakpoint between the jth storage sequence number and the j+1th storage sequence number, and execute step S2.

[0072] Among them, the starting value of j is 1. The jth storage sequence number and the j+1th storage sequence number are used to represent two adjacent storage sequence numbers. The starting value of j is 1, that is, the process of calculating the difference can be calculated starting from the starting value of the circular sequence. If the difference between the jth storage sequence number and the j+1th storage sequence number is equal to the first preset value, then the jth storage sequence number and the j+1th storage sequence number are stored in sequence, and there is no breakpoint between the two. If the difference between the jth storage sequence number and the j+1th storage sequence number is not equal to the first preset value, there is a breakpoint between the two storage sequence numbers.

[0073] After determining whether there is a breakpoint between the jth storage sequence number and the j+1th storage sequence number, it is necessary to continue to calculate the difference between the j+1th storage sequence number and its next storage sequence number, so that all storage sequence numbers in the circular sequence can be traversed to determine the storage status of all storage sequence numbers stored by the storage device. The specific steps of continuing to calculate the difference between the j+1th storage sequence number and its next storage sequence number are as follows:

[0074] S2, determine whether the j+1th storage sequence number is the last storage sequence number in the circular sequence; if the j+1th storage sequence number is the last storage sequence number in the circular sequence, end the loop; if the j+1th storage sequence number is not the last storage sequence number in the circular sequence, execute step S4.

[0075] S4, add 1 to the value of j and jump to step S1.

[0076] Here, take the case where the arithmetic progression includes t items as an example. If j+1=t, then the j+1th storage number is the last storage number in the circular sequence, indicating that the difference between any two adjacent storage numbers in the circular sequence has been calculated. If j+1≠t, it means that the j+1th storage number is not the last storage number in the circular sequence. At this time, j=j+1 can be set, and then the storage relationship between the jth storage number and the j+1th storage number can be calculated according to S1. In this way, all storage numbers in the circular sequence can be traversed.

[0077] In the embodiment of the present application, the j+1th storage sequence number in the circular sequence satisfies the following formula:

[0078] A j+1 =(A j +d)%m;

[0079] Among them, A j A represents the jth storage number in the circular sequence; j+1 represents the j+1th storage number in the circular sequence; d represents the difference; % is the modulo operator; m represents the total number of storage numbers in the circular arithmetic sequence.

[0080] It is understandable that, given A j+1 , A j When the values ​​of and m are determined, the value of d can be determined accordingly.

[0081] It can be understood that if there is no breakpoint between two adjacent storage numbers in the annular sequence, then the relationship between the two storage numbers conforms to the general formula of the annular arithmetic sequence, and therefore the tolerance d calculated using the total number of storage numbers in the annular arithmetic sequence (the maximum number of entry data that the storage device can store) is equal to the tolerance (first preset value) d' of the annular arithmetic sequence. If there is a breakpoint between two adjacent storage numbers in the annular sequence, then the relationship between the two storage numbers does not conform to the general formula of the annular arithmetic sequence, and therefore the tolerance d calculated using the total number of storage numbers in the annular arithmetic sequence is not equal to the tolerance d' of the annular arithmetic sequence.

[0082] Figure 5 A schematic diagram of a flow chart for determining the sequence number of the next entry data to be written according to the number of sequence numbers stored in a circular sequence provided in an embodiment of the present application.

[0083] In some implementations, after step S101, the embodiment of the present application may further include the following steps:

[0084] S201: Determine whether the number of stored sequence numbers in the circular sequence is equal to 0.

[0085] S202: If the number of storage sequence numbers in the annular sequence is equal to 0, determine that the sequence number of the next entry data to be written into the storage device is the starting value of the annular arithmetic sequence.

[0086] Among them, the number of storage numbers in the annular sequence is equal to 0, indicating that no entry data has been stored in the current storage device, so the storage number of the next entry data written into the storage device can start from the starting value of the annular arithmetic sequence. In this way, the storage number of the newly written entry data can be quickly determined. After that, the value of the storage number can gradually increase from the starting value until a annular arithmetic sequence is formed.

[0087] S203: Determine whether the number of stored sequence numbers in the circular sequence is equal to 1.

[0088] S204: If the number of stored sequence numbers in the circular sequence is equal to 1, determine that the sequence number of the next entry data written into the storage device is a first value, where the first value is the sum of the value of the stored sequence number in the circular sequence and a first preset value.

[0089] Among them, the number of storage numbers in the circular sequence is equal to 1, indicating that there is one entry data stored in the current storage device. At this time, for the next entry data written into the storage device, its storage sequence number can be determined by simply calculating with the storage sequence number in the circular sequence. Specifically, the storage sequence number in the circular sequence can be added to the first preset value to obtain a first value, and the first value is the sequence number of the next entry data written into the storage device. In this way, the sequence number of the next entry data written into the storage device and the storage sequence number of the entry data stored in the storage device satisfy the general formula of the circular arithmetic progression of the storage device. In this way, the storage sequence number of the newly written entry data can be quickly determined.

[0090] For example, if the value of the stored sequence number in the annular sequence is 0, then the first value = 0 + the first preset value, and when the first preset value is 1, the first value = 1. The first value calculated in this way can satisfy the general formula of the annular arithmetic sequence of the storage device.

[0091] It should be noted that the order of S201, S202 and S203, S204 can be swapped, and is not limited to S203, S204 being after S201, S202.

[0092] Figure 6 A schematic diagram of a flow chart for determining the sequence number of the next entry data to be written according to the number of breakpoints provided in an embodiment of the present application.

[0093] In some implementations, step S105 of the embodiment of the present application may include the following steps:

[0094] S1051: If the number of breakpoints is equal to 1, determine that the sequence number of the next entry data written into the storage device is a second value, and the second value is the sum of the previous storage sequence number of the breakpoint position and the first preset value.

[0095] Among them, if the number of breakpoints is equal to 1, it means that the circular sequence does not form a circular arithmetic sequence, and the storage device stores the entry data in sequence, and the breakpoint appears between the tail end of the circular sequence and the starting value of the circular sequence. At this time, for the next entry data written into the storage device, its storage sequence number can be determined by calculating the storage sequence number at the tail end of the circular sequence (the previous storage sequence number of the breakpoint position). Specifically, the previous storage sequence number of the breakpoint position can be added to the first preset value to obtain a second value, and the second value is the sequence number of the next entry data written into the storage device. In this way, the sequence number of the next entry data written into the storage device and the previous storage sequence number of the breakpoint position satisfy the general formula of the circular arithmetic sequence of the storage device. In this way, the storage sequence number of the newly written entry data can be quickly determined.

[0096] For example, if the previous storage sequence number of the breakpoint position in the annular sequence is 5, then the second value = 5 + the first preset value, and when the first preset value is 1, the second value = 6. The second value calculated in this way can satisfy the general formula of the annular arithmetic sequence of the storage device.

[0097] S1052: If the number of breakpoints is greater than 1, determine that the sequence number of the next entry data to be written into the storage device is the starting value of the circular arithmetic progression.

[0098] If the number of breakpoints is greater than 1, it means that the annular sequence does not form an annular arithmetic sequence and there are multiple breakpoints in the annular sequence. At this time, the stored data in the storage device has been damaged, so the sequence number of the next entry data written into the storage device is the starting value of the annular arithmetic sequence.

[0099] Figure 7 A schematic diagram of the structure of a data storage device provided in an embodiment of the present application is shown in FIG. Figure 7 As shown, the device may include the following modules:

[0100] The reading module 301 is used to read the storage sequence numbers of all entry data in the storage device.

[0101] The difference calculation module 302 is used to take the storage sequence numbers of all the entry data as a circular sequence and calculate the difference between any two adjacent storage sequence numbers in the circular sequence.

[0102] The breakpoint determination module 303 is used to determine whether there is a breakpoint in the circular sequence according to the difference between any two adjacent storage numbers in the circular sequence, and the breakpoint is a position where the difference between any two adjacent storage numbers in the circular sequence is not a first preset value.

[0103] The first sequence number determination module 304 is used to determine the sequence number of the next entry data to be written into the storage device as the starting value of the circular arithmetic progression if there is no breakpoint.

[0104] The second sequence number determination module 305 is used to determine the sequence number of the next entry data to be written into the storage device according to the number of breakpoints if there are breakpoints.

[0105] From the above content, it can be seen that the data storage device provided in the embodiment of the present application determines the sequence number of the next entry data written into the storage device based on the relationship between the storage sequence number of the entry data in the storage device and the annular arithmetic progression. It does not need to obtain all the data stored in the storage device. Even if a large amount of data is already stored in the storage device, the sequence number can be quickly determined. The amount of calculation is small, the memory usage is small, and it is suitable for 8-bit, 16-bit and other processors. It can improve the speed of determining the sequence number of the newly written entry data, shorten the processing time, and be more efficient.

[0106] In a specific implementation, the present invention further provides a computer storage medium, wherein the computer storage medium may store a program, and when the program is executed, the program may include some or all of the steps in each embodiment of the method for determining a network resource reuse area provided by the present invention. The storage medium may be a magnetic disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM).

[0107] It is easy to understand that those skilled in the art can combine, split, reorganize, etc. the embodiments of the present application to obtain other embodiments based on the several embodiments provided in the present application, and these embodiments do not exceed the protection scope of the present application.

[0108] The above specific implementation methods further explain in detail the purpose, technical solutions and beneficial effects of the embodiments of the present application. It should be understood that the above are only specific implementation methods of the embodiments of the present application and are not used to limit the protection scope of the embodiments of the present application. Any modifications, equivalent substitutions, improvements, etc. made on the basis of the technical solutions of the embodiments of the present application should be included in the protection scope of the embodiments of the present application.

Claims

1. A data storage method, It is characterized in that Applied to a storage device, the storage device is used to store at most N items of data, and when each item of data is written into the storage device, a storage sequence number is assigned to each item of data; wherein the storage sequence number of the i-th item of data differs from the storage sequence number of the i-1th data item by a first preset value, the first preset value is 1, and i is less than or equal to N; when the number of data items written into the storage device is N, the N storage sequence numbers corresponding to the N items of data form a ring arithmetic progression, and the starting value of the ring arithmetic progression is 0; The method comprises: Read the storage sequence numbers of all entry data in the storage device; Taking the storage sequence numbers of all the entry data as a circular sequence, and calculating the difference between any two adjacent storage sequence numbers in the circular sequence; According to the difference between any two adjacent storage numbers in the circular sequence, it is determined whether there is a breakpoint in the circular sequence, and the breakpoint is a position where the difference between any two adjacent storage numbers in the circular sequence is not the first preset value; the j+1th storage number in the circular sequence satisfies the following formula: A j+1 =(A j +d)%m; Among them, A j+1 A represents the j+1th storage sequence number in the circular sequence; j represents the jth storage sequence number in the annular sequence; d represents the difference; % is the modulo operator; m represents the total number of storage sequences in the annular arithmetic sequence; If there is no breakpoint, determining the sequence number of the next entry data to be written into the storage device as the starting value of the annular arithmetic progression to determine the writing point of the next entry data to be written into the storage device; If there are breakpoints, the sequence number of the next entry data to be written into the storage device is determined according to the number of the breakpoints to determine the writing point of the next entry data to be written into the storage device.

2. The data storage method according to claim 1, It is characterized in that The step of taking the storage sequence numbers of all the entry data as a circular sequence and calculating the difference between any two adjacent storage sequence numbers in the circular sequence comprises: Determining the number of the storage sequence numbers in the annular sequence; If the number of the stored sequence numbers in the circular sequence is greater than 1, the following steps are executed in a loop: S1, determine whether the difference between the jth storage sequence number and the j+1th storage sequence number in the circular sequence is equal to the first preset value; if it is equal to the first preset value, execute step S2; if it is not equal to the first preset value, determine that there is a breakpoint between the jth storage sequence number and the j+1th storage sequence number, and execute step S2; wherein the starting value of j is 1; S2, determine whether the j+1th storage sequence number is the last storage sequence number in the circular sequence; if the j+1th storage sequence number is the last storage sequence number in the circular sequence, end the loop; if the j+1th storage sequence number is not the last storage sequence number in the circular sequence, add 1 to the value of j and jump to step S1.

3. The data storage method according to claim 2, It is characterized in that Also includes: If the number of the storage sequence numbers in the annular sequence is equal to 0, the sequence number of the next entry data to be written into the storage device is determined to be the starting value of the annular arithmetic sequence.

4. The data storage method according to claim 2, It is characterized in that Also includes: If the number of the storage sequence numbers in the circular sequence is equal to 1, the sequence number of the next entry data written into the storage device is determined to be a first value, which is the sum of the value of the storage sequence number in the circular sequence and the first preset value.

5. The data storage method according to claim 1, It is characterized in that If there are breakpoints, determining the sequence number of the next entry data to be written into the storage device according to the number of the breakpoints comprises: If the number of breakpoints is equal to 1, the sequence number of the next entry data written into the storage device is determined to be a second value, and the second value is the sum of the previous storage sequence number of the breakpoint position and the first preset value.

6. The data storage method according to claim 1, It is characterized in that If there are breakpoints, determining the sequence number of the next entry data to be written into the storage device according to the number of the breakpoints comprises: If the number of the breakpoints is greater than 1, the sequence number of the next entry data to be written into the storage device is determined to be the starting value of the annular arithmetic progression.

7. The data storage method according to claim 1, It is characterized in that The n+1th storage sequence number in the annular arithmetic progression satisfies the following formula: A n+1 =(A n +d′)%N; In the formula, A n+1 A represents the n+1th storage sequence number in the annular arithmetic progression; n represents the nth storage sequence number in the annular arithmetic progression; d ′ represents the first preset value; % is the modulo operator; N represents the total number of stored sequence numbers in the annular arithmetic sequence.

8. A data storage device, It is characterized in that Applied to a storage device, the storage device is used to store at most N items of data, and when each item of data is written into the storage device, a storage sequence number is assigned to each item of data; wherein the storage sequence number of the i-th item of data differs from the storage sequence number of the i-1th data item by a first preset value, the first preset value is 1, and i is less than or equal to N; when the number of data items written into the storage device is N, the N storage sequence numbers corresponding to the N items of data form a ring arithmetic progression, and the starting value of the ring arithmetic progression is 0; The data storage device comprises: A reading module, used for reading the storage sequence numbers of all entry data in the storage device; A difference calculation module, used for taking the storage sequence numbers of all the entry data as a circular sequence, and calculating the difference between any two adjacent storage sequence numbers in the circular sequence; A breakpoint determination module is used to determine whether there is a breakpoint in the circular sequence according to the difference between any two adjacent storage sequence numbers in the circular sequence, wherein the breakpoint is a position where the difference between any two adjacent storage sequence numbers in the circular sequence is not the first preset value; the j+1th storage sequence number in the circular sequence satisfies the following formula: A j+1 =(A j +d)%m; Among them, A j+1 A represents the j+1th storage sequence number in the circular sequence; j represents the jth storage sequence number in the annular sequence; d represents the difference; % is the modulo operator; m represents the total number of storage sequences in the annular arithmetic sequence; A first sequence number determination module is used to determine, if there is no breakpoint, that the sequence number of the next entry data written into the storage device is the starting value of the annular arithmetic progression, so as to determine the writing point of the next entry data written into the storage device; The second sequence number determination module is used to determine the sequence number of the next entry data written into the storage device according to the number of the breakpoints if there are breakpoints, so as to determine the writing point of the next entry data written into the storage device.