ext/sdbm/sdbm.h


DEFINITIONS

This source file includes following functions.


   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  #define DBLKSIZ 4096
  11  #define PBLKSIZ 1024
  12  #define PAIRMAX 1008                    /* arbitrary on PBLKSIZ-N */
  13  #define SPLTMAX 10                      /* maximum allowed splits */
  14                                          /* for a single insertion */
  15  #define DIRFEXT ".dir"
  16  #define PAGFEXT ".pag"
  17  
  18  typedef struct {
  19          int dirf;                      /* directory file descriptor */
  20          int pagf;                      /* page file descriptor */
  21          int flags;                     /* status/error flags, see below */
  22          long maxbno;                   /* size of dirfile in bits */
  23          long curbit;                   /* current bit number */
  24          long hmask;                    /* current hash mask */
  25          long blkptr;                   /* current block for nextkey */
  26          int keyptr;                    /* current key for nextkey */
  27          long blkno;                    /* current page to read/write */
  28          long pagbno;                   /* current page in pagbuf */
  29          char pagbuf[PBLKSIZ];          /* page file block buffer */
  30          long dirbno;                   /* current block in dirbuf */
  31          char dirbuf[DBLKSIZ];          /* directory file block buffer */
  32  } DBM;
  33  
  34  #define DBM_RDONLY      0x1            /* data base open read-only */
  35  #define DBM_IOERR       0x2            /* data base I/O error */
  36  
  37  /*
  38   * utility macros
  39   */
  40  #define sdbm_rdonly(db)         ((db)->flags & DBM_RDONLY)
  41  #define sdbm_error(db)          ((db)->flags & DBM_IOERR)
  42  
  43  #define sdbm_clearerr(db)       ((db)->flags &= ~DBM_IOERR)  /* ouch */
  44  
  45  #define sdbm_dirfno(db) ((db)->dirf)
  46  #define sdbm_pagfno(db) ((db)->pagf)
  47  
  48  typedef struct {
  49          char *dptr;
  50          int dsize;
  51  } datum;
  52  
  53  extern datum nullitem;
  54  
  55  #if defined(__STDC__) || defined(MSDOS)
  56  #define proto(p) p
  57  #else
  58  #define proto(p) ()
  59  #endif
  60  
  61  /*
  62   * flags to sdbm_store
  63   */
  64  #define DBM_INSERT      0
  65  #define DBM_REPLACE     1
  66  
  67  /*
  68   * ndbm interface
  69   */
  70  extern DBM *sdbm_open proto((char *, int, int));
  71  extern void sdbm_close proto((DBM *));
  72  extern datum sdbm_fetch proto((DBM *, datum));
  73  extern int sdbm_delete proto((DBM *, datum));
  74  extern int sdbm_store proto((DBM *, datum, datum, int));
  75  extern datum sdbm_firstkey proto((DBM *));
  76  extern datum sdbm_nextkey proto((DBM *));
  77  
  78  /*
  79   * other
  80   */
  81  extern DBM *sdbm_prep proto((char *, char *, int, int));
  82  extern long sdbm_hash proto((char *, int));
  83  
  84  #endif  /* _SDBM_H_ */