1 .\" tbl | readme.ms | [tn]roff -ms | ...
2 .\" note the "C" (courier) and "CB" fonts: you will probably have to
4 .\" $Id: readme.ms,v 1.1 90/12/13 13:09:15 oz Exp Locker: oz $
13 .ta 1u*\\ntu 2u*\\ntu 3u*\\ntu 4u*\\ntu 5u*\\ntu 6u*\\ntu 7u*\\ntu 8u*\\ntu 9u*\\ntu 10u*\\ntu 11u*\\ntu 12u*\\ntu 13u*\\ntu 14u*\\ntu
23 .\" CW uses the typewriter/courier font.
28 .\" Footnote numbering [by Henry Spencer]
29 .\" <text>\*f for a footnote number..
31 .\" \*F <footnote text>
34 .ds f \\u\\s-2\\n+f\\s+2\\d
42 \fIsdbm\fP \(em Substitute DBM
46 Berkeley \fIndbm\fP for Every UN*X\** Made Simple
50 The Guild of PD Software Toolmakers
56 UN*X is not a trademark of any (dis)organization.
59 \fIImplementation is the sincerest form of flattery. \(em L. Peter Deutsch\fP
61 A The Clone of the \fIndbm\fP library
63 The sources accompanying this notice \(em \fIsdbm\fP \(em constitute
64 the first public release (Dec. 1990) of a complete clone of
65 the Berkeley UN*X \fIndbm\fP library. The \fIsdbm\fP library is meant to
66 clone the proven functionality of \fIndbm\fP as closely as possible,
67 including a few improvements. It is practical, easy to understand, and
69 The \fIsdbm\fP library is not derived from any licensed, proprietary or
72 The \fIsdbm\fP implementation is based on a 1978 algorithm
73 [Lar78] by P.-A. (Paul) Larson known as ``Dynamic Hashing''.
74 In the course of searching for a substitute for \fIndbm\fP, I
75 prototyped three different external-hashing algorithms [Lar78, Fag79, Lit80]
76 and ultimately chose Larson's algorithm as a basis of the \fIsdbm\fP
77 implementation. The Bell Labs
78 \fIdbm\fP (and therefore \fIndbm\fP) is based on an algorithm invented by
79 Ken Thompson, [Tho90, Tor87] and predates Larson's work.
81 The \fIsdbm\fR programming interface is totally compatible
82 with \fIndbm\fP and includes a slight improvement in database initialization.
83 It is also expected to be binary-compatible under most UN*X versions that
84 support the \fIndbm\fP library.
86 The \fIsdbm\fP implementation shares the shortcomings of the \fIndbm\fP
87 library, as a side effect of various simplifications to the original Larson
88 algorithm. It does produce \fIholes\fP in the page file as it writes
89 pages past the end of file. (Larson's paper include a clever solution to
90 this problem that is a result of using the hash value directly as a block
91 address.) On the other hand, extensive tests seem to indicate that \fIsdbm\fP
92 creates fewer holes in general, and the resulting pagefiles are
93 smaller. The \fIsdbm\fP implementation is also faster than \fIndbm\fP
95 Unlike the \fIndbm\fP, the \fIsdbm\fP
97 operation will not ``wander away'' trying to split its
98 data pages to insert a datum that \fIcannot\fP (due to elaborate worst-case
99 situations) be inserted. (It will fail after a pre-defined number of attempts.)
101 Important Compatibility Warning
103 The \fIsdbm\fP and \fIndbm\fP
104 libraries \fIcannot\fP share databases: one cannot read the (dir/pag)
105 database created by the other. This is due to the differences
106 between the \fIndbm\fP and \fIsdbm\fP algorithms\**,
108 Torek's discussion [Tor87]
109 indicates that \fIdbm/ndbm\fP implementations use the hash
110 value to traverse the radix trie differently than \fIsdbm\fP
111 and as a result, the page indexes are generated in \fIdifferent\fP order.
112 For more information, send e-mail to the author.
114 and the hash functions
116 It is easy to convert between the \fIdbm/ndbm\fP databases and \fIsdbm\fP
117 by ignoring the index completely: see
124 Notice of Intellectual Property
126 \fIThe entire\fP sdbm \fIlibrary package, as authored by me,\fP Ozan S. Yigit,
127 \fIis hereby placed in the public domain.\fP As such, the author is not
128 responsible for the consequences of use of this software, no matter how
129 awful, even if they arise from defects in it. There is no expressed or
130 implied warranty for the \fIsdbm\fP library.
133 library package is in the public domain, this \fIoriginal\fP
134 release or any additional public-domain releases of the modified original
135 cannot possibly (by definition) be withheld from you. Also by definition,
136 You (singular) have all the rights to this code (including the right to
137 sell without permission, the right to hoard\**
139 You cannot really hoard something that is available to the public at
140 large, but try if it makes you feel any better.
142 and the right to do other icky things as
143 you see fit) but those rights are also granted to everyone else.
145 Please note that all previous distributions of this software contained
146 a copyright (which is now dropped) to protect its
147 origins and its current public domain status against any possible claims
152 Many people have been very helpful and supportive. A partial list would
153 necessarily include Rayan Zacherissen (who contributed the man page,
154 and also hacked a MMAP version of \fIsdbm\fP),
155 Arnold Robbins, Chris Lewis,
156 Bill Davidsen, Henry Spencer, Geoff Collyer, Rich Salz (who got me started
157 in the first place), Johannes Ruschein
158 (who did the minix port) and David Tilbrook. I thank you all.
160 Distribution Manifest and Notes
162 This distribution of \fIsdbm\fP includes (at least) the following:
166 biblio a small bibliography on external hashing
167 dba.c a crude (n/s)dbm page file analyzer
168 dbd.c a crude (n/s)dbm page file dumper (for conversion)
169 dbe.1 man page for dbe.c
170 dbe.c Janick's database editor
171 dbm.c a dbm library emulation wrapper for ndbm/sdbm
172 dbm.h header file for the above
173 dbu.c a crude db management utility
174 hash.c hashing function
176 pair.c page-level routines (posted earlier)
177 pair.h header file for the above
178 readme.ms troff source for the README file
180 sdbm.c the real thing
181 sdbm.h header file for the above
182 tune.h place for tuning & portability thingies
187 is a simple database manipulation program\** that tries to look
193 utilities are quick hacks and are not fit for production use. They were
194 developed late one night, just to test out \fIsdbm\fP, and convert some
199 utility. It is currently incomplete in functionality.
202 to test out the routines: it takes (from stdin) tab separated
203 key/value pairs for commands like
213 dbu <build|creat|look|insert|cat|delete> dbmfile
217 is a crude analyzer of \fIdbm/sdbm/ndbm\fP
218 page files. It scans the entire
219 page file, reporting page level statistics, and totals at the end.
222 is a crude dump program for \fIdbm/ndbm/sdbm\fP
223 databases. It ignores the
224 bitmap, and dumps the data pages in sequence. It can be used to create
230 will skip any NULLs in the key and data
231 fields, thus is unsuitable to convert some peculiar databases that
232 insist in including the terminating null.
234 I have also included a copy of the
236 (\fIndbm\fP DataBase Editor) by Janick Bergeron [janick@bnr.ca] for
237 your pleasure. You may find it more useful than the little
242 is a \fIdbm\fP library emulation on top of \fIndbm\fP
243 (and hence suitable for \fIsdbm\fP). Written by Robert Elz.
246 library has been around in beta test for quite a long time, and from whatever
247 little feedback I received (maybe no news is good news), I believe it has been
248 functioning without any significant problems. I would, of course, appreciate
249 all fixes and/or improvements. Portability enhancements would especially be
252 Implementation Issues
255 The algorithm behind \fIsdbm\fP implementation needs a good bit-scrambling
256 hash function to be effective. I ran into a set of constants for a simple
257 hash function that seem to help \fIsdbm\fP perform better than \fIndbm\fP
261 * polynomial conversion ignoring overflows
262 * 65599 nice. 65587 even better.
265 dbm_hash(char *str, int len) {
266 register unsigned long n = 0;
269 n = n * 65599 + *str++;
274 There may be better hash functions for the purposes of dynamic hashing.
275 Try your favorite, and check the pagefile. If it contains too many pages
276 with too many holes, (in relation to this one for example) or if
278 simply stops working (fails after
280 attempts to split) when you feed your
283 file to it, you probably do not have a good hashing function.
284 If you do better (for different types of input), I would like to know
285 about the function you use.
287 Block sizes: It seems (from various tests on a few machines) that a page
290 of 1024 is by far the best for performance, but
291 this also happens to limit the size of a key/value pair. Depending on your
292 needs, you may wish to increase the page size, and also adjust
294 (the maximum size of a key/value pair allowed: should always be at least
295 three words smaller than
297 accordingly. The system-wide version of the library
299 configured with 1024 (distribution default), as this appears to be sufficient
300 for most common uses of \fIsdbm\fP.
304 This package has been tested in many different UN*Xes even including minix,
305 and appears to be reasonably portable. This does not mean it will port
306 easily to non-UN*X systems.
308 Notes and Miscellaneous
310 The \fIsdbm\fP is not a very complicated package, at least not after you
311 familiarize yourself with the literature on external hashing. There are
312 other interesting algorithms in existence that ensure (approximately)
313 single-read access to a data value associated with any key. These are
314 directory-less schemes such as \fIlinear hashing\fP [Lit80] (+ Larson
315 variations), \fIspiral storage\fP [Mar79] or directory schemes such as
316 \fIextensible hashing\fP [Fag79] by Fagin et al. I do hope these sources
317 provide a reasonable playground for experimentation with other algorithms.
318 See the June 1988 issue of ACM Computing Surveys [Enb88] for an
319 excellent overview of the field.
326 ``Dynamic Hashing'', \fIBIT\fP, vol. 18, pp. 184-201, 1978.
328 Ken Thompson, \fIprivate communication\fP, Nov. 1990
331 `` Linear Hashing: A new tool for file and table addressing'',
332 \fIProceedings of the 6th Conference on Very Large Dabatases (Montreal)\fP,
333 pp. 212-223, Very Large Database Foundation, Saratoga, Calif., 1980.
335 R. Fagin, J. Nievergelt, N. Pippinger, and H. R. Strong,
336 ``Extendible Hashing - A Fast Access Method for Dynamic Files'',
337 \fIACM Trans. Database Syst.\fP, vol. 4, no.3, pp. 315-344, Sept. 1979.
340 ``Discussion of "dbm" data base system'', \fIUSENET newsgroup unix.wizards\fP,
344 ``Re: dbm.a and ndbm.a archives'', \fIUSENET newsgroup comp.unix\fP,
348 ``Spiral Storage: Incrementally Augmentable Hash Addressed Storage'',
349 \fITechnical Report #27\fP, University of Varwick, Coventry, U.K., 1979.
351 R. J. Enbody and H. C. Du,
352 ``Dynamic Hashing Schemes'',\fIACM Computing Surveys\fP,
353 vol. 20, no. 2, pp. 85-113, June 1988.