Ruby 2.0.0p353(2013-11-22revision43784)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

sdbm.h
Go to the documentation of this file.
1 /*
2 * sdbm - ndbm work-alike hashed database library
3 * based on Per-Ake Larson's Dynamic Hashing algorithms. BIT 18 (1978).
4 * author: oz@nexus.yorku.ca
5 * status: public domain.
6 */
7 #ifndef _SDBM_H_
8 #define _SDBM_H_
9
10 #include <stdio.h>
11
12 #define DBLKSIZ 4096
13 #define PBLKSIZ 1024
14 #define PAIRMAX 1008 /* arbitrary on PBLKSIZ-N */
15 #define SPLTMAX 10 /* maximum allowed splits */
16 /* for a single insertion */
17 #define DIRFEXT ".dir"
18 #define PAGFEXT ".pag"
19
20 typedef struct {
21 int dirf; /* directory file descriptor */
22 int pagf; /* page file descriptor */
23 int flags; /* status/error flags, see below */
24 int keyptr; /* current key for nextkey */
25 off_t maxbno; /* size of dirfile in bits */
26 long curbit; /* current bit number */
27 long hmask; /* current hash mask */
28 long blkptr; /* current block for nextkey */
29 long blkno; /* current page to read/write */
30 long pagbno; /* current page in pagbuf */
31 char pagbuf[PBLKSIZ]; /* page file block buffer */
32 long dirbno; /* current block in dirbuf */
33 char dirbuf[DBLKSIZ]; /* directory file block buffer */
34 } DBM;
35
36 #define DBM_RDONLY 0x1 /* data base open read-only */
37 #define DBM_IOERR 0x2 /* data base I/O error */
38
39 /*
40 * utility macros
41 */
42 #define sdbm_rdonly(db) ((db)->flags & DBM_RDONLY)
43 #define sdbm_error(db) ((db)->flags & DBM_IOERR)
44
45 #define sdbm_clearerr(db) ((db)->flags &= ~DBM_IOERR) /* ouch */
46
47 #define sdbm_dirfno(db) ((db)->dirf)
48 #define sdbm_pagfno(db) ((db)->pagf)
49
50 typedef struct {
51 char *dptr;
52 int dsize;
53 } datum;
54
55 extern datum nullitem;
56
57 #if defined(__STDC__)
58 #define proto(p) p
59 #else
60 #define proto(p) ()
61 #endif
62
63 /*
64 * flags to sdbm_store
65 */
66 #define DBM_INSERT 0
67 #define DBM_REPLACE 1
68
69 /*
70 * ndbm interface
71 */
72 extern DBM *sdbm_open proto((char *, int, int));
73 extern void sdbm_close proto((DBM *));
74 extern datum sdbm_fetch proto((DBM *, datum));
75 extern int sdbm_delete proto((DBM *, datum));
76 extern int sdbm_store proto((DBM *, datum, datum, int));
77 extern datum sdbm_firstkey proto((DBM *));
78 extern datum sdbm_nextkey proto((DBM *));
79
80 /*
81 * other
82 */
83 extern DBM *sdbm_prep proto((char *, char *, int, int));
84 extern long sdbm_hash proto((char *, int));
85
86 #endif /* _SDBM_H_ */
sdbm_hash
long sdbm_hash(register char *str, register int len)
Definition: _sdbm.c:927
DBM::flags
int flags
Definition: sdbm.h:23
DBM::hmask
long hmask
Definition: sdbm.h:27
DBM::blkno
long blkno
Definition: sdbm.h:29
DBM::pagf
int pagf
Definition: sdbm.h:22
datum::dptr
char * dptr
Definition: sdbm.h:51
DBM::blkptr
long blkptr
Definition: sdbm.h:28
DBM::curbit
long curbit
Definition: sdbm.h:26
nullitem
datum nullitem
Definition: _sdbm.c:146
sdbm_close
void sdbm_close(register DBM *db)
Definition: _sdbm.c:266
sdbm_open
DBM * sdbm_open(register char *file, register int flags, register int mode)
Definition: _sdbm.c:149
datum
Definition: sdbm.h:50
DBM::keyptr
int keyptr
Definition: sdbm.h:24
sdbm_firstkey
datum sdbm_firstkey(register DBM *db)
Definition: _sdbm.c:469
DBM::pagbno
long pagbno
Definition: sdbm.h:30
sdbm_prep
DBM * sdbm_prep(char *dirname, char *pagname, int flags, int mode)
Definition: _sdbm.c:201
off_t
#define off_t
Definition: io.c:65
DBM
Definition: sdbm.h:20
datum::dsize
int dsize
Definition: sdbm.h:52
DBLKSIZ
#define DBLKSIZ
Definition: sdbm.h:12
sdbm_store
int sdbm_store(register DBM *db, datum key, datum val, int flags)
Definition: _sdbm.c:314
proto
#define proto(p)
Definition: sdbm.h:60
DBM::dirf
int dirf
Definition: sdbm.h:21
sdbm_nextkey
datum sdbm_nextkey(register DBM *db)
Definition: _sdbm.c:488
PBLKSIZ
#define PBLKSIZ
Definition: sdbm.h:13
sdbm_delete
int sdbm_delete(register DBM *db, datum key)
Definition: _sdbm.c:290
sdbm_fetch
datum sdbm_fetch(register DBM *db, datum key)
Definition: _sdbm.c:278
DBM::maxbno
off_t maxbno
Definition: sdbm.h:25
DBM::dirbno
long dirbno
Definition: sdbm.h:32