⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbz.3z

📁 gcc-2.95.3 Linux下最常用的C编译器
💻 3Z
字号:
.TH DBZ 3Z "3 Feb 1991".BY "C News".SH NAMEdbminit, fetch, store, dbmclose \- somewhat dbm-compatible database routines.brdbzfresh, dbzagain, dbzfetch, dbzstore \- database routines.brdbzsync, dbzsize, dbzincore, dbzcancel, dbzdebug \- database routines.SH SYNOPSIS.nf.B #include <dbz.h>.PP.B dbminit(base).B char *base;.PP.B datum.B fetch(key).B datum key;.PP.B store(key, value).B datum key;.B datum value;.PP.B dbmclose().PP.B dbzfresh(base, size, fieldsep, cmap, tagmask).B char *base;.B long size;.B int fieldsep;.B int cmap;.B long tagmask;.PP.B dbzagain(base, oldbase).B char *base;.B char *oldbase;.PP.B datum.B dbzfetch(key).B datum key;.PP.B dbzstore(key, value).B datum key;.B datum value;.PP.B dbzsync().PP.B long.B dbzsize(nentries).B long nentries;.PP.B dbzincore(newvalue).PP.B dbzcancel().PP.B dbzdebug(newvalue).SH DESCRIPTIONThese functions provide an indexing system for rapid random access to atext file (the.I base .IR file ).Subject to certain constraints, they are call-compatible with.IR dbm (3),although they also provide some extensions.(Note that they are.I notfile-compatible with.I dbmor any variant thereof.).PPIn principle,.I dbzstores key-value pairs, where both key and value are arbitrary sequencesof bytes, specified to the functions byvalues of type.IR datum ,typedefed in the header file to be a structure with members.I dptr(a value of type.I char *pointing to the bytes)and.I dsize(a value of type.I intindicating how long the byte sequence is)..PPIn practice,.I dbzis more restricted than.IR dbm .A.I dbzdatabasemust be an index into a base file,with the database.IR value sbeing.IR fseek (3)offsets into the base file.Each such.I valuemust ``point to'' a place in the base file where the corresponding.I keysequence is found.A key can be no longer than.SM DBZMAXKEY(a constant defined in the header file) bytes.No key can be an initial subsequence of another,which in most applications requires that keys beeither bracketed or terminated in some way (see thediscussion of the.I fieldsepparameter of.IR dbzfresh ,below,for a fine point on terminators)..PP.I Dbminitopens a database,an index into the base file.IR base ,consisting of files.IB base .dirand.IB base .pagwhich must already exist.(If the database is new, they should be zero-length files.)Subsequent accesses go to that database until.I dbmcloseis called to close the database.The base file need not exist at the time of the.IR dbminit ,but it must exist before accesses are attempted..PP.I Fetchsearches the database for the specified.IR key ,returning the corresponding.IR valueif any..I Storestores the.IR key - valuepair in the database..I Storewill fail unless the database files are writeable.See below for a complication arising from case mapping..PP.I Dbzfreshis a variant of.I dbminitfor creating a new database with more control over details.Unlike for.IR dbminit ,the database files need not exist:they will be created if necessary,and truncated in any case..PP.IR Dbzfresh 's.I sizeparameter specifies the size of the first hash table within the database,in key-value pairs.Performance will be best if.I sizeis a prime number andthe number of key-value pairs stored in the database does not exceedabout 2/3 of.IR size .(The.I dbzsizefunction, given the expected number of key-value pairs,will suggest a database size that meets these criteria.)Assuming that an.I fseekoffset is 4 bytes,the.B .pagfile will be.RI 4* sizebytes(the.B .dirfile is tiny and roughly constant in size)untilthe number of key-value pairs exceeds about 80% of.IR size .(Nothing awful will happen if the database grows beyond 100% of.IR size ,but accesses will slow down somewhat and the.B .pagfile will grow somewhat.).PP.IR Dbzfresh 's.I fieldsepparameter specifies the field separator in the base file.If this is notNUL (0), and the last character of a.I keyargument is NUL, that NUL compares equal to either a NUL or a.I fieldsepin the base file.This permits use of NUL to terminate key strings without requiring thatNULs appear in the base file.The.I fieldsepof a database created with.I dbminitis the horizontal-tab character..PPFor use in news systems, various forms of case mapping (e.g. uppercase tolowercase) in keys are available.The.I cmapparameter to.I dbzfreshis a single character specifying which of several mapping algorithms to use.Available algorithms are:.RS.TP.B 0case-sensitive:  no case mapping.TP.B Bsame as.B 0.TP.B NULsame as.B 0.TP.B =case-insensitive:  uppercase and lowercase equivalent.TP.B bsame as.B =.TP.B CRFC822 message-ID rules, case-sensitive before `@' (with certain exceptions)and case-insensitive after.TP.B ?whatever the local default is, normally.B C.RE.PPMapping algorithm.B 0(no mapping) is faster than the others and is overwhelmingly the correctchoice for most applications.Unless compatibility constraints interfere, it is more efficient to pre-mapthe keys, storing mapped keys in the base file, than to have.I dbzdo the mapping on every search..PPFor historical reasons,.I fetchand.I storeexpect their.I keyarguments to be pre-mapped, but expect unmapped keys in the base file..I Dbzfetchand.I dbzstoredo the same jobs but handle all case mapping internally,so the customer need not worry about it..PP.I Dbzstores only the database.IR value sin its files, relying on reference to the base file to confirm a hit on a key.References to the base file can be minimized, greatly speeding up searches,if a little bit of information about the keys can be stored in the.I dbzfiles.This is ``free'' if there are some unused bits in an.I fseekoffset,so that the offset can be.I taggedwith some information about the key.The.I tagmaskparameter of.I dbzfreshallows specifying the location of unused bits..I Tagmaskshould be a mask withone group ofcontiguous.B 1bits.The bits in the mask shouldbe unused (0) in.I mostoffsets.The bit immediately above the mask (the.I flagbit) should be unused (0) in.I alloffsets;.I (dbz)storewill reject attempts to store a key-value pair in which the.I valuehas the flag bit on.Apart from this restriction, tagging is invisible to the user.As a special case, a.I tagmaskof 1 means ``no tagging'', for use with enormous base files oron systems with unusual offset representations..PPA.I sizeof 0given to.I dbzfreshis synonymous with the local default;the normal default is suitable for tables of 90-100,000key-value pairs.A.I cmapof 0 (NUL) is synonymous with the character.BR 0 ,signifying no case mapping(note that the character.B ?specifies the local default mapping,normally.BR C ).A.I tagmaskof 0 is synonymous with the local default tag mask,normally 0x7f000000 (specifying the top bit in a 32-bit offsetas the flag bit, and the next 7 bits as the mask,which is suitable for base files up to circa 24MB).Calling.I dbminit(name)with the database files empty is equivalent to calling.IR dbzfresh(name,0,'\et','?',0) ..PPWhen databases are regenerated periodically, as in news,it is simplest to pick the parameters for a new database based on the old one.This also permits some memory of past sizes of the old database, so thata new database size can be chosen to cover expected fluctuations..I Dbzagainis a variant of.I dbminitfor creating a new database as a new generation of an old database.The database files for.I oldbasemust exist..I Dbzagainis equivalent to calling.I dbzfreshwith the same field separator, case mapping, and tag mask as the old database,and a.I sizeequal to the result of applying.I dbzsizeto the largest number of entries in the.I oldbasedatabase and its previous 10 generations..PPWhen many accesses are being done by the same program,.I dbzis massively faster if its first hash table is in memory.If an internal flag is 1,an attempt is made to read the table in whenthe database is opened, and.I dbmclosewrites it out to disk again (if it was read successfully andhas been modified)..I Dbzincoresets the flag to.I newvalue(which should be 0 or 1)and returns the previous value;this does not affect the status of a database that has already been opened.The default is 0.The attempt to read the table in may fail due to memory shortage;in this case.I dbzquietly falls back on its default behavior..IR Store sto an in-memory database are not (in general) written out to the fileuntil.IR dbmcloseor.IR dbzsync ,so if robustness in the presence of crashesor concurrent accessesis crucial, in-memory databasesshould probably be avoided..PP.I Dbzsynccauses all buffers etc. to be flushed out to the files.It is typically used as a precaution against crashes or concurrent accesseswhen a.IR dbz -usingprocess will be running for a long time.It is a somewhat expensive operation,especiallyfor an in-memory database..PP.I Dbzcancelcancels any pending writes from buffers.This is typically useful only for in-core databases, since writes areotherwise done immediately.Its main purpose is to let a child process, in the wake of a.IR fork ,do a.I dbmclosewithout writing its parent's data to disk..PPIf.I dbzhas been compiled with debugging facilities available (which makes itbigger and a bit slower),.I dbzdebugalters the value (and returns the previous value) of an internal flagwhich (when 1; default is 0) causesverbose and cryptic debugging output on standard output..PPConcurrent reading of databases is fairly safe,but there is no (inter)locking,so concurrent updating is not..PPThe database files include a record of the byte order of the processorcreating the database, and accesses by processors with different byteorder will work, although they will be slightly slower.Byte order is preserved by.IR dbzagain .However,agreement on the size and internal structure of an.I fseekoffset is necessary, as is consensus onthe character set..PPAn open database occupies three.I stdiostreams and their corresponding file descriptors;a fourth is needed for an in-memory database.Memory consumption is negligible (except for.I stdiobuffers) except for in-memory databases..SH SEE ALSOdbz(1), dbm(3).SH DIAGNOSTICSFunctions returning.I intvalues return 0 for success, \-1 for failure.Functions returning.I datumvalues return a value with.I dptrset to NULL for failure..I Dbminitattempts to have.I errnoset plausibly on return, but otherwise this is not guaranteed.An.I errnoof.B EDOMfrom.I dbminitindicates that the database did not appear to be in.I dbzformat..SH HISTORYThe original.I dbzwas written byJon Zeeff (zeeff@b-tech.ann-arbor.mi.us).Later contributions by David Butler and Mark Moraes.Extensive reworking,including this documentation,by Henry Spencer (henry@zoo.toronto.edu) aspart of the C News project.Hashing function by Peter Honeyman..SH BUGSThe.I dptrmembers of returned.I datumvalues point to static storage which is overwritten by later calls..PPUnlike.IR dbm ,.I dbzwill misbehave if an existing key-value pair is `overwritten' bya new.I (dbz)storewith the same key.The user is responsible for avoiding this by using.I (dbz)fetchfirst to check for duplicates;an internal optimization remembers the result of thefirst search so there is minimal overhead in this..PPWaiting until after.I dbminitto bring the base file into existencewill fail if.IR chdir (2)has been used meanwhile..PPThe RFC822 case mapper implements only a first approximation to thehideously-complex RFC822 case rules..PPThe prime finder in.I dbzsizeis not particularly quick..PPShould implement the.I dbmfunctions.IR delete ,.IR firstkey ,and.IR nextkey ..PPOn C implementations which trap integer overflow,.I dbzwill refuse to.I (dbz)storean.I fseekoffset equal to the greatestrepresentablepositive number,as this would cause overflow in the biased representation used..PP.I Dbzagainperhaps ought to notice when many offsetsin the old database weretoo big fortagging, and shrink the tag mask to match..PPMarking.IR dbz 'sfile descriptors.RI close-on- execwould be a better approach to the problem.I dbzcanceltries to address, but that's harder to do portably.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -