]> git.saurik.com Git - apple/libc.git/blobdiff - db/hash/hash_bigkey.c
Libc-320.tar.gz
[apple/libc.git] / db / hash / hash_bigkey.c
index fa8e8ddecd2b46166071c17f5a6c17bfc805a4c3..3d1713bb77b2a138c004c4f3022e06dc959284e4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  * 
@@ -22,8 +22,8 @@
  * 
  * @APPLE_LICENSE_HEADER_END@
  */
-/*
- * Copyright (c) 1990, 1993
+/*-
+ * Copyright (c) 1990, 1993, 1994
  *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  * SUCH DAMAGE.
  */
 
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)hash_bigkey.c      8.3 (Berkeley) 5/31/94";
+#endif /* LIBC_SCCS and not lint */
+#include <sys/cdefs.h>
 
 /*
  * PACKAGE: hash
@@ -93,8 +97,8 @@
 #include "page.h"
 #include "extern.h"
 
-static int collect_key __P((HTAB *, BUFHEAD *, int, DBT *, int));
-static int collect_data __P((HTAB *, BUFHEAD *, int, int));
+static int collect_key(HTAB *, BUFHEAD *, int, DBT *, int);
+static int collect_data(HTAB *, BUFHEAD *, int, int);
 
 /*
  * Big_insert
@@ -111,13 +115,13 @@ __big_insert(hashp, bufp, key, val)
        BUFHEAD *bufp;
        const DBT *key, *val;
 {
-       register u_short *p;
+       u_int16_t *p;
        int key_size, n, val_size;
-       u_short space, move_bytes, off;
+       u_int16_t space, move_bytes, off;
        char *cp, *key_data, *val_data;
 
        cp = bufp->page;                /* Character pointer of p. */
-       p = (u_short *)cp;
+       p = (u_int16_t *)cp;
 
        key_data = (char *)key->data;
        key_size = key->size;
@@ -142,7 +146,7 @@ __big_insert(hashp, bufp, key, val)
                if (!bufp)
                        return (-1);
                n = p[0];
-               if (!key_size)
+               if (!key_size) {
                        if (FREESPACE(p)) {
                                move_bytes = MIN(FREESPACE(p), val_size);
                                off = OFFSET(p) - move_bytes;
@@ -155,7 +159,8 @@ __big_insert(hashp, bufp, key, val)
                                OFFSET(p) = off;
                        } else
                                p[n - 2] = FULL_KEY;
-               p = (u_short *)bufp->page;
+               }
+               p = (u_int16_t *)bufp->page;
                cp = bufp->page;
                bufp->flags |= BUF_MOD;
        }
@@ -185,7 +190,7 @@ __big_insert(hashp, bufp, key, val)
                        if (!bufp)
                                return (-1);
                        cp = bufp->page;
-                       p = (u_short *)cp;
+                       p = (u_int16_t *)cp;
                } else
                        p[n] = FULL_KEY_DATA;
                bufp->flags |= BUF_MOD;
@@ -209,13 +214,13 @@ __big_delete(hashp, bufp)
        HTAB *hashp;
        BUFHEAD *bufp;
 {
-       register BUFHEAD *last_bfp, *rbufp;
-       u_short *bp, pageno;
+       BUFHEAD *last_bfp, *rbufp;
+       u_int16_t *bp, pageno;
        int key_done, n;
 
        rbufp = bufp;
        last_bfp = NULL;
-       bp = (u_short *)bufp->page;
+       bp = (u_int16_t *)bufp->page;
        pageno = 0;
        key_done = 0;
 
@@ -238,7 +243,7 @@ __big_delete(hashp, bufp)
                last_bfp = rbufp;
                if (!rbufp)
                        return (-1);            /* Error. */
-               bp = (u_short *)rbufp->page;
+               bp = (u_int16_t *)rbufp->page;
        }
 
        /*
@@ -253,7 +258,7 @@ __big_delete(hashp, bufp)
        pageno = bp[n - 1];
 
        /* Now, bp is the first page of the pair. */
-       bp = (u_short *)bufp->page;
+       bp = (u_int16_t *)bufp->page;
        if (n > 2) {
                /* There is an overflow page. */
                bp[1] = pageno;
@@ -291,13 +296,13 @@ __find_bigpair(hashp, bufp, ndx, key, size)
        char *key;
        int size;
 {
-       register u_short *bp;
-       register char *p;
+       u_int16_t *bp;
+       char *p;
        int ksize;
-       u_short bytes;
+       u_int16_t bytes;
        char *kkey;
 
-       bp = (u_short *)bufp->page;
+       bp = (u_int16_t *)bufp->page;
        p = bufp->page;
        ksize = size;
        kkey = key;
@@ -313,7 +318,7 @@ __find_bigpair(hashp, bufp, ndx, key, size)
                if (!bufp)
                        return (-3);
                p = bufp->page;
-               bp = (u_short *)p;
+               bp = (u_int16_t *)p;
                ndx = 1;
        }
 
@@ -335,17 +340,17 @@ __find_bigpair(hashp, bufp, ndx, key, size)
  * of the pair; 0 if there isn't any (i.e. big pair is the last key in the
  * bucket)
  */
-extern u_short
+extern u_int16_t
 __find_last_page(hashp, bpp)
        HTAB *hashp;
        BUFHEAD **bpp;
 {
        BUFHEAD *bufp;
-       u_short *bp, pageno;
+       u_int16_t *bp, pageno;
        int n;
 
        bufp = *bpp;
-       bp = (u_short *)bufp->page;
+       bp = (u_int16_t *)bufp->page;
        for (;;) {
                n = bp[0];
 
@@ -362,7 +367,7 @@ __find_last_page(hashp, bpp)
                bufp = __get_buf(hashp, pageno, bufp, 0);
                if (!bufp)
                        return (0);     /* Need to indicate an error! */
-               bp = (u_short *)bufp->page;
+               bp = (u_int16_t *)bufp->page;
        }
 
        *bpp = bufp;
@@ -385,15 +390,15 @@ __big_return(hashp, bufp, ndx, val, set_current)
        int set_current;
 {
        BUFHEAD *save_p;
-       u_short *bp, len, off, save_addr;
+       u_int16_t *bp, len, off, save_addr;
        char *tp;
 
-       bp = (u_short *)bufp->page;
+       bp = (u_int16_t *)bufp->page;
        while (bp[ndx + 1] == PARTIAL_KEY) {
                bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
                if (!bufp)
                        return (-1);
-               bp = (u_short *)bufp->page;
+               bp = (u_int16_t *)bufp->page;
                ndx = 1;
        }
 
@@ -401,7 +406,7 @@ __big_return(hashp, bufp, ndx, val, set_current)
                bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
                if (!bufp)
                        return (-1);
-               bp = (u_short *)bufp->page;
+               bp = (u_int16_t *)bufp->page;
                save_p = bufp;
                save_addr = save_p->addr;
                off = bp[1];
@@ -422,7 +427,7 @@ __big_return(hashp, bufp, ndx, val, set_current)
                        bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
                        if (!bufp)
                                return (-1);
-                       bp = (u_short *)bufp->page;
+                       bp = (u_int16_t *)bufp->page;
                } else {
                        /* The data is all on one page. */
                        tp = (char *)bp;
@@ -441,7 +446,7 @@ __big_return(hashp, bufp, ndx, val, set_current)
                                        if (!hashp->cpage)
                                                return (-1);
                                        hashp->cndx = 1;
-                                       if (!((u_short *)
+                                       if (!((u_int16_t *)
                                            hashp->cpage->page)[0]) {
                                                hashp->cbucket++;
                                                hashp->cpage = NULL;
@@ -473,14 +478,14 @@ collect_data(hashp, bufp, len, set)
        BUFHEAD *bufp;
        int len, set;
 {
-       register u_short *bp;
-       register char *p;
+       u_int16_t *bp;
+       char *p;
        BUFHEAD *xbp;
-       u_short save_addr;
+       u_int16_t save_addr;
        int mylen, totlen;
 
        p = bufp->page;
-       bp = (u_short *)p;
+       bp = (u_int16_t *)p;
        mylen = hashp->BSIZE - bp[1];
        save_addr = bufp->addr;
 
@@ -500,7 +505,7 @@ collect_data(hashp, bufp, len, set)
                                    __get_buf(hashp, bp[bp[0] - 1], bufp, 0);
                                if (!hashp->cpage)
                                        return (-1);
-                               else if (!((u_short *)hashp->cpage->page)[0]) {
+                               else if (!((u_int16_t *)hashp->cpage->page)[0]) {
                                        hashp->cbucket++;
                                        hashp->cpage = NULL;
                                }
@@ -552,10 +557,10 @@ collect_key(hashp, bufp, len, val, set)
        BUFHEAD *xbp;
        char *p;
        int mylen, totlen;
-       u_short *bp, save_addr;
+       u_int16_t *bp, save_addr;
 
        p = bufp->page;
-       bp = (u_short *)p;
+       bp = (u_int16_t *)p;
        mylen = hashp->BSIZE - bp[1];
 
        save_addr = bufp->addr;
@@ -594,15 +599,15 @@ __big_split(hashp, op, np, big_keyp, addr, obucket, ret)
                        /* Pointer to first page containing the big key/data */
        BUFHEAD *big_keyp;
        int addr;       /* Address of big_keyp */
-       u_int   obucket;/* Old Bucket */
+       u_int32_t   obucket;/* Old Bucket */
        SPLIT_RETURN *ret;
 {
-       register BUFHEAD *tmpp;
-       register u_short *tp;
+       BUFHEAD *tmpp;
+       u_int16_t *tp;
        BUFHEAD *bp;
        DBT key, val;
-       u_int change;
-       u_short free_space, n, off;
+       u_int32_t change;
+       u_int16_t free_space, n, off;
 
        bp = big_keyp;
 
@@ -611,7 +616,7 @@ __big_split(hashp, op, np, big_keyp, addr, obucket, ret)
                return (-1);
        change = (__call_hash(hashp, key.data, key.size) != obucket);
 
-       if (ret->next_addr = __find_last_page(hashp, &big_keyp)) {
+       if ( (ret->next_addr = __find_last_page(hashp, &big_keyp)) ) {
                if (!(ret->nextp =
                    __get_buf(hashp, ret->next_addr, big_keyp, 0)))
                        return (-1);;
@@ -634,14 +639,14 @@ __big_split(hashp, op, np, big_keyp, addr, obucket, ret)
            (tmpp->ovfl ? tmpp->ovfl->addr : 0), (bp ? bp->addr : 0));
 #endif
        tmpp->ovfl = bp;        /* one of op/np point to big_keyp */
-       tp = (u_short *)tmpp->page;
+       tp = (u_int16_t *)tmpp->page;
 #ifdef DEBUG
        assert(FREESPACE(tp) >= OVFLSIZE);
 #endif
        n = tp[0];
        off = OFFSET(tp);
        free_space = FREESPACE(tp);
-       tp[++n] = (u_short)addr;
+       tp[++n] = (u_int16_t)addr;
        tp[++n] = OVFLPAGE;
        tp[0] = n;
        OFFSET(tp) = off;
@@ -657,7 +662,7 @@ __big_split(hashp, op, np, big_keyp, addr, obucket, ret)
        ret->newp = np;
        ret->oldp = op;
 
-       tp = (u_short *)big_keyp->page;
+       tp = (u_int16_t *)big_keyp->page;
        big_keyp->flags |= BUF_MOD;
        if (tp[0] > 2) {
                /*