CN103226602B - A kind of location reading offset method realizing circulation storage record in single file - Google Patents

A kind of location reading offset method realizing circulation storage record in single file Download PDF

Info

Publication number
CN103226602B
CN103226602B CN201310150557.9A CN201310150557A CN103226602B CN 103226602 B CN103226602 B CN 103226602B CN 201310150557 A CN201310150557 A CN 201310150557A CN 103226602 B CN103226602 B CN 103226602B
Authority
CN
China
Prior art keywords
record
file
label
higher limit
write
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201310150557.9A
Other languages
Chinese (zh)
Other versions
CN103226602A (en
Inventor
王斌
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Fujian Landi Commercial Equipment Co Ltd
Original Assignee
Fujian Landi Commercial Equipment Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Fujian Landi Commercial Equipment Co Ltd filed Critical Fujian Landi Commercial Equipment Co Ltd
Priority to CN201310150557.9A priority Critical patent/CN103226602B/en
Publication of CN103226602A publication Critical patent/CN103226602A/en
Application granted granted Critical
Publication of CN103226602B publication Critical patent/CN103226602B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a kind of method realizing and circulating storage record in single file, it comprises the following steps: 1) enactment document can store higher limit N of record strip number;2) set M as can not be evenly divisible by N any positive integer;3) in file, record is write in order, for every record one label A of distribution;4) method of label is set as A=(Apre+ 1) %M, wherein ApreFor a upper record index value;5) after the record number in file reaches higher limit, the label of all records is scanned, if (A+1) %M!=Anext, then A it is numberednextRecord position i.e. be to continue with write new record position.The present invention is by giving record distribution label and the method for delivery, achieve circulation in monofile and add record, easy positioning cycle file can write slider position, thus realize well reading record and write record, can effectively control again the size that file takes up room.

Description

A kind of location reading offset method realizing circulation storage record in single file
Technical field
The present invention relates to file memory method, particularly relate to a kind of location realizing circulating storage record in single file and read Offset method.
Background technology
Conventional a kind of usage in data store: with single several records of file linear memory, when record number reaches to set valve During value, newly-increased record, by covering a oldest record, so circulates storage.Such as: some journal files use this side Formula carries out the daily record of record system operation, i.e. can preserve the process logs that system is run, it is also ensured that journal file only takes up Limited space.In the present invention, this file is called circular file.During to circular file access record, first having to solution is: fixed Position is to the oldest record in file.Simple localization method: can be newly-increased by increasing a LSN to every record Record increases by 1 on the basis of last registration sequence number.Newly-increased LSN is maximum all the time, therefore can be by scanning record Sequence number, what sequence number was minimum is recorded as the oldest record.But owing to LSN constantly increases, to such an extent as to the LSN write below It is likely to occur the effective storage bit number (such as 1 byte can represent that maximum numerical value is 256) exceeding computer.The most in the past, The LSN constantly increased can only take, by increase, the numerical value that figure place represents bigger, and this point not only wastes memory space, Also increase the complexity of calculating simultaneously.
Summary of the invention
It is an object of the invention to provide one and can circulate interpolation record in single file, and the space that LSN takies will not The realization increased circulates storage record in single file and offset method is read in location.
For achieving the above object, the technical scheme is that realization circulation storage record in single file includes following step Rapid:
1) enactment document can store higher limit N of record strip number;
2) set M as can not be evenly divisible by N any positive integer, i.e. N%M!=0, % are modulo operation;
3) in order toward file writes record, for every record one label of distribution, first bar record be numbered 0, be numbered non-negative Integer, represents with A;
4) method of label is set as A=(Apre+ 1) %M, wherein ApreFor a upper record index value, % is modulo operation I.e. (Apre+ 1) the remainder number that is divided by with M operates;
5) when the record strip number of file reaches higher limit N first, next time re-writes record from top of file, and covers the oldest Record;
6) after file record number reaches higher limit, the label of all records is scanned, if (A+1) %M!=Anext, then A it is numberednext Record position i.e. be to continue with write new record position;Wherein, AnextFor being positioned at a rear record label of current record;If When current record is positioned at end of file, AnextLabel for top of file record;
Offset method is read in described location:
1) when the record number in file is not up to higher limit N, record-shifted Y=ID*L;
Wherein Y is the deviation post of record, and ID is the sequence number of record, and the serial number record of record is ranked up according to adding time sequencing, Starting counting up from 0, the sequence number ID maximum of record is N-1;
2) after file record number reaches higher limit N, Y=(C+ID*L) % (N*L);
Wherein, Y is the deviation post of record, and L is the length of record, and the length setting every record is identical;ID is the sequence number of record, The serial number record of record is ranked up according to adding time sequencing, starts counting up from 0, and the sequence number ID maximum of record is N -1;C is the skew writing slider position.
The present invention uses above method, realizes circulation and add record in single file.Meanwhile, for each record distribution mark Number, by label is carried out modulo operation, make the index value of record constantly to increase, effectively control file and take up room Size, again ensure user can store up-to-date some records.The present invention gives the method for positioning cycle top of file, Write record can be conveniently implemented in file.
When described file record number is not up to higher limit N, then write vernier still at the end of file;When described file record After number reaches higher limit N, it is numbered AnextRecord position i.e. be to continue with write new record position, be i.e. to write slider position.
The length of described every record is identical, and length L of every record represents.
Use above method, the position reading record can be positioned easily, thus record can be read easily.
In a word, the present invention is by giving record distribution label and the method for delivery, it is achieved that in monofile, record is added in circulation, The easiest positioning cycle file can write slider position, thus realize well reading record and write record;I.e. effectively control Make the size that file takes up room, ensured that again user can store up-to-date some records.In actual use, the present invention Method is respond well, is worthy to be popularized.
Detailed description of the invention
The present invention realizes circulation storage record in single file and comprises the following steps:
1) enactment document can store higher limit N of record strip number;
2) set M as can not be evenly divisible by N any positive integer, i.e. N%M!=0, % are modulo operation;
3) in order toward file writes record, for every record one label of distribution, first bar record be numbered 0, be numbered non-negative Integer, represents with A;
4) method of label is set as A=(Apre+ 1) %M, wherein ApreFor a upper record index value, % is modulo operation I.e. (Apre+ 1) the remainder number that is divided by with M operates;As shown in table 1;
Table 1 monofile records the arranging situation of label
0 1 M-1 0 M-2 M-1
5) when the record strip number of file reaches higher limit N first, as shown in table 2, next time re-writes record from top of file, And cover the oldest record, as shown in table 3;
The record strip number of table 2 file reaches the arranging situation of record label during higher limit N
0 1 M-1 0 M-2 M-1 (N-1) %M
The record strip number of table 3 file reaches state-of-the-art record after higher limit N and covers the situation of the oldest record
N%M 1 M-1 0 M-2 M-1 (N-1) %M
6) after file record number reaches higher limit, the label of all records is scanned, if (A+1) %M!=Anext, then A it is numberednext Record position i.e. be to continue with write new record position;Wherein, AnextFor being positioned at a rear record label of current record;If When current record is positioned at end of file, AnextLabel for top of file record.
As shown in table 4, when carry out in positioning cycle file when writing slider position, due to N%M!=0, therefore (N+Q -1+1) %M!=Q.
Therefore scanning record label, find (A+1) %M!=AnextTime, it is numbered AnextRecord be i.e. circular file write trip Cursor position.
Table 4 positioning cycle file writes slider position
(N+Q-1) %M Q M-1 0 M-2 M-1 (N+Q-2) %M
Wherein, when described file record number is not up to higher limit N, then vernier is write still at the end of file;When described file note After record number reaches higher limit N, it is numbered AnextRecord position i.e. be to continue with write new record position, be i.e. to write slider position.
The length of described every record is identical, and length L of every record represents.
The present invention also provides for realizing the location of circulation storage record in single file and reads offset method, and described location is read partially Shifting method is:
1) when the record number in file is not up to higher limit N, record-shifted Y=ID*L;
Wherein Y is the deviation post of record, and ID is the sequence number of record, and the serial number record of record is ranked up according to adding time sequencing, Starting counting up from 0, the sequence number ID maximum of record is N-1;
2) after file record number reaches higher limit N, Y=(C+ID*L) % (N*L);
Wherein, Y is the deviation post of record, and L is the length of record, and the length setting every record is identical;ID is the sequence number of record, The serial number record of record is ranked up according to adding time sequencing, starts counting up from 0, and the sequence number ID maximum of record is N -1;C is the skew writing slider position.

Claims (3)

1. the location reading offset method realizing circulation storage record in single file, it is characterised in that: in single file, circulation storage record comprises the following steps:
1) enactment document can store higher limit N of record strip number;
2) set M as can not be evenly divisible by N any positive integer, i.e. N%M!=0, % are modulo operation;
3) in order toward file writes record, for every record one label of distribution, first bar record be numbered 0, be numbered nonnegative integer, represent with A;
4) method of label is set as A=(Apre+ 1) %M, wherein ApreFor a upper record index value, % is modulo operation i.e. (Apre+ 1) the remainder number that is divided by with M operates;
5) when the record strip number in file reaches higher limit N first, next time re-writes record from top of file, and covers the oldest record;
6) after the record number in file reaches higher limit, the label of all records is scanned, if (A+1) % M!= Anext, then A it is numberednextRecord position i.e. be to continue with write new record position;Wherein, AnextFor being positioned at a rear record label of current record;If current record is positioned at end of file, AnextLabel for top of file record;
Offset method is read in described location:
1) when the record number in file is not up to higher limit N, record-shifted Y=ID * L;
Wherein Y is the deviation post of record, and ID is the sequence number of record, and the serial number record of record is ranked up according to adding time sequencing, starts counting up from 0, and the sequence number ID maximum of record is N-1;
2) after file record number reaches higher limit N, Y=(C+ID * L) %(N*L);
Wherein, Y is the deviation post of record, and L is the length of record, and the length setting every record is identical;ID is the sequence number of record, and the serial number record of record is ranked up according to adding time sequencing, starts counting up from 0, and the sequence number ID maximum of record is N-1;C is the skew writing slider position.
Realization the most according to claim 1 circulates the location of storage record in single file and reads offset method, it is characterised in that: when the record number in described file is not up to higher limit N, then write vernier still at the end of file;After the record number in described file reaches higher limit N, it is numbered AnextRecord position i.e. be to continue with write new record position, be i.e. to write slider position.
Realization the most according to claim 1 circulates the location of storage record in single file and reads offset method, it is characterised in that: the length of described every record is identical, and length L of every record represents.
CN201310150557.9A 2013-04-26 2013-04-26 A kind of location reading offset method realizing circulation storage record in single file Active CN103226602B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201310150557.9A CN103226602B (en) 2013-04-26 2013-04-26 A kind of location reading offset method realizing circulation storage record in single file

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201310150557.9A CN103226602B (en) 2013-04-26 2013-04-26 A kind of location reading offset method realizing circulation storage record in single file

Publications (2)

Publication Number Publication Date
CN103226602A CN103226602A (en) 2013-07-31
CN103226602B true CN103226602B (en) 2016-08-10

Family

ID=48837047

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201310150557.9A Active CN103226602B (en) 2013-04-26 2013-04-26 A kind of location reading offset method realizing circulation storage record in single file

Country Status (1)

Country Link
CN (1) CN103226602B (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101662336A (en) * 2009-09-16 2010-03-03 北京海尔集成电路设计有限公司 Configurable interleave and deinterleave method and device thereof
CN102694924A (en) * 2012-06-14 2012-09-26 宇龙计算机通信科技(深圳)有限公司 Communication data storing system and method for mobile terminal

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP4910475B2 (en) * 2006-05-18 2012-04-04 ソニー株式会社 RECORDING DEVICE, RECORDING METHOD, RECORDING PROGRAM, IMAGING DEVICE, IMAGING METHOD, AND IMAGING PROGRAM

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101662336A (en) * 2009-09-16 2010-03-03 北京海尔集成电路设计有限公司 Configurable interleave and deinterleave method and device thereof
CN102694924A (en) * 2012-06-14 2012-09-26 宇龙计算机通信科技(深圳)有限公司 Communication data storing system and method for mobile terminal

Also Published As

Publication number Publication date
CN103226602A (en) 2013-07-31

Similar Documents

Publication Publication Date Title
CN107168647B (en) FLASH data read-write method and system
CN110149803B (en) Data storage method, system and terminal equipment
CN104220991B (en) Framework for allowing effective storage of the data on nand flash memory
US9323661B2 (en) Memory system and control method thereof
CN102157202B (en) Method and controller for preventing nonvolatile memory from occurring read interference
CN106409344A (en) Data storage device and operating method thereof
CN107346212B (en) Method for screening damaged data row and data storage device with damaged data row general table
CN102158349A (en) Log management device and method thereof
CN105830022A (en) File access method and apparatus
CN104620230A (en) Method of managing memory
US20130054878A1 (en) Solid state drive and wear-leveling control method thereof
CN103440205A (en) Method and device for storing data of set top box
CN102200892A (en) Capacity expansion method based on dynamic redundant array of independent disks (RAID) system
CN102214143A (en) Method and device for managing multilayer unit flash memory, and storage equipment
CN104919433A (en) Page allocation for flash memories
CN103412826A (en) Garbage collection method and system of solid state disk
CN101441891B (en) Method for using flash memory
US9710504B2 (en) Data processing and writing method and related apparatus
CN106155572B (en) Data storage device and data access method
CN103226602B (en) A kind of location reading offset method realizing circulation storage record in single file
CN111984651A (en) Column type storage method, device and equipment based on persistent memory
CN104572139A (en) Method and device for accelerating starting of application program
CN106844229B (en) Organization method, system and device of solid state disk firmware mapping table
CN102609364A (en) Cache exchange method
CN109521954B (en) Distribution network FTU fixed point file management method and device

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant