Ruby  2.5.0dev(2017-10-22revision60238)
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_ */
long sdbm_hash(register char *str, register int len)
Definition: _sdbm.c:926
int flags
Definition: sdbm.h:23
long hmask
Definition: sdbm.h:27
long blkno
Definition: sdbm.h:29
int pagf
Definition: sdbm.h:22
char * dptr
Definition: sdbm.h:51
long blkptr
Definition: sdbm.h:28
long curbit
Definition: sdbm.h:26
void sdbm_close(register DBM *db)
Definition: _sdbm.c:265
DBM * sdbm_open(register char *file, register int flags, register int mode)
Definition: _sdbm.c:148
Definition: sdbm.h:50
int keyptr
Definition: sdbm.h:24
datum sdbm_firstkey(register DBM *db)
Definition: _sdbm.c:468
long pagbno
Definition: sdbm.h:30
DBM * sdbm_prep(char *dirname, char *pagname, int flags, int mode)
Definition: _sdbm.c:200
#define off_t
Definition: io.c:61
Definition: sdbm.h:20
int dsize
Definition: sdbm.h:52
datum nullitem
Definition: _sdbm.c:145
#define DBLKSIZ
Definition: sdbm.h:12
int sdbm_store(register DBM *db, datum key, datum val, int flags)
Definition: _sdbm.c:313
#define proto(p)
Definition: sdbm.h:60
int dirf
Definition: sdbm.h:21
datum sdbm_nextkey(register DBM *db)
Definition: _sdbm.c:487
#define PBLKSIZ
Definition: sdbm.h:13
int sdbm_delete(register DBM *db, datum key)
Definition: _sdbm.c:289
datum sdbm_fetch(register DBM *db, datum key)
Definition: _sdbm.c:277
off_t maxbno
Definition: sdbm.h:25
long dirbno
Definition: sdbm.h:32