Ruby 1.9.2p136(2010-12-25revision30365)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

# ext/sdbm/sdbm.h

Go to the documentation of this file.

    00001 /*
    00002  * sdbm - ndbm work-alike hashed database library
    00003  * based on Per-Ake Larson's Dynamic Hashing algorithms. BIT 18 (1978).
    00004  * author: oz@nexus.yorku.ca
    00005  * status: public domain.
    00006  */
    00007 #ifndef _SDBM_H_
    00008 #define _SDBM_H_
    00009
    00010 #include <stdio.h>
    00011
    00012 #define DBLKSIZ 4096
    00013 #define PBLKSIZ 1024
    00014 #define PAIRMAX 1008                    /* arbitrary on PBLKSIZ-N */
    00015 #define SPLTMAX 10                      /* maximum allowed splits */
    00016                                         /* for a single insertion */
    00017 #define DIRFEXT ".dir"
    00018 #define PAGFEXT ".pag"
    00019
    00020 typedef struct {
    00021         int dirf;                      /* directory file descriptor */
    00022         int pagf;                      /* page file descriptor */
    00023         int flags;                     /* status/error flags, see below */
    00024         int keyptr;                    /* current key for nextkey */
    00025         off_t maxbno;                  /* size of dirfile in bits */
    00026         long curbit;                   /* current bit number */
    00027         long hmask;                    /* current hash mask */
    00028         long blkptr;                   /* current block for nextkey */
    00029         long blkno;                    /* current page to read/write */
    00030         long pagbno;                   /* current page in pagbuf */
    00031         char pagbuf[PBLKSIZ];          /* page file block buffer */
    00032         long dirbno;                   /* current block in dirbuf */
    00033         char dirbuf[DBLKSIZ];          /* directory file block buffer */
    00034 } DBM;
    00035
    00036 #define DBM_RDONLY      0x1            /* data base open read-only */
    00037 #define DBM_IOERR       0x2            /* data base I/O error */
    00038
    00039 /*
    00040  * utility macros
    00041  */
    00042 #define sdbm_rdonly(db)         ((db)->flags & DBM_RDONLY)
    00043 #define sdbm_error(db)          ((db)->flags & DBM_IOERR)
    00044
    00045 #define sdbm_clearerr(db)       ((db)->flags &= ~DBM_IOERR)  /* ouch */
    00046
    00047 #define sdbm_dirfno(db) ((db)->dirf)
    00048 #define sdbm_pagfno(db) ((db)->pagf)
    00049
    00050 typedef struct {
    00051         char *dptr;
    00052         int dsize;
    00053 } datum;
    00054
    00055 extern datum nullitem;
    00056
    00057 #if defined(__STDC__)
    00058 #define proto(p) p
    00059 #else
    00060 #define proto(p) ()
    00061 #endif
    00062
    00063 /*
    00064  * flags to sdbm_store
    00065  */
    00066 #define DBM_INSERT      0
    00067 #define DBM_REPLACE     1
    00068
    00069 /*
    00070  * ndbm interface
    00071  */
    00072 extern DBM *sdbm_open proto((char *, int, int));
    00073 extern void sdbm_close proto((DBM *));
    00074 extern datum sdbm_fetch proto((DBM *, datum));
    00075 extern int sdbm_delete proto((DBM *, datum));
    00076 extern int sdbm_store proto((DBM *, datum, datum, int));
    00077 extern datum sdbm_firstkey proto((DBM *));
    00078 extern datum sdbm_nextkey proto((DBM *));
    00079
    00080 /*
    00081  * other
    00082  */
    00083 extern DBM *sdbm_prep proto((char *, char *, int, int));
    00084 extern long sdbm_hash proto((char *, int));
    00085
    00086 #endif  /* _SDBM_H_ */
    00087