Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Enumerations | Functions | Variables
hash.h File Reference
#include <stdio.h>
#include "mcom_db.h"
#include "page.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _bufhead
struct  hashhdr
struct  htab

Defines

#define BUF_MOD   0x0001
#define BUF_DISK   0x0002
#define BUF_BUCKET   0x0004
#define BUF_PIN   0x0008
#define IS_BUCKET(X)   ((X) & BUF_BUCKET)
#define NO_FILE   -1
#define DBFILE_OPEN(path, flag, mode)   open((path), (flag), (mode))
#define NCACHED
#define DATABASE_CORRUPTED_ERROR   -999 /* big ugly abort, delete database */
#define OLD_MAX_BSIZE   65536 /* 2^16 */
#define MAX_BSIZE   32l*1024l /* 2^15 */
#define MIN_BUFFERS   6
#define MINHDRSIZE   512
#define DEF_BUFSIZE   65536l /* 64 K */
#define DEF_BUCKET_SIZE   4096
#define DEF_BUCKET_SHIFT   12 /* log2(BUCKET) */
#define DEF_SEGSIZE   256
#define DEF_SEGSIZE_SHIFT   8 /* log2(SEGSIZE) */
#define DEF_DIRSIZE   256
#define DEF_FFACTOR   65536l
#define MIN_FFACTOR   4
#define SPLTMAX   8
#define CHARKEY   "%$sniglet^&"
#define NUMKEY   1038583l
#define BYTE_SHIFT   3
#define INT_TO_BYTE   2
#define INT_BYTE_SHIFT   5
#define ALL_SET   ((uint32)0xFFFFFFFF)
#define ALL_CLEAR   0
#define PTROF(X)   ((ptrdiff_t)(X) == BUF_DISK ? 0 : (X))
#define ISDISK(X)
#define BITS_PER_MAP   32
#define CLRBIT(A, N)   ((A)[(N)/BITS_PER_MAP] &= ~(1<<((N)%BITS_PER_MAP)))
#define SETBIT(A, N)   ((A)[(N)/BITS_PER_MAP] |= (1<<((N)%BITS_PER_MAP)))
#define ISSET(A, N)   ((A)[(N)/BITS_PER_MAP] & (1<<((N)%BITS_PER_MAP)))
#define SPLITSHIFT   11
#define SPLITMASK   0x7FF
#define SPLITNUM(N)   (((uint32)(N)) >> SPLITSHIFT)
#define OPAGENUM(N)   ((N) & SPLITMASK)
#define OADDR_OF(S, O)   ((uint32)((uint32)(S) << SPLITSHIFT) + (O))
#define BUCKET_TO_PAGE(B)   (B) + hashp->HDRPAGES + ((B) ? hashp->SPARES[__log2((uint32)((B)+1))-1] : 0)
#define OADDR_TO_PAGE(B)   BUCKET_TO_PAGE ( (1 << SPLITNUM((B))) -1 ) + OPAGENUM((B));
#define OVFLPAGE   0
#define PARTIAL_KEY   1
#define FULL_KEY   2
#define FULL_KEY_DATA   3
#define REAL_KEY   4
#define BSIZE   hdr.bsize
#define BSHIFT   hdr.bshift
#define DSIZE   hdr.dsize
#define SGSIZE   hdr.ssize
#define SSHIFT   hdr.sshift
#define LORDER   hdr.lorder
#define OVFL_POINT   hdr.ovfl_point
#define LAST_FREED   hdr.last_freed
#define MAX_BUCKET   hdr.max_bucket
#define FFACTOR   hdr.ffactor
#define HIGH_MASK   hdr.high_mask
#define LOW_MASK   hdr.low_mask
#define NKEYS   hdr.nkeys
#define HDRPAGES   hdr.hdrpages
#define SPARES   hdr.spares
#define BITMAPS   hdr.bitmaps
#define VERSION   hdr.version
#define MAGIC   hdr.magic
#define NEXT_FREE   hdr.next_free
#define H_CHARKEY   hdr.h_charkey

Typedefs

typedef struct _bufhead
typedef BUFHEAD ** SEGMENT
typedef int DBFILE_PTR
typedef struct hashhdr HASHHDR
typedef struct htab HTAB

Enumerations

enum  ACTION {
  HASH_GET, HASH_PUT, HASH_PUTNEW, HASH_DELETE,
  HASH_FIRST, HASH_NEXT, FIND, ENTER,
  FIND, ENTER
}

Functions

void __buf_init (HTAB *hashp, int32 nbytes)
int __big_delete (HTAB *hashp, BUFHEAD *bufp)
BUFHEAD * __get_buf (HTAB *hashp, uint32 addr, BUFHEAD *prev_bp, int newpage)
uint32 __call_hash (HTAB *hashp, char *k, size_t len)
int __big_split (HTAB *hashp, BUFHEAD *op, BUFHEAD *np, BUFHEAD *big_keyp, uint32 addr, uint32 obucket, SPLIT_RETURN *ret)
void __free_ovflpage (HTAB *hashp, BUFHEAD *obufp)
BUFHEAD * __add_ovflpage (HTAB *hashp, BUFHEAD *bufp)
int __big_insert (HTAB *hashp, BUFHEAD *bufp, const DBT *key, const DBT *val)
int __expand_table (HTAB *hashp)
uint32 __log2 (uint32 num)
void __reclaim_buf (HTAB *hashp, BUFHEAD *bp)
int __get_page (HTAB *hashp, char *p, uint32 bucket, int is_bucket, int is_disk, int is_bitmap)
int __put_page (HTAB *hashp, char *p, uint32 bucket, int is_bucket, int is_bitmap)
int __ibitmap (HTAB *hashp, int pnum, int nbits, int ndx)
int __buf_free (HTAB *hashp, int do_free, int to_disk)
int __find_bigpair (HTAB *hashp, BUFHEAD *bufp, int ndx, char *key, int size)
uint16 __find_last_page (HTAB *hashp, BUFHEAD **bpp)
int __addel (HTAB *hashp, BUFHEAD *bufp, const DBT *key, const DBT *val)
int __big_return (HTAB *hashp, BUFHEAD *bufp, int ndx, DBT *val, int set_current)
int __delpair (HTAB *hashp, BUFHEAD *bufp, int ndx)
int __big_keydata (HTAB *hashp, BUFHEAD *bufp, DBT *key, DBT *val, int set)
int __split_page (HTAB *hashp, uint32 obucket, uint32 nbucket)

Variables

uint32(* __default_hash )(const void *, size_t)

Class Documentation

struct _bufhead

Definition at line 48 of file hash.h.

Class Members
uint32 addr
char flags
char is_disk
BUFHEAD * next
BUFHEAD * ovfl
char * page
BUFHEAD * prev
struct hashhdr

Definition at line 75 of file hash.h.

Class Members
uint16 bitmaps
int32 bshift
int32 bsize
int32 dsize
int32 ffactor
uint32 h_charkey
int32 hdrpages
int32 high_mask
int32 last_freed
uint32 lorder
int32 low_mask
int32 magic
int32 max_bucket
int32 nkeys
int32 ovfl_point
int32 spares
int32 sshift
int32 ssize
int32 version

Define Documentation

#define ALL_CLEAR   0

Definition at line 157 of file hash.h.

#define ALL_SET   ((uint32)0xFFFFFFFF)

Definition at line 156 of file hash.h.

#define BITMAPS   hdr.bitmaps

Definition at line 304 of file hash.h.

#define BITS_PER_MAP   32

Definition at line 163 of file hash.h.

#define BSHIFT   hdr.bshift

Definition at line 290 of file hash.h.

#define BSIZE   hdr.bsize

Definition at line 288 of file hash.h.

#define BUCKET_TO_PAGE (   B)    (B) + hashp->HDRPAGES + ((B) ? hashp->SPARES[__log2((uint32)((B)+1))-1] : 0)

Definition at line 185 of file hash.h.

#define BUF_BUCKET   0x0004

Definition at line 58 of file hash.h.

#define BUF_DISK   0x0002

Definition at line 57 of file hash.h.

#define BUF_MOD   0x0001

Definition at line 56 of file hash.h.

#define BUF_PIN   0x0008

Definition at line 59 of file hash.h.

#define BYTE_SHIFT   3

Definition at line 153 of file hash.h.

#define CHARKEY   "%$sniglet^&"

Definition at line 151 of file hash.h.

#define CLRBIT (   A,
  N 
)    ((A)[(N)/BITS_PER_MAP] &= ~(1<<((N)%BITS_PER_MAP)))

Definition at line 166 of file hash.h.

#define DATABASE_CORRUPTED_ERROR   -999 /* big ugly abort, delete database */

Definition at line 137 of file hash.h.

#define DBFILE_OPEN (   path,
  flag,
  mode 
)    open((path), (flag), (mode))

Definition at line 72 of file hash.h.

#define DEF_BUCKET_SHIFT   12 /* log2(BUCKET) */

Definition at line 144 of file hash.h.

#define DEF_BUCKET_SIZE   4096

Definition at line 143 of file hash.h.

#define DEF_BUFSIZE   65536l /* 64 K */

Definition at line 142 of file hash.h.

#define DEF_DIRSIZE   256

Definition at line 147 of file hash.h.

#define DEF_FFACTOR   65536l

Definition at line 148 of file hash.h.

#define DEF_SEGSIZE   256

Definition at line 145 of file hash.h.

#define DEF_SEGSIZE_SHIFT   8 /* log2(SEGSIZE) */

Definition at line 146 of file hash.h.

#define DSIZE   hdr.dsize

Definition at line 291 of file hash.h.

#define FFACTOR   hdr.ffactor

Definition at line 298 of file hash.h.

#define FULL_KEY   2

Definition at line 282 of file hash.h.

Definition at line 283 of file hash.h.

#define H_CHARKEY   hdr.h_charkey

Definition at line 308 of file hash.h.

#define HDRPAGES   hdr.hdrpages

Definition at line 302 of file hash.h.

#define HIGH_MASK   hdr.high_mask

Definition at line 299 of file hash.h.

Definition at line 155 of file hash.h.

Definition at line 154 of file hash.h.

#define IS_BUCKET (   X)    ((X) & BUF_BUCKET)

Definition at line 62 of file hash.h.

#define ISDISK (   X)
Value:
((X) ? ((ptrdiff_t)(X) == BUF_DISK ? BUF_DISK \
                            : (X)->is_disk) : 0)

Definition at line 160 of file hash.h.

#define ISSET (   A,
  N 
)    ((A)[(N)/BITS_PER_MAP] & (1<<((N)%BITS_PER_MAP)))

Definition at line 168 of file hash.h.

#define LAST_FREED   hdr.last_freed

Definition at line 296 of file hash.h.

#define LORDER   hdr.lorder

Definition at line 294 of file hash.h.

#define LOW_MASK   hdr.low_mask

Definition at line 300 of file hash.h.

Definition at line 306 of file hash.h.

#define MAX_BSIZE   32l*1024l /* 2^15 */

Definition at line 139 of file hash.h.

#define MAX_BUCKET   hdr.max_bucket

Definition at line 297 of file hash.h.

Definition at line 140 of file hash.h.

Definition at line 149 of file hash.h.

#define MINHDRSIZE   512

Definition at line 141 of file hash.h.

Value:
32                   /* number of bit maps and spare 
                                    * points */

Definition at line 95 of file hash.h.

#define NEXT_FREE   hdr.next_free

Definition at line 307 of file hash.h.

#define NKEYS   hdr.nkeys

Definition at line 301 of file hash.h.

#define NO_FILE   -1

Definition at line 67 of file hash.h.

#define NUMKEY   1038583l

Definition at line 152 of file hash.h.

#define OADDR_OF (   S,
  O 
)    ((uint32)((uint32)(S) << SPLITSHIFT) + (O))

Definition at line 183 of file hash.h.

#define OADDR_TO_PAGE (   B)    BUCKET_TO_PAGE ( (1 << SPLITNUM((B))) -1 ) + OPAGENUM((B));

Definition at line 187 of file hash.h.

#define OLD_MAX_BSIZE   65536 /* 2^16 */

Definition at line 138 of file hash.h.

#define OPAGENUM (   N)    ((N) & SPLITMASK)

Definition at line 182 of file hash.h.

#define OVFL_POINT   hdr.ovfl_point

Definition at line 295 of file hash.h.

#define OVFLPAGE   0

Definition at line 280 of file hash.h.

Definition at line 281 of file hash.h.

#define PTROF (   X)    ((ptrdiff_t)(X) == BUF_DISK ? 0 : (X))

Definition at line 159 of file hash.h.

#define REAL_KEY   4

Definition at line 284 of file hash.h.

#define SETBIT (   A,
  N 
)    ((A)[(N)/BITS_PER_MAP] |= (1<<((N)%BITS_PER_MAP)))

Definition at line 167 of file hash.h.

#define SGSIZE   hdr.ssize

Definition at line 292 of file hash.h.

#define SPARES   hdr.spares

Definition at line 303 of file hash.h.

#define SPLITMASK   0x7FF

Definition at line 180 of file hash.h.

#define SPLITNUM (   N)    (((uint32)(N)) >> SPLITSHIFT)

Definition at line 181 of file hash.h.

#define SPLITSHIFT   11

Definition at line 179 of file hash.h.

#define SPLTMAX   8

Definition at line 150 of file hash.h.

#define SSHIFT   hdr.sshift

Definition at line 293 of file hash.h.

Definition at line 305 of file hash.h.


Typedef Documentation

typedef struct _bufhead

Definition at line 46 of file hash.h.

typedef int DBFILE_PTR

Definition at line 66 of file hash.h.

typedef struct hashhdr HASHHDR
typedef struct htab HTAB
typedef BUFHEAD** SEGMENT

Definition at line 64 of file hash.h.


Enumeration Type Documentation

enum ACTION
Enumerator:
HASH_GET 
HASH_PUT 
HASH_PUTNEW 
HASH_DELETE 
HASH_FIRST 
HASH_NEXT 
FIND 
ENTER 
FIND 
ENTER 

Definition at line 41 of file hash.h.


Function Documentation

BUFHEAD* __add_ovflpage ( HTAB hashp,
BUFHEAD *  bufp 
)

Definition at line 635 of file h_page.c.

{
       register uint16 *sp;
       uint16 ndx, ovfl_num;
#ifdef DEBUG1
       int tmp1, tmp2;
#endif
       sp = (uint16 *)bufp->page;

       /* Check if we are dynamically determining the fill factor */
       if (hashp->FFACTOR == DEF_FFACTOR) {
              hashp->FFACTOR = sp[0] >> 1;
              if (hashp->FFACTOR < MIN_FFACTOR)
                     hashp->FFACTOR = MIN_FFACTOR;
       }
       bufp->flags |= BUF_MOD;
       ovfl_num = overflow_page(hashp);
#ifdef DEBUG1
       tmp1 = bufp->addr;
       tmp2 = bufp->ovfl ? bufp->ovfl->addr : 0;
#endif
       if (!ovfl_num || !(bufp->ovfl = __get_buf(hashp, ovfl_num, bufp, 1)))
              return (NULL);
       bufp->ovfl->flags |= BUF_MOD;
#ifdef DEBUG1
       (void)fprintf(stderr, "ADDOVFLPAGE: %d->ovfl was %d is now %d\n",
           tmp1, tmp2, bufp->ovfl->addr);
#endif
       ndx = sp[0];
       /*
        * Since a pair is allocated on a page only if there's room to add
        * an overflow page, we know that the OVFL information will fit on
        * the page.
        */
       sp[ndx + 4] = OFFSET(sp);
       sp[ndx + 3] = FREESPACE(sp) - OVFLSIZE;
       sp[ndx + 1] = ovfl_num;
       sp[ndx + 2] = OVFLPAGE;
       sp[0] = ndx + 2;
#ifdef HASH_STATISTICS
       hash_overflows++;
#endif
       return (bufp->ovfl);
}

Here is the call graph for this function:

int __addel ( HTAB hashp,
BUFHEAD *  bufp,
const DBT key,
const DBT val 
)

Definition at line 542 of file h_page.c.

{
       register uint16 *bp, *sop;
       int do_expand;

       bp = (uint16 *)bufp->page;
       do_expand = 0;
       while (bp[0] && (bp[2] < REAL_KEY || bp[bp[0]] < REAL_KEY))
              /* Exception case */
              if (bp[2] == FULL_KEY_DATA && bp[0] == 2)
                     /* This is the last page of a big key/data pair
                        and we need to add another page */
                     break;
              else if (bp[2] < REAL_KEY && bp[bp[0]] != OVFLPAGE) {
                     bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
                     if (!bufp)
                       {
#ifdef DEBUG
                            assert(0);
#endif
                            return (-1);
                       }
                     bp = (uint16 *)bufp->page;
              } else
                     /* Try to squeeze key on this page */
                     if (FREESPACE(bp) > PAIRSIZE(key, val)) {
                       {
                            squeeze_key(bp, key, val);

                            /* LJM: I added this because I think it was
                             * left out on accident.
                             * if this isn't incremented nkeys will not
                             * be the actual number of keys in the db.
                             */
                            hashp->NKEYS++;
                            return (0);
                       }
                     } else {
                            bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
                            if (!bufp)
                           {
#ifdef DEBUG
                                assert(0);
#endif
                                   return (-1);
                              }
                            bp = (uint16 *)bufp->page;
                     }

       if (PAIRFITS(bp, key, val))
              putpair(bufp->page, key, (DBT *)val);
       else {
              do_expand = 1;
              bufp = __add_ovflpage(hashp, bufp);
              if (!bufp)
             {
#ifdef DEBUG
                  assert(0);
#endif
                     return (-1);
                }
              sop = (uint16 *)bufp->page;

              if (PAIRFITS(sop, key, val))
                     putpair((char *)sop, key, (DBT *)val);
              else
                     if (__big_insert(hashp, bufp, key, val))
                 {
#ifdef DEBUG
                      assert(0);
#endif
                         return (-1);
                    }
       }
       bufp->flags |= BUF_MOD;
       /*
        * If the average number of keys per bucket exceeds the fill factor,
        * expand the table.
        */
       hashp->NKEYS++;
       if (do_expand ||
           (hashp->NKEYS / (hashp->MAX_BUCKET + 1) > hashp->FFACTOR))
              return (__expand_table(hashp));
       return (0);
}

Here is the call graph for this function:

int __big_delete ( HTAB hashp,
BUFHEAD *  bufp 
)

Definition at line 187 of file h_bigkey.c.

{
       register BUFHEAD *last_bfp, *rbufp;
       uint16 *bp, pageno;
       int key_done, n;

       rbufp = bufp;
       last_bfp = NULL;
       bp = (uint16 *)bufp->page;
       pageno = 0;
       key_done = 0;

       while (!key_done || (bp[2] != FULL_KEY_DATA)) {
              if (bp[2] == FULL_KEY || bp[2] == FULL_KEY_DATA)
                     key_done = 1;

              /*
               * If there is freespace left on a FULL_KEY_DATA page, then
               * the data is short and fits entirely on this page, and this
               * is the last page.
               */
              if (bp[2] == FULL_KEY_DATA && FREESPACE(bp))
                     break;
              pageno = bp[bp[0] - 1];
              rbufp->flags |= BUF_MOD;
              rbufp = __get_buf(hashp, pageno, rbufp, 0);
              if (last_bfp)
                     __free_ovflpage(hashp, last_bfp);
              last_bfp = rbufp;
              if (!rbufp)
                     return (-1);         /* Error. */
              bp = (uint16 *)rbufp->page;
       }

       /*
        * If we get here then rbufp points to the last page of the big
        * key/data pair.  Bufp points to the first one -- it should now be
        * empty pointing to the next page after this pair.  Can't free it
        * because we don't have the page pointing to it.
        */

       /* This is information from the last page of the pair. */
       n = bp[0];
       pageno = bp[n - 1];

       /* Now, bp is the first page of the pair. */
       bp = (uint16 *)bufp->page;
       if (n > 2) {
              /* There is an overflow page. */
              bp[1] = pageno;
              bp[2] = OVFLPAGE;
              bufp->ovfl = rbufp->ovfl;
       } else
              /* This is the last page. */
              bufp->ovfl = NULL;
       n -= 2;
       bp[0] = n;
       FREESPACE(bp) = hashp->BSIZE - PAGE_META(n);
       OFFSET(bp) = hashp->BSIZE - 1;

       bufp->flags |= BUF_MOD;
       if (rbufp)
              __free_ovflpage(hashp, rbufp);
       if (last_bfp != rbufp)
              __free_ovflpage(hashp, last_bfp);

       hashp->NKEYS--;
       return (0);
}

Here is the call graph for this function:

int __big_insert ( HTAB hashp,
BUFHEAD *  bufp,
const DBT key,
const DBT val 
)

Definition at line 90 of file h_bigkey.c.

{
       register uint16 *p;
       uint key_size, n, val_size;
       uint16 space, move_bytes, off;
       char *cp, *key_data, *val_data;

       cp = bufp->page;            /* Character pointer of p. */
       p = (uint16 *)cp;

       key_data = (char *)key->data;
       key_size = key->size;
       val_data = (char *)val->data;
       val_size = val->size;

       /* First move the Key */
       for (space = FREESPACE(p) - BIGOVERHEAD; key_size;
           space = FREESPACE(p) - BIGOVERHEAD) {
              move_bytes = PR_MIN(space, key_size);
              off = OFFSET(p) - move_bytes;
              memmove(cp + off, key_data, move_bytes);
              key_size -= move_bytes;
              key_data += move_bytes;
              n = p[0];
              p[++n] = off;
              p[0] = ++n;
              FREESPACE(p) = off - PAGE_META(n);
              OFFSET(p) = off;
              p[n] = PARTIAL_KEY;
              bufp = __add_ovflpage(hashp, bufp);
              if (!bufp)
                     return (-1);
              n = p[0];
              if (!key_size) {
                     if (FREESPACE(p)) {
                            move_bytes = PR_MIN(FREESPACE(p), val_size);
                            off = OFFSET(p) - move_bytes;
                            p[n] = off;
                            memmove(cp + off, val_data, move_bytes);
                            val_data += move_bytes;
                            val_size -= move_bytes;
                            p[n - 2] = FULL_KEY_DATA;
                            FREESPACE(p) = FREESPACE(p) - move_bytes;
                            OFFSET(p) = off;
                     } else
                            p[n - 2] = FULL_KEY;
              }
              p = (uint16 *)bufp->page;
              cp = bufp->page;
              bufp->flags |= BUF_MOD;
       }

       /* Now move the data */
       for (space = FREESPACE(p) - BIGOVERHEAD; val_size;
           space = FREESPACE(p) - BIGOVERHEAD) {
              move_bytes = PR_MIN(space, val_size);
              /*
               * Here's the hack to make sure that if the data ends on the
               * same page as the key ends, FREESPACE is at least one.
               */
              if (space == val_size && val_size == val->size)
                     move_bytes--;
              off = OFFSET(p) - move_bytes;
              memmove(cp + off, val_data, move_bytes);
              val_size -= move_bytes;
              val_data += move_bytes;
              n = p[0];
              p[++n] = off;
              p[0] = ++n;
              FREESPACE(p) = off - PAGE_META(n);
              OFFSET(p) = off;
              if (val_size) {
                     p[n] = FULL_KEY;
                     bufp = __add_ovflpage(hashp, bufp);
                     if (!bufp)
                            return (-1);
                     cp = bufp->page;
                     p = (uint16 *)cp;
              } else
                     p[n] = FULL_KEY_DATA;
              bufp->flags |= BUF_MOD;
       }
       return (0);
}

Here is the call graph for this function:

int __big_keydata ( HTAB hashp,
BUFHEAD *  bufp,
DBT key,
DBT val,
int  set 
)

Definition at line 545 of file h_bigkey.c.

{
       key->size = collect_key(hashp, bufp, 0, val, set);
       if (key->size == (size_t)-1)
              return (-1);
       key->data = (uint8 *)hashp->tmp_key;
       return (0);
}

Here is the call graph for this function:

int __big_return ( HTAB hashp,
BUFHEAD *  bufp,
int  ndx,
DBT val,
int  set_current 
)

Definition at line 355 of file h_bigkey.c.

{
       BUFHEAD *save_p;
       uint16 *bp, len, off, save_addr;
       char *tp;
       int save_flags;

       bp = (uint16 *)bufp->page;
       while (bp[ndx + 1] == PARTIAL_KEY) {
              bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
              if (!bufp)
                     return (-1);
              bp = (uint16 *)bufp->page;
              ndx = 1;
       }

       if (bp[ndx + 1] == FULL_KEY) {
              bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
              if (!bufp)
                     return (-1);
              bp = (uint16 *)bufp->page;
              save_p = bufp;
              save_addr = save_p->addr;
              off = bp[1];
              len = 0;
       } else
              if (!FREESPACE(bp)) {
                     /*
                      * This is a hack.  We can't distinguish between
                      * FULL_KEY_DATA that contains complete data or
                      * incomplete data, so we require that if the data
                      * is complete, there is at least 1 byte of free
                      * space left.
                      */
                     off = bp[bp[0]];
                     len = bp[1] - off;
                     save_p = bufp;
                     save_addr = bufp->addr;
                     bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
                     if (!bufp)
                            return (-1);
                     bp = (uint16 *)bufp->page;
              } else {
                     /* The data is all on one page. */
                     tp = (char *)bp;
                     off = bp[bp[0]];
                     val->data = (uint8 *)tp + off;
                     val->size = bp[1] - off;
                     if (set_current) {
                            if (bp[0] == 2) {    /* No more buckets in
                                                  * chain */
                                   hashp->cpage = NULL;
                                   hashp->cbucket++;
                                   hashp->cndx = 1;
                            } else {
                                   hashp->cpage = __get_buf(hashp,
                                       bp[bp[0] - 1], bufp, 0);
                                   if (!hashp->cpage)
                                          return (-1);
                                   hashp->cndx = 1;
                                   if (!((uint16 *)
                                       hashp->cpage->page)[0]) {
                                          hashp->cbucket++;
                                          hashp->cpage = NULL;
                                   }
                            }
                     }
                     return (0);
              }

       /* pin our saved buf so that we don't lose if 
        * we run out of buffers */
       save_flags = save_p->flags;
       save_p->flags |= BUF_PIN;
       val->size = collect_data(hashp, bufp, (int)len, set_current);
       save_p->flags = save_flags;
       if (val->size == (size_t)-1)
              return (-1);
       if (save_p->addr != save_addr) {
              /* We are pretty short on buffers. */
              errno = EINVAL;                    /* OUT OF BUFFERS */
              return (-1);
       }
       memmove(hashp->tmp_buf, (save_p->page) + off, len);
       val->data = (uint8 *)hashp->tmp_buf;
       return (0);
}

Here is the call graph for this function:

int __big_split ( HTAB hashp,
BUFHEAD *  op,
BUFHEAD *  np,
BUFHEAD *  big_keyp,
uint32  addr,
uint32  obucket,
SPLIT_RETURN ret 
)

Definition at line 608 of file h_bigkey.c.

{
       register BUFHEAD *tmpp;
       register uint16 *tp;
       BUFHEAD *bp;
       DBT key, val;
       uint32 change;
       uint16 free_space, n, off;

       bp = big_keyp;

       /* Now figure out where the big key/data goes */
       if (__big_keydata(hashp, big_keyp, &key, &val, 0))
              return (-1);
       change = (__call_hash(hashp,(char*) key.data, key.size) != obucket);

       if ((ret->next_addr = __find_last_page(hashp, &big_keyp))) {
              if (!(ret->nextp =
                  __get_buf(hashp, ret->next_addr, big_keyp, 0)))
                     return (-1);;
       } else
              ret->nextp = NULL;

       /* Now make one of np/op point to the big key/data pair */
#ifdef DEBUG
       assert(np->ovfl == NULL);
#endif
       if (change)
              tmpp = np;
       else
              tmpp = op;

       tmpp->flags |= BUF_MOD;
#ifdef DEBUG1
       (void)fprintf(stderr,
           "BIG_SPLIT: %d->ovfl was %d is now %d\n", tmpp->addr,
           (tmpp->ovfl ? tmpp->ovfl->addr : 0), (bp ? bp->addr : 0));
#endif
       tmpp->ovfl = bp;     /* one of op/np point to big_keyp */
       tp = (uint16 *)tmpp->page;


#if 0  /* this get's tripped on database corrupted error */
       assert(FREESPACE(tp) >= OVFLSIZE);
#endif
       if(FREESPACE(tp) < OVFLSIZE)
              return(DATABASE_CORRUPTED_ERROR);

       n = tp[0];
       off = OFFSET(tp);
       free_space = FREESPACE(tp);
       tp[++n] = (uint16)addr;
       tp[++n] = OVFLPAGE;
       tp[0] = n;
       OFFSET(tp) = off;
       FREESPACE(tp) = free_space - OVFLSIZE;

       /*
        * Finally, set the new and old return values. BIG_KEYP contains a
        * pointer to the last page of the big key_data pair. Make sure that
        * big_keyp has no following page (2 elements) or create an empty
        * following page.
        */

       ret->newp = np;
       ret->oldp = op;

       tp = (uint16 *)big_keyp->page;
       big_keyp->flags |= BUF_MOD;
       if (tp[0] > 2) {
              /*
               * There may be either one or two offsets on this page.  If
               * there is one, then the overflow page is linked on normally
               * and tp[4] is OVFLPAGE.  If there are two, tp[4] contains
               * the second offset and needs to get stuffed in after the
               * next overflow page is added.
               */
              n = tp[4];
              free_space = FREESPACE(tp);
              off = OFFSET(tp);
              tp[0] -= 2;
              FREESPACE(tp) = free_space + OVFLSIZE;
              OFFSET(tp) = off;
              tmpp = __add_ovflpage(hashp, big_keyp);
              if (!tmpp)
                     return (-1);
              tp[4] = n;
       } else
              tmpp = big_keyp;

       if (change)
              ret->newp = tmpp;
       else
              ret->oldp = tmpp;
       return (0);
}

Here is the call graph for this function:

int __buf_free ( HTAB hashp,
int  do_free,
int  to_disk 
)

Definition at line 366 of file hash_buf.c.

{
       BUFHEAD *bp;
       int status = -1;

       /* Need to make sure that buffer manager has been initialized */
       if (!LRU)
              return (0);
       for (bp = LRU; bp != &hashp->bufhead;) {
              /* Check that the buffer is valid */
              if (bp->addr || IS_BUCKET(bp->flags)) {
                     if (to_disk && (bp->flags & BUF_MOD) &&
                         (status = __put_page(hashp, bp->page,
                         bp->addr, IS_BUCKET(bp->flags), 0))) {
                       
                            if (do_free) {
                                   if (bp->page)
                                          free(bp->page);
                                   BUF_REMOVE(bp);
                                   free(bp);
                            }
                            
                            return (status);
                     }
              }
              /* Check if we are freeing stuff */
              if (do_free) {
                     if (bp->page)
                            free(bp->page);
                     BUF_REMOVE(bp);
                     free(bp);
                     bp = LRU;
              } else
                     bp = bp->prev;
       }
       return (0);
}

Here is the call graph for this function:

void __buf_init ( HTAB hashp,
int32  nbytes 
)

Definition at line 343 of file hash_buf.c.

{
       BUFHEAD *bfp;
       int npages;

       bfp = &(hashp->bufhead);
       npages = (nbytes + hashp->BSIZE - 1) >> hashp->BSHIFT;
       npages = PR_MAX(npages, MIN_BUFFERS);

       hashp->nbufs = npages;
       bfp->next = bfp;
       bfp->prev = bfp;
       /*
        * This space is calloc'd so these are already null.
        *
        * bfp->ovfl = NULL;
        * bfp->flags = 0;
        * bfp->page = NULL;
        * bfp->addr = 0;
        */
}
uint32 __call_hash ( HTAB hashp,
char *  k,
size_t  len 
)

Definition at line 1074 of file hash.c.

{
       uint32 n, bucket;

       n = hashp->hash(k, len);
       bucket = n & hashp->HIGH_MASK;
       if (bucket > (uint32)hashp->MAX_BUCKET)
              bucket = bucket & hashp->LOW_MASK;
       return (bucket);
}
int __delpair ( HTAB hashp,
BUFHEAD *  bufp,
int  ndx 
)

Definition at line 211 of file h_page.c.

{
       register uint16 *bp, newoff;
       register int n;
       uint16 pairlen;

       bp = (uint16 *)bufp->page;
       n = bp[0];

       if (bp[ndx + 1] < REAL_KEY)
              return (__big_delete(hashp, bufp));
       if (ndx != 1)
              newoff = bp[ndx - 1];
       else
              newoff = hashp->BSIZE;
       pairlen = newoff - bp[ndx + 1];

       if (ndx != (n - 1)) {
              /* Hard Case -- need to shuffle keys */
              register int i;
              register char *src = bufp->page + (int)OFFSET(bp);
              uint32 dst_offset = (uint32)OFFSET(bp) + (uint32)pairlen;
              register char *dst = bufp->page + dst_offset;
              uint32 length = bp[ndx + 1] - OFFSET(bp);

              /*
               * +-----------+XXX+---------+XXX+---------+---------> +infinity
               * |           |             |             |
               * 0           src_offset    dst_offset    BSIZE
               *
               * Dst_offset is > src_offset, so if src_offset were bad, dst_offset
               * would be too, therefore we check only dst_offset.
               *
               * If dst_offset is >= BSIZE, either OFFSET(bp), or pairlen, or both
               * is corrupted.
               *
               * Once we know dst_offset is < BSIZE, we can subtract it from BSIZE
               * to get an upper bound on length.
               */
              if(dst_offset > (uint32)hashp->BSIZE)
                     return(DATABASE_CORRUPTED_ERROR);

              if(length > (uint32)(hashp->BSIZE - dst_offset))
                     return(DATABASE_CORRUPTED_ERROR);

              memmove(dst, src, length);

              /* Now adjust the pointers */
              for (i = ndx + 2; i <= n; i += 2) {
                     if (bp[i + 1] == OVFLPAGE) {
                            bp[i - 2] = bp[i];
                            bp[i - 1] = bp[i + 1];
                     } else {
                            bp[i - 2] = bp[i] + pairlen;
                            bp[i - 1] = bp[i + 1] + pairlen;
                     }
              }
       }
       /* Finally adjust the page data */
       bp[n] = OFFSET(bp) + pairlen;
       bp[n - 1] = bp[n + 1] + pairlen + 2 * sizeof(uint16);
       bp[0] = n - 2;
       hashp->NKEYS--;

       bufp->flags |= BUF_MOD;
       return (0);
}

Here is the call graph for this function:

int __expand_table ( HTAB hashp)

Definition at line 1003 of file hash.c.

{
       uint32 old_bucket, new_bucket;
       int new_segnum, spare_ndx;
       size_t dirsize;

#ifdef HASH_STATISTICS
       hash_expansions++;
#endif
       new_bucket = ++hashp->MAX_BUCKET;
       old_bucket = (hashp->MAX_BUCKET & hashp->LOW_MASK);

       new_segnum = new_bucket >> hashp->SSHIFT;

       /* Check if we need a new segment */
       if (new_segnum >= hashp->nsegs) {
              /* Check if we need to expand directory */
              if (new_segnum >= hashp->DSIZE) {
                     /* Reallocate directory */
                     dirsize = hashp->DSIZE * sizeof(SEGMENT *);
                     if (!hash_realloc(&hashp->dir, dirsize, dirsize << 1))
                            return (-1);
                     hashp->DSIZE = dirsize << 1;
              }
              if ((hashp->dir[new_segnum] =
                  (SEGMENT)calloc((size_t)hashp->SGSIZE, sizeof(SEGMENT))) == NULL)
                     return (-1);
              hashp->exsegs++;
              hashp->nsegs++;
       }
       /*
        * If the split point is increasing (MAX_BUCKET's log base 2
        * * increases), we need to copy the current contents of the spare
        * split bucket to the next bucket.
        */
       spare_ndx = __log2((uint32)(hashp->MAX_BUCKET + 1));
       if (spare_ndx > hashp->OVFL_POINT) {
              hashp->SPARES[spare_ndx] = hashp->SPARES[hashp->OVFL_POINT];
              hashp->OVFL_POINT = spare_ndx;
       }

       if (new_bucket > (uint32)hashp->HIGH_MASK) {
              /* Starting a new doubling */
              hashp->LOW_MASK = hashp->HIGH_MASK;
              hashp->HIGH_MASK = new_bucket | hashp->LOW_MASK;
       }
       /* Relocate records to the new bucket */
       return (__split_page(hashp, old_bucket, new_bucket));
}

Here is the call graph for this function:

int __find_bigpair ( HTAB hashp,
BUFHEAD *  bufp,
int  ndx,
char *  key,
int  size 
)

Definition at line 264 of file h_bigkey.c.

{
       register uint16 *bp;
       register char *p;
       int ksize;
       uint16 bytes;
       char *kkey;

       bp = (uint16 *)bufp->page;
       p = bufp->page;
       ksize = size;
       kkey = key;

       for (bytes = hashp->BSIZE - bp[ndx];
           bytes <= size && bp[ndx + 1] == PARTIAL_KEY;
           bytes = hashp->BSIZE - bp[ndx]) {
              if (memcmp(p + bp[ndx], kkey, bytes))
                     return (-2);
              kkey += bytes;
              ksize -= bytes;
              bufp = __get_buf(hashp, bp[ndx + 2], bufp, 0);
              if (!bufp)
                     return (-3);
              p = bufp->page;
              bp = (uint16 *)p;
              ndx = 1;
       }

       if (bytes != ksize || memcmp(p + bp[ndx], kkey, bytes)) {
#ifdef HASH_STATISTICS
              ++hash_collisions;
#endif
              return (-2);
       } else
              return (ndx);
}

Here is the call graph for this function:

uint16 __find_last_page ( HTAB hashp,
BUFHEAD **  bpp 
)

Definition at line 311 of file h_bigkey.c.

{
       BUFHEAD *bufp;
       uint16 *bp, pageno;
       uint n;

       bufp = *bpp;
       bp = (uint16 *)bufp->page;
       for (;;) {
              n = bp[0];

              /*
               * This is the last page if: the tag is FULL_KEY_DATA and
               * either only 2 entries OVFLPAGE marker is explicit there
               * is freespace on the page.
               */
              if (bp[2] == FULL_KEY_DATA &&
                  ((n == 2) || (bp[n] == OVFLPAGE) || (FREESPACE(bp))))
                     break;

              /* LJM bound the size of n to reasonable limits
               */
              if(n > hashp->BSIZE/sizeof(uint16))
                     return(0);

              pageno = bp[n - 1];
              bufp = __get_buf(hashp, pageno, bufp, 0);
              if (!bufp)
                     return (0);   /* Need to indicate an error! */
              bp = (uint16 *)bufp->page;
       }

       *bpp = bufp;
       if (bp[0] > 2)
              return (bp[3]);
       else
              return (0);
}

Here is the call graph for this function:

void __free_ovflpage ( HTAB hashp,
BUFHEAD *  obufp 
)

Definition at line 1107 of file h_page.c.

{
       uint16 addr;
       uint32 *freep;
       uint32 bit_address, free_page, free_bit;
       uint16 ndx;

       if(!obufp || !obufp->addr)
           return;

       addr = obufp->addr;
#ifdef DEBUG1
       (void)fprintf(stderr, "Freeing %d\n", addr);
#endif
       ndx = (((uint16)addr) >> SPLITSHIFT);
       bit_address =
           (ndx ? hashp->SPARES[ndx - 1] : 0) + (addr & SPLITMASK) - 1;
       if (bit_address < (uint32)hashp->LAST_FREED)
              hashp->LAST_FREED = bit_address;
       free_page = (bit_address >> (hashp->BSHIFT + BYTE_SHIFT));
       free_bit = bit_address & ((hashp->BSIZE << BYTE_SHIFT) - 1);

       if (!(freep = hashp->mapp[free_page])) 
              freep = fetch_bitmap(hashp, free_page);

#ifdef DEBUG
       /*
        * This had better never happen.  It means we tried to read a bitmap
        * that has already had overflow pages allocated off it, and we
        * failed to read it from the file.
        */
       if (!freep)
         {
              assert(0);
              return;
         }
#endif
       CLRBIT(freep, free_bit);
#ifdef DEBUG2
       (void)fprintf(stderr, "FREE_OVFLPAGE: ADDR: %d BIT: %d PAGE %d\n",
           obufp->addr, free_bit, free_page);
#endif
       __reclaim_buf(hashp, obufp);
}

Here is the call graph for this function:

BUFHEAD* __get_buf ( HTAB hashp,
uint32  addr,
BUFHEAD *  prev_bp,
int  newpage 
)

Definition at line 107 of file hash_buf.c.

{
       register BUFHEAD *bp;
       register uint32 is_disk_mask;
       register int is_disk, segment_ndx = 0;
       SEGMENT segp = 0;

       is_disk = 0;
       is_disk_mask = 0;
       if (prev_bp) {
              bp = prev_bp->ovfl;
              if (!bp || (bp->addr != addr))
                     bp = NULL;
              if (!newpage)
                     is_disk = BUF_DISK;
       } else {
              /* Grab buffer out of directory */
              segment_ndx = addr & (hashp->SGSIZE - 1);

              /* valid segment ensured by __call_hash() */
              segp = hashp->dir[addr >> hashp->SSHIFT];
#ifdef DEBUG
              assert(segp != NULL);
#endif  

              bp = PTROF(segp[segment_ndx]);

              is_disk_mask = ISDISK(segp[segment_ndx]);
              is_disk = is_disk_mask || !hashp->new_file;
       }

       if (!bp) {
              bp = newbuf(hashp, addr, prev_bp);
              if (!bp)
                     return(NULL);
              if(__get_page(hashp, bp->page, addr, !prev_bp, is_disk, 0))
                {
                     /* free bp and its page */
                     if(prev_bp)
                       {
                            /* if prev_bp is set then the new page that
                             * failed is hooked onto prev_bp as an overflow page.
                             * if we don't remove the pointer to the bad page
                             * we may try and access it later and we will die
                             * horribly because it will have already been
                             * free'd and overwritten with bogus data.
                             */
                            prev_bp->ovfl = NULL;
                       }
                     BUF_REMOVE(bp);
                     free(bp->page);
                     free(bp);
                     return (NULL);
                }

              if (!prev_bp)               
                {
#if 0
                     /* 16 bit windows and mac can't handle the
                      * oring of the is disk flag.
                      */                  
                     segp[segment_ndx] =
                         (BUFHEAD *)((ptrdiff_t)bp | is_disk_mask);
#else   
                     /* set the is_disk thing inside the structure
                      */
                     bp->is_disk = is_disk_mask;
                     segp[segment_ndx] = bp;
#endif
                }
       } else {  
              BUF_REMOVE(bp);
              MRU_INSERT(bp);                 
       }
       return (bp);
}

Here is the call graph for this function:

int __get_page ( HTAB hashp,
char *  p,
uint32  bucket,
int  is_bucket,
int  is_disk,
int  is_bitmap 
)

Definition at line 686 of file h_page.c.

{
       register int fd, page;
       size_t size;
       int rsize;
       uint16 *bp;

       fd = hashp->fp;
       size = hashp->BSIZE;

       if ((fd == -1) || !is_disk) {
              PAGE_INIT(p);
              return (0);
       }
       if (is_bucket)
              page = BUCKET_TO_PAGE(bucket);
       else
              page = OADDR_TO_PAGE(bucket);
       if ((MY_LSEEK(fd, (off_t)page << hashp->BSHIFT, SEEK_SET) == -1) ||
           ((rsize = read(fd, p, size)) == -1))
              return (-1);

       bp = (uint16 *)p;
       if (!rsize)
              bp[0] = 0;    /* We hit the EOF, so initialize a new page */
       else
              if ((unsigned)rsize != size) {
                     errno = EFTYPE;
                     return (-1);
              }

       if (!is_bitmap && !bp[0]) {
              PAGE_INIT(p);
       } else {

#ifdef DEBUG
              if(BYTE_ORDER == LITTLE_ENDIAN)
                {
                     int is_little_endian;
                     is_little_endian = BYTE_ORDER;
                }
              else if(BYTE_ORDER == BIG_ENDIAN)
                {
                     int is_big_endian;
                     is_big_endian = BYTE_ORDER;
                }
              else
                {
                     assert(0);
                }
#endif

              if (hashp->LORDER != BYTE_ORDER) {
                     register int i, max;

                     if (is_bitmap) {
                            max = hashp->BSIZE >> 2; /* divide by 4 */
                            for (i = 0; i < max; i++)
                                   M_32_SWAP(((int *)p)[i]);
                     } else {
                            M_16_SWAP(bp[0]);
                            max = bp[0] + 2;

                     /* bound the size of max by
                      * the maximum number of entries
                      * in the array
                      */
                            if((unsigned)max > (size / sizeof(uint16)))
                                   return(DATABASE_CORRUPTED_ERROR);

                            /* do the byte order swap
                             */
                            for (i = 1; i <= max; i++)
                                   M_16_SWAP(bp[i]);
                     }
              }

              /* check the validity of the page here
               * (after doing byte order swaping if necessary)
               */
              if(!is_bitmap && bp[0] != 0)
                {
                     uint16 num_keys = bp[0];
                     uint16 offset;
                     uint16 i;

                     /* bp[0] is supposed to be the number of
                      * entries currently in the page.  If
                      * bp[0] is too large (larger than the whole
                      * page) then the page is corrupted
                      */
                     if(bp[0] > (size / sizeof(uint16)))
                            return(DATABASE_CORRUPTED_ERROR);
                     
                     /* bound free space */
                     if(FREESPACE(bp) > size)
                            return(DATABASE_CORRUPTED_ERROR);
              
                     /* check each key and data offset to make
                      * sure they are all within bounds they
                      * should all be less than the previous
                      * offset as well.
                      */
                     offset = size;
                     for(i=1 ; i <= num_keys; i+=2)
                       {
                            /* ignore overflow pages etc. */
                            if(bp[i+1] >= REAL_KEY)
                              {
                                          
                                   if(bp[i] > offset || bp[i+1] > bp[i])                   
                                          return(DATABASE_CORRUPTED_ERROR);
                     
                                   offset = bp[i+1];
                              }
                            else
                              {
                                   /* there are no other valid keys after
                                    * seeing a non REAL_KEY
                                    */
                                   break;
                              }
                       }
              }
       }
       return (0);
}
int __ibitmap ( HTAB hashp,
int  pnum,
int  nbits,
int  ndx 
)

Definition at line 918 of file h_page.c.

{
       uint32 *ip;
       size_t clearbytes, clearints;

       if ((ip = (uint32 *)malloc((size_t)hashp->BSIZE)) == NULL)
              return (1);
       hashp->nmaps++;
       clearints = ((nbits - 1) >> INT_BYTE_SHIFT) + 1;
       clearbytes = clearints << INT_TO_BYTE;
       (void)memset((char *)ip, 0, clearbytes);
       (void)memset(((char *)ip) + clearbytes, 0xFF,
           hashp->BSIZE - clearbytes);
       ip[clearints - 1] = ALL_SET << (nbits & BYTE_MASK);
       SETBIT(ip, 0);
       hashp->BITMAPS[ndx] = (uint16)pnum;
       hashp->mapp[ndx] = ip;
       return (0);
}

Here is the call graph for this function:

uint32 __log2 ( uint32  num)

Definition at line 47 of file h_log2.c.

{
       register uint32 i, limit;

       limit = 1;
       for (i = 0; limit < num; limit = limit << 1, i++) {}
       return (i);
}
int __put_page ( HTAB hashp,
char *  p,
uint32  bucket,
int  is_bucket,
int  is_bitmap 
)

Definition at line 827 of file h_page.c.

{
       register int fd, page;
       size_t size;
       int wsize;
       off_t offset;

       size = hashp->BSIZE;
       if ((hashp->fp == -1) && open_temp(hashp))
              return (-1);
       fd = hashp->fp;

       if (hashp->LORDER != BYTE_ORDER) {
              register int i;
              register int max;

              if (is_bitmap) {
                     max = hashp->BSIZE >> 2;    /* divide by 4 */
                     for (i = 0; i < max; i++)
                            M_32_SWAP(((int *)p)[i]);
              } else {
                     max = ((uint16 *)p)[0] + 2;

            /* bound the size of max by
             * the maximum number of entries
             * in the array
             */
            if((unsigned)max > (size / sizeof(uint16)))
                return(DATABASE_CORRUPTED_ERROR);

                     for (i = 0; i <= max; i++)
                            M_16_SWAP(((uint16 *)p)[i]);

              }
       }

       if (is_bucket)
              page = BUCKET_TO_PAGE(bucket);
       else
              page = OADDR_TO_PAGE(bucket);
       offset = (off_t)page << hashp->BSHIFT;
       if ((MY_LSEEK(fd, offset, SEEK_SET) == -1) ||
           ((wsize = write(fd, p, size)) == -1))
              /* Errno is set */
              return (-1);
       if ((unsigned)wsize != size) {
              errno = EFTYPE;
              return (-1);
       }
#if defined(_WIN32) || defined(_WINDOWS) 
       if (offset + size > hashp->file_size) {
              hashp->updateEOF = 1;
       }
#endif
       /* put the page back the way it was so that it isn't byteswapped
        * if it remains in memory - LJM
        */
       if (hashp->LORDER != BYTE_ORDER) {
              register int i;
              register int max;

              if (is_bitmap) {
                     max = hashp->BSIZE >> 2;    /* divide by 4 */
                     for (i = 0; i < max; i++)
                            M_32_SWAP(((int *)p)[i]);
              } else {
              uint16 *bp = (uint16 *)p;

                     M_16_SWAP(bp[0]);
                     max = bp[0] + 2;

                     /* no need to bound the size if max again
                      * since it was done already above
                      */

                     /* do the byte order re-swap
                      */
                     for (i = 1; i <= max; i++)
                            M_16_SWAP(bp[i]);
              }
       }

       return (0);
}

Here is the call graph for this function:

void __reclaim_buf ( HTAB hashp,
BUFHEAD *  bp 
)

Definition at line 405 of file hash_buf.c.

{
       bp->ovfl = 0;
       bp->addr = 0;
       bp->flags = 0;
       BUF_REMOVE(bp);
       LRU_INSERT(bp);
}
int __split_page ( HTAB hashp,
uint32  obucket,
uint32  nbucket 
)

Definition at line 284 of file h_page.c.

{
       register BUFHEAD *new_bufp, *old_bufp;
       register uint16 *ino;
       register uint16 *tmp_uint16_array;
       register char *np;
       DBT key, val;
    uint16 n, ndx;
       int retval;
       uint16 copyto, diff, moved;
       size_t off;
       char *op;

       copyto = (uint16)hashp->BSIZE;
       off = (uint16)hashp->BSIZE;
       old_bufp = __get_buf(hashp, obucket, NULL, 0);
       if (old_bufp == NULL)
              return (-1);
       new_bufp = __get_buf(hashp, nbucket, NULL, 0);
       if (new_bufp == NULL)
              return (-1);

       old_bufp->flags |= (BUF_MOD | BUF_PIN);
       new_bufp->flags |= (BUF_MOD | BUF_PIN);

       ino = (uint16 *)(op = old_bufp->page);
       np = new_bufp->page;

       moved = 0;

       for (n = 1, ndx = 1; n < ino[0]; n += 2) {
              if (ino[n + 1] < REAL_KEY) {
                     retval = ugly_split(hashp, obucket, old_bufp, new_bufp,
                         (int)copyto, (int)moved);
                     old_bufp->flags &= ~BUF_PIN;
                     new_bufp->flags &= ~BUF_PIN;
                     return (retval);

              }
              key.data = (uint8 *)op + ino[n];

              /* check here for ino[n] being greater than
               * off.  If it is then the database has
               * been corrupted.
               */
              if(ino[n] > off)
                     return(DATABASE_CORRUPTED_ERROR);

              key.size = off - ino[n];

#ifdef DEBUG
              /* make sure the size is positive */
              assert(((int)key.size) > -1);
#endif

              if (__call_hash(hashp, (char *)key.data, key.size) == obucket) {
                     /* Don't switch page */
                     diff = copyto - off;
                     if (diff) {
                            copyto = ino[n + 1] + diff;
                            memmove(op + copyto, op + ino[n + 1],
                                off - ino[n + 1]);
                            ino[ndx] = copyto + ino[n] - ino[n + 1];
                            ino[ndx + 1] = copyto;
                     } else
                            copyto = ino[n + 1];
                     ndx += 2;
              } else {
                     /* Switch page */
                     val.data = (uint8 *)op + ino[n + 1];
                     val.size = ino[n] - ino[n + 1];

                     /* if the pair doesn't fit something is horribly
                      * wrong.  LJM
                      */
                     tmp_uint16_array = (uint16*)np;
                     if(!PAIRFITS(tmp_uint16_array, &key, &val))
                            return(DATABASE_CORRUPTED_ERROR);

                     putpair(np, &key, &val);
                     moved += 2;
              }

              off = ino[n + 1];
       }

       /* Now clean up the page */
       ino[0] -= moved;
       FREESPACE(ino) = copyto - sizeof(uint16) * (ino[0] + 3);
       OFFSET(ino) = copyto;

#ifdef DEBUG3
       (void)fprintf(stderr, "split %d/%d\n",
           ((uint16 *)np)[0] / 2,
           ((uint16 *)op)[0] / 2);
#endif
       /* unpin both pages */
       old_bufp->flags &= ~BUF_PIN;
       new_bufp->flags &= ~BUF_PIN;
       return (0);
}

Here is the call graph for this function:


Variable Documentation