home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / online / source / c / compilers / Tickle-4.0.sit.hqx / Tickle-4.0 / cbtree / src / db.h < prev    next >
Text File  |  1993-11-21  |  4KB  |  129 lines

  1. #ifndef _DB_H_
  2. #define    _DB_H_
  3.  
  4. #include "cdefs.h"
  5. #include "stddef.h"
  6.  
  7. //#ifdef macintosh
  8. //#    define cbMALLOC    malloc
  9. //#endif
  10.  
  11. /* flags for DB.put() call */
  12. #define    R_IBEFORE    1        /* RECNO */
  13. #define    R_IAFTER    2        /* RECNO */
  14. #define    R_NOOVERWRITE    3        /* BTREE, HASH, RECNO */
  15. #define    R_PUT        4        /* BTREE, HASH, RECNO */
  16.  
  17. /* flags for DB.seq() call */
  18. #define    R_CURSOR    1        /* BTREE, RECNO */
  19. #define    R_FIRST        2        /* BTREE, HASH, RECNO */
  20. #define    R_LAST        3        /* BTREE, RECNO */
  21. #define    R_NEXT        4        /* BTREE, HASH, RECNO */
  22. #define    R_PREV        5        /* BTREE, RECNO */
  23.  
  24. /* key/data structure -- a data-base thang */
  25. typedef struct {
  26.     void *data;
  27.     int size;
  28. } DBT;
  29.  
  30. /* access method description structure */
  31. typedef struct __db {
  32.     void *internal;        /* access method private */
  33. #define    DB_BTREE    1
  34. #define    DB_HASH        2
  35. #define    DB_RECNO    3
  36.     int type;        /* type of underlying db */
  37.     int (*close) __P((const struct __db *));
  38.     int (*del) __P((const struct __db *, const DBT *, unsigned int));
  39.     int (*get) __P((const struct __db *, DBT *, DBT *, unsigned int));
  40.     int (*put) __P((const struct __db *, const DBT *, const DBT *,
  41.         unsigned int));
  42.     int (*seq) __P((const struct __db *, DBT *, DBT *, unsigned int));
  43.     int (*sync) __P((const struct __db *));
  44. } DB;
  45.  
  46. #define    BTREEMAGIC    0x053162
  47. #define    BTREEVERSION    2
  48.  
  49. /* structure used to pass parameters to the btree routines */
  50. typedef struct {
  51. #define    R_DUP        0x01    /* duplicate keys */
  52.     u_long flags;
  53.     int cachesize;        /* bytes to cache */
  54.     int psize;        /* page size */
  55.     int (*compare)();    /* compare function */
  56.     int lorder;        /* byte order */
  57. } BTREEINFO;
  58.  
  59. #define    HASHMAGIC    0x061561
  60. #define    HASHVERSION    1
  61.  
  62. /* structure used to pass parameters to the hashing routines */
  63. typedef struct {
  64.     int bsize;        /* bucket size */
  65.     int ffactor;        /* fill factor */
  66.     int nelem;        /* number of elements */
  67.     int cachesize;        /* bytes to cache */
  68.     int (*hash)();        /* hash function */
  69.     int lorder;        /* byte order */
  70. } HASHINFO;
  71.  
  72. /* structure used to pass parameters to the record routines */
  73. typedef struct {
  74. #define    R_FIXEDLEN    0x01    /* fixed-length records */
  75.     u_long flags;
  76.     int cachesize;        /* bytes to cache */
  77.     size_t reclen;        /* record length (fixed-length records) */
  78.     u_char bval;        /* delimiting byte (variable-length records */
  79. } RECNOINFO;
  80.  
  81. /* key structure for the record routines */
  82. typedef struct {
  83.     u_long number;
  84.     u_long offset;
  85.     u_long length;
  86. #define    R_LENGTH    0x01    /* length is valid */
  87. #define    R_NUMBER    0x02    /* record number is valid */
  88. #define    R_OFFSET    0x04    /* offset is valid */
  89.     u_char valid;
  90. } RECNOKEY;
  91.  
  92. /* Little endian <--> big endian long swap macros. */
  93. #define BLSWAP(a) { \
  94.     u_long _tmp = a; \
  95.     ((char *)&a)[0] = ((char *)&_tmp)[3]; \
  96.     ((char *)&a)[1] = ((char *)&_tmp)[2]; \
  97.     ((char *)&a)[2] = ((char *)&_tmp)[1]; \
  98.     ((char *)&a)[3] = ((char *)&_tmp)[0]; \
  99. }
  100. #define    BLSWAP_COPY(a,b) { \
  101.     ((char *)&(b))[0] = ((char *)&(a))[3]; \
  102.     ((char *)&(b))[1] = ((char *)&(a))[2]; \
  103.     ((char *)&(b))[2] = ((char *)&(a))[1]; \
  104.     ((char *)&(b))[3] = ((char *)&(a))[0]; \
  105. }
  106.  
  107.  
  108. /* Little endian <--> big endian short swap macros. */
  109. #define BSSWAP(a) { \
  110.     u_short _tmp = a; \
  111.     ((char *)&a)[0] = ((char *)&_tmp)[1]; \
  112.     ((char *)&a)[1] = ((char *)&_tmp)[0]; \
  113. }
  114. #define BSSWAP_COPY(a,b) { \
  115.     ((char *)&(b))[0] = ((char *)&(a))[1]; \
  116.     ((char *)&(b))[1] = ((char *)&(a))[0]; \
  117. }
  118.  
  119. __BEGIN_DECLS
  120. DB    *btree_open
  121.         __P((const char *, int, int, const BTREEINFO *));
  122. DB    *hash_open
  123.         __P((const char *, int, int, const HASHINFO *));
  124. DB    *recno_open
  125.         __P((const char *, int, int, const RECNOINFO *));
  126. __END_DECLS
  127.  
  128. #endif /* !_DB_H_ */
  129.