diff options
author | pst <pst@FreeBSD.org> | 1996-02-27 01:59:15 +0000 |
---|---|---|
committer | pst <pst@FreeBSD.org> | 1996-02-27 01:59:15 +0000 |
commit | c2306789fe98946429af7462a2fd453454034a79 (patch) | |
tree | e6563df097216e3af35d87ac698b2ea9eb3f5f75 /lib/libc/db/hash | |
parent | 5476eae499a3e1c3530620c0ebc3a69ffb2f25ba (diff) | |
download | FreeBSD-src-c2306789fe98946429af7462a2fd453454034a79.zip FreeBSD-src-c2306789fe98946429af7462a2fd453454034a79.tar.gz |
Import updated Berkeley DB into CSRG branch
Diffstat (limited to 'lib/libc/db/hash')
-rw-r--r-- | lib/libc/db/hash/extern.h | 24 | ||||
-rw-r--r-- | lib/libc/db/hash/hash.c | 56 | ||||
-rw-r--r-- | lib/libc/db/hash/hash.h | 125 | ||||
-rw-r--r-- | lib/libc/db/hash/hash_bigkey.c | 76 | ||||
-rw-r--r-- | lib/libc/db/hash/hash_buf.c | 28 | ||||
-rw-r--r-- | lib/libc/db/hash/hash_log2.c | 12 | ||||
-rw-r--r-- | lib/libc/db/hash/hash_page.c | 170 | ||||
-rw-r--r-- | lib/libc/db/hash/hsearch.c | 4 | ||||
-rw-r--r-- | lib/libc/db/hash/ndbm.c | 6 | ||||
-rw-r--r-- | lib/libc/db/hash/page.h | 16 |
10 files changed, 268 insertions, 249 deletions
diff --git a/lib/libc/db/hash/extern.h b/lib/libc/db/hash/extern.h index b7ef37a..3167e6d 100644 --- a/lib/libc/db/hash/extern.h +++ b/lib/libc/db/hash/extern.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1991, 1993 + * Copyright (c) 1991, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -30,7 +30,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)extern.h 8.2 (Berkeley) 2/21/94 + * @(#)extern.h 8.4 (Berkeley) 6/16/94 */ BUFHEAD *__add_ovflpage __P((HTAB *, BUFHEAD *)); @@ -40,26 +40,26 @@ int __big_insert __P((HTAB *, BUFHEAD *, const DBT *, const DBT *)); int __big_keydata __P((HTAB *, BUFHEAD *, DBT *, DBT *, int)); int __big_return __P((HTAB *, BUFHEAD *, int, DBT *, int)); int __big_split __P((HTAB *, BUFHEAD *, BUFHEAD *, BUFHEAD *, - int, u_int, SPLIT_RETURN *)); + int, u_int32_t, SPLIT_RETURN *)); int __buf_free __P((HTAB *, int, int)); void __buf_init __P((HTAB *, int)); -u_int __call_hash __P((HTAB *, char *, int)); +u_int32_t __call_hash __P((HTAB *, char *, int)); int __delpair __P((HTAB *, BUFHEAD *, int)); int __expand_table __P((HTAB *)); int __find_bigpair __P((HTAB *, BUFHEAD *, int, char *, int)); -u_short __find_last_page __P((HTAB *, BUFHEAD **)); +u_int16_t __find_last_page __P((HTAB *, BUFHEAD **)); void __free_ovflpage __P((HTAB *, BUFHEAD *)); -BUFHEAD *__get_buf __P((HTAB *, u_int, BUFHEAD *, int)); -int __get_page __P((HTAB *, char *, u_int, int, int, int)); -int __init_bitmap __P((HTAB *, int, int, int)); -u_int __log2 __P((u_int)); -int __put_page __P((HTAB *, char *, u_int, int, int)); +BUFHEAD *__get_buf __P((HTAB *, u_int32_t, BUFHEAD *, int)); +int __get_page __P((HTAB *, char *, u_int32_t, int, int, int)); +int __ibitmap __P((HTAB *, int, int, int)); +u_int32_t __log2 __P((u_int32_t)); +int __put_page __P((HTAB *, char *, u_int32_t, int, int)); void __reclaim_buf __P((HTAB *, BUFHEAD *)); -int __split_page __P((HTAB *, u_int, u_int)); +int __split_page __P((HTAB *, u_int32_t, u_int32_t)); /* Default hash routine. */ extern u_int32_t (*__default_hash) __P((const void *, size_t)); #ifdef HASH_STATISTICS -extern long hash_accesses, hash_collisions, hash_expansions, hash_overflows; +extern int hash_accesses, hash_collisions, hash_expansions, hash_overflows; #endif diff --git a/lib/libc/db/hash/hash.c b/lib/libc/db/hash/hash.c index 6a23f3d..4b7b732 100644 --- a/lib/libc/db/hash/hash.c +++ b/lib/libc/db/hash/hash.c @@ -1,5 +1,5 @@ /*- - * 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 @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)hash.c 8.7 (Berkeley) 2/21/94"; +static char sccsid[] = "@(#)hash.c 8.9 (Berkeley) 6/16/94"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -60,13 +60,13 @@ static int alloc_segs __P((HTAB *, int)); static int flush_meta __P((HTAB *)); static int hash_access __P((HTAB *, ACTION, DBT *, DBT *)); static int hash_close __P((DB *)); -static int hash_delete __P((const DB *, const DBT *, u_int)); +static int hash_delete __P((const DB *, const DBT *, u_int32_t)); static int hash_fd __P((const DB *)); -static int hash_get __P((const DB *, const DBT *, DBT *, u_int)); -static int hash_put __P((const DB *, DBT *, const DBT *, u_int)); +static int hash_get __P((const DB *, const DBT *, DBT *, u_int32_t)); +static int hash_put __P((const DB *, DBT *, const DBT *, u_int32_t)); static void *hash_realloc __P((SEGMENT **, int, int)); -static int hash_seq __P((const DB *, DBT *, DBT *, u_int)); -static int hash_sync __P((const DB *, u_int)); +static int hash_seq __P((const DB *, DBT *, DBT *, u_int32_t)); +static int hash_sync __P((const DB *, u_int32_t)); static int hdestroy __P((HTAB *)); static HTAB *init_hash __P((HTAB *, const char *, HASHINFO *)); static int init_htab __P((HTAB *, int)); @@ -86,7 +86,7 @@ static void swap_header_copy __P((HASHHDR *, HASHHDR *)); #define ABNORMAL (1) #ifdef HASH_STATISTICS -long hash_accesses, hash_collisions, hash_expansions, hash_overflows; +int hash_accesses, hash_collisions, hash_expansions, hash_overflows; #endif /************************** INTERFACE ROUTINES ***************************/ @@ -179,7 +179,7 @@ __hash_open(file, flags, mode, info, dflags) (hashp->BSHIFT + BYTE_SHIFT); hashp->nmaps = bpages; - (void)memset(&hashp->mapp[0], 0, bpages * sizeof(u_long *)); + (void)memset(&hashp->mapp[0], 0, bpages * sizeof(u_int32_t *)); } /* Initialize Buffer Manager */ @@ -366,7 +366,7 @@ init_htab(hashp, nelem) hashp->LAST_FREED = 2; /* First bitmap page is at: splitpoint l2 page offset 1 */ - if (__init_bitmap(hashp, OADDR_OF(l2, 1), l2 + 1, 0)) + if (__ibitmap(hashp, OADDR_OF(l2, 1), l2 + 1, 0)) return (-1); hashp->MAX_BUCKET = hashp->LOW_MASK = nbuckets - 1; @@ -451,7 +451,7 @@ hdestroy(hashp) static int hash_sync(dbp, flags) const DB *dbp; - u_int flags; + u_int32_t flags; { HTAB *hashp; @@ -530,7 +530,7 @@ hash_get(dbp, key, data, flag) const DB *dbp; const DBT *key; DBT *data; - u_int flag; + u_int32_t flag; { HTAB *hashp; @@ -547,7 +547,7 @@ hash_put(dbp, key, data, flag) const DB *dbp; DBT *key; const DBT *data; - u_int flag; + u_int32_t flag; { HTAB *hashp; @@ -568,7 +568,7 @@ static int hash_delete(dbp, key, flag) const DB *dbp; const DBT *key; - u_int flag; /* Ignored */ + u_int32_t flag; /* Ignored */ { HTAB *hashp; @@ -595,10 +595,10 @@ hash_access(hashp, action, key, val) { register BUFHEAD *rbufp; BUFHEAD *bufp, *save_bufp; - register u_short *bp; + register u_int16_t *bp; register int n, ndx, off, size; register char *kp; - u_short pageno; + u_int16_t pageno; #ifdef HASH_STATISTICS hash_accesses++; @@ -614,7 +614,7 @@ hash_access(hashp, action, key, val) /* Pin the bucket chain */ rbufp->flags |= BUF_PIN; - for (bp = (u_short *)rbufp->page, n = *bp++, ndx = 1; ndx < n;) + for (bp = (u_int16_t *)rbufp->page, n = *bp++, ndx = 1; ndx < n;) if (bp[1] >= REAL_KEY) { /* Real key/data pair */ if (size == off - *bp && @@ -633,7 +633,7 @@ hash_access(hashp, action, key, val) return (ERROR); } /* FOR LOOP INIT */ - bp = (u_short *)rbufp->page; + bp = (u_int16_t *)rbufp->page; n = *bp++; ndx = 1; off = hashp->BSIZE; @@ -655,7 +655,7 @@ hash_access(hashp, action, key, val) return (ERROR); } /* FOR LOOP INIT */ - bp = (u_short *)rbufp->page; + bp = (u_int16_t *)rbufp->page; n = *bp++; ndx = 1; off = hashp->BSIZE; @@ -689,7 +689,7 @@ found: save_bufp->flags &= ~BUF_PIN; return (ABNORMAL); case HASH_GET: - bp = (u_short *)rbufp->page; + bp = (u_int16_t *)rbufp->page; if (bp[ndx + 1] < REAL_KEY) { if (__big_return(hashp, rbufp, ndx, val, 0)) return (ERROR); @@ -720,12 +720,12 @@ static int hash_seq(dbp, key, data, flag) const DB *dbp; DBT *key, *data; - u_int flag; + u_int32_t flag; { - register u_int bucket; + register u_int32_t bucket; register BUFHEAD *bufp; HTAB *hashp; - u_short *bp, ndx; + u_int16_t *bp, ndx; hashp = (HTAB *)dbp->internal; if (flag && flag != R_FIRST && flag != R_NEXT) { @@ -750,7 +750,7 @@ hash_seq(dbp, key, data, flag) if (!bufp) return (ERROR); hashp->cpage = bufp; - bp = (u_short *)bufp->page; + bp = (u_int16_t *)bufp->page; if (bp[0]) break; } @@ -760,7 +760,7 @@ hash_seq(dbp, key, data, flag) return (ABNORMAL); } } else - bp = (u_short *)hashp->cpage->page; + bp = (u_int16_t *)hashp->cpage->page; #ifdef DEBUG assert(bp); @@ -771,7 +771,7 @@ hash_seq(dbp, key, data, flag) __get_buf(hashp, bp[hashp->cndx], bufp, 0); if (!bufp) return (ERROR); - bp = (u_short *)(bufp->page); + bp = (u_int16_t *)(bufp->page); hashp->cndx = 1; } if (!bp[0]) { @@ -810,7 +810,7 @@ extern int __expand_table(hashp) HTAB *hashp; { - u_int old_bucket, new_bucket; + u_int32_t old_bucket, new_bucket; int dirsize, new_segnum, spare_ndx; #ifdef HASH_STATISTICS @@ -877,7 +877,7 @@ hash_realloc(p_ptr, oldsize, newsize) return (p); } -extern u_int +extern u_int32_t __call_hash(hashp, k, len) HTAB *hashp; char *k; diff --git a/lib/libc/db/hash/hash.h b/lib/libc/db/hash/hash.h index cfbedaa..913e82b 100644 --- a/lib/libc/db/hash/hash.h +++ b/lib/libc/db/hash/hash.h @@ -1,5 +1,5 @@ /*- - * 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 @@ -33,7 +33,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)hash.h 8.2 (Berkeley) 2/21/94 + * @(#)hash.h 8.3 (Berkeley) 5/31/94 */ /* Operations */ @@ -45,12 +45,12 @@ typedef enum { typedef struct _bufhead BUFHEAD; struct _bufhead { - BUFHEAD *prev; /* LRU links */ - BUFHEAD *next; /* LRU links */ - BUFHEAD *ovfl; /* Overflow page buffer header */ - u_int addr; /* Address of this page */ - char *page; /* Actual page data */ - char flags; + BUFHEAD *prev; /* LRU links */ + BUFHEAD *next; /* LRU links */ + BUFHEAD *ovfl; /* Overflow page buffer header */ + u_int32_t addr; /* Address of this page */ + char *page; /* Actual page data */ + char flags; #define BUF_MOD 0x0001 #define BUF_DISK 0x0002 #define BUF_BUCKET 0x0004 @@ -62,51 +62,60 @@ struct _bufhead { typedef BUFHEAD **SEGMENT; /* Hash Table Information */ -typedef struct hashhdr { /* Disk resident portion */ - int magic; /* Magic NO for hash tables */ - int version; /* Version ID */ - long lorder; /* Byte Order */ - int bsize; /* Bucket/Page Size */ - int bshift; /* Bucket shift */ - int dsize; /* Directory Size */ - int ssize; /* Segment Size */ - int sshift; /* Segment shift */ - int ovfl_point; /* Where overflow pages are being allocated */ - int last_freed; /* Last overflow page freed */ - int max_bucket; /* ID of Maximum bucket in use */ - int high_mask; /* Mask to modulo into entire table */ - int low_mask; /* Mask to modulo into lower half of table */ - int ffactor; /* Fill factor */ - int nkeys; /* Number of keys in hash table */ - int hdrpages; /* Size of table header */ - int h_charkey; /* value of hash(CHARKEY) */ -#define NCACHED 32 /* number of bit maps and spare points */ - int spares[NCACHED];/* spare pages for overflow */ - u_short bitmaps[NCACHED]; /* address of overflow page bitmaps */ +typedef struct hashhdr { /* Disk resident portion */ + int magic; /* Magic NO for hash tables */ + int version; /* Version ID */ + u_int32_t lorder; /* Byte Order */ + int bsize; /* Bucket/Page Size */ + int bshift; /* Bucket shift */ + int dsize; /* Directory Size */ + int ssize; /* Segment Size */ + int sshift; /* Segment shift */ + int ovfl_point; /* Where overflow pages are being + * allocated */ + int last_freed; /* Last overflow page freed */ + int max_bucket; /* ID of Maximum bucket in use */ + int high_mask; /* Mask to modulo into entire table */ + int low_mask; /* Mask to modulo into lower half of + * table */ + int ffactor; /* Fill factor */ + int nkeys; /* Number of keys in hash table */ + int hdrpages; /* Size of table header */ + int h_charkey; /* value of hash(CHARKEY) */ +#define NCACHED 32 /* number of bit maps and spare + * points */ + int spares[NCACHED];/* spare pages for overflow */ + u_int16_t bitmaps[NCACHED]; /* address of overflow page + * bitmaps */ } HASHHDR; -typedef struct htab { /* Memory resident data structure */ - HASHHDR hdr; /* Header */ - int nsegs; /* Number of allocated segments */ - int exsegs; /* Number of extra allocated segments */ - u_int32_t /* Hash function */ +typedef struct htab { /* Memory resident data structure */ + HASHHDR hdr; /* Header */ + int nsegs; /* Number of allocated segments */ + int exsegs; /* Number of extra allocated + * segments */ + u_int32_t /* Hash function */ (*hash)__P((const void *, size_t)); - int flags; /* Flag values */ - int fp; /* File pointer */ - char *tmp_buf; /* Temporary Buffer for BIG data */ - char *tmp_key; /* Temporary Buffer for BIG keys */ - BUFHEAD *cpage; /* Current page */ - int cbucket; /* Current bucket */ - int cndx; /* Index of next item on cpage */ - int errno; /* Error Number -- for DBM compatability */ - int new_file; /* Indicates if fd is backing store or no */ - int save_file; /* Indicates whether we need to flush file at - * exit */ - u_long *mapp[NCACHED]; /* Pointers to page maps */ - int nmaps; /* Initial number of bitmaps */ - int nbufs; /* Number of buffers left to allocate */ - BUFHEAD bufhead; /* Header of buffer lru list */ - SEGMENT *dir; /* Hash Bucket directory */ + int flags; /* Flag values */ + int fp; /* File pointer */ + char *tmp_buf; /* Temporary Buffer for BIG data */ + char *tmp_key; /* Temporary Buffer for BIG keys */ + BUFHEAD *cpage; /* Current page */ + int cbucket; /* Current bucket */ + int cndx; /* Index of next item on cpage */ + int errno; /* Error Number -- for DBM + * compatability */ + int new_file; /* Indicates if fd is backing store + * or no */ + int save_file; /* Indicates whether we need to flush + * file at + * exit */ + u_int32_t *mapp[NCACHED]; /* Pointers to page maps */ + int nmaps; /* Initial number of bitmaps */ + int nbufs; /* Number of buffers left to + * allocate */ + BUFHEAD bufhead; /* Header of buffer lru list */ + SEGMENT *dir; /* Hash Bucket directory */ } HTAB; /* @@ -129,14 +138,14 @@ typedef struct htab { /* Memory resident data structure */ #define BYTE_SHIFT 3 #define INT_TO_BYTE 2 #define INT_BYTE_SHIFT 5 -#define ALL_SET ((u_int)0xFFFFFFFF) +#define ALL_SET ((u_int32_t)0xFFFFFFFF) #define ALL_CLEAR 0 -#define PTROF(X) ((BUFHEAD *)((u_int)(X)&~0x3)) -#define ISMOD(X) ((u_int)(X)&0x1) -#define DOMOD(X) ((X) = (char *)((u_int)(X)|0x1)) -#define ISDISK(X) ((u_int)(X)&0x2) -#define DODISK(X) ((X) = (char *)((u_int)(X)|0x2)) +#define PTROF(X) ((BUFHEAD *)((ptrdiff_t)(X)&~0x3)) +#define ISMOD(X) ((u_int32_t)(ptrdiff_t)(X)&0x1) +#define DOMOD(X) ((X) = (char *)((ptrdiff_t)(X)|0x1)) +#define ISDISK(X) ((u_int32_t)(ptrdiff_t)(X)&0x2) +#define DODISK(X) ((X) = (char *)((ptrdiff_t)(X)|0x2)) #define BITS_PER_MAP 32 @@ -156,9 +165,9 @@ typedef struct htab { /* Memory resident data structure */ #define SPLITSHIFT 11 #define SPLITMASK 0x7FF -#define SPLITNUM(N) (((u_int)(N)) >> SPLITSHIFT) +#define SPLITNUM(N) (((u_int32_t)(N)) >> SPLITSHIFT) #define OPAGENUM(N) ((N) & SPLITMASK) -#define OADDR_OF(S,O) ((u_int)((u_int)(S) << SPLITSHIFT) + (O)) +#define OADDR_OF(S,O) ((u_int32_t)((u_int32_t)(S) << SPLITSHIFT) + (O)) #define BUCKET_TO_PAGE(B) \ (B) + hashp->HDRPAGES + ((B) ? hashp->SPARES[__log2((B)+1)-1] : 0) diff --git a/lib/libc/db/hash/hash_bigkey.c b/lib/libc/db/hash/hash_bigkey.c index b747fbc..578314a 100644 --- a/lib/libc/db/hash/hash_bigkey.c +++ b/lib/libc/db/hash/hash_bigkey.c @@ -1,5 +1,5 @@ /*- - * 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 @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)hash_bigkey.c 8.2 (Berkeley) 2/21/94"; +static char sccsid[] = "@(#)hash_bigkey.c 8.3 (Berkeley) 5/31/94"; #endif /* LIBC_SCCS and not lint */ /* @@ -90,13 +90,13 @@ __big_insert(hashp, bufp, key, val) BUFHEAD *bufp; const DBT *key, *val; { - register u_short *p; + register 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; @@ -134,7 +134,7 @@ __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; } @@ -164,7 +164,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; @@ -189,12 +189,12 @@ __big_delete(hashp, bufp) BUFHEAD *bufp; { register BUFHEAD *last_bfp, *rbufp; - u_short *bp, pageno; + 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; @@ -217,7 +217,7 @@ __big_delete(hashp, bufp) last_bfp = rbufp; if (!rbufp) return (-1); /* Error. */ - bp = (u_short *)rbufp->page; + bp = (u_int16_t *)rbufp->page; } /* @@ -232,7 +232,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; @@ -270,13 +270,13 @@ __find_bigpair(hashp, bufp, ndx, key, size) char *key; int size; { - register u_short *bp; + register u_int16_t *bp; register 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; @@ -292,7 +292,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; } @@ -314,17 +314,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]; @@ -341,7 +341,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; @@ -364,15 +364,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; } @@ -380,7 +380,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]; @@ -401,7 +401,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; @@ -420,7 +420,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; @@ -452,14 +452,14 @@ collect_data(hashp, bufp, len, set) BUFHEAD *bufp; int len, set; { - register u_short *bp; + register u_int16_t *bp; register 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; @@ -479,7 +479,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; } @@ -531,10 +531,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; @@ -573,15 +573,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; + register 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; @@ -613,14 +613,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; @@ -636,7 +636,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) { /* diff --git a/lib/libc/db/hash/hash_buf.c b/lib/libc/db/hash/hash_buf.c index 1362c83..92e1f93 100644 --- a/lib/libc/db/hash/hash_buf.c +++ b/lib/libc/db/hash/hash_buf.c @@ -1,5 +1,5 @@ /*- - * 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 @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)hash_buf.c 8.2 (Berkeley) 2/21/94"; +static char sccsid[] = "@(#)hash_buf.c 8.5 (Berkeley) 7/15/94"; #endif /* LIBC_SCCS and not lint */ /* @@ -57,8 +57,10 @@ static char sccsid[] = "@(#)hash_buf.c 8.2 (Berkeley) 2/21/94"; #include <sys/param.h> #include <errno.h> +#include <stddef.h> #include <stdio.h> #include <stdlib.h> + #ifdef DEBUG #include <assert.h> #endif @@ -68,7 +70,7 @@ static char sccsid[] = "@(#)hash_buf.c 8.2 (Berkeley) 2/21/94"; #include "page.h" #include "extern.h" -static BUFHEAD *newbuf __P((HTAB *, u_int, BUFHEAD *)); +static BUFHEAD *newbuf __P((HTAB *, u_int32_t, BUFHEAD *)); /* Unlink B from its place in the lru */ #define BUF_REMOVE(B) { \ @@ -102,12 +104,12 @@ static BUFHEAD *newbuf __P((HTAB *, u_int, BUFHEAD *)); extern BUFHEAD * __get_buf(hashp, addr, prev_bp, newpage) HTAB *hashp; - u_int addr; + u_int32_t addr; BUFHEAD *prev_bp; int newpage; /* If prev_bp set, indicates a new overflow page. */ { register BUFHEAD *bp; - register u_int is_disk_mask; + register u_int32_t is_disk_mask; register int is_disk, segment_ndx; SEGMENT segp; @@ -140,7 +142,7 @@ __get_buf(hashp, addr, prev_bp, newpage) return (NULL); if (!prev_bp) segp[segment_ndx] = - (BUFHEAD *)((u_int)bp | is_disk_mask); + (BUFHEAD *)((ptrdiff_t)bp | is_disk_mask); } else { BUF_REMOVE(bp); MRU_INSERT(bp); @@ -157,7 +159,7 @@ __get_buf(hashp, addr, prev_bp, newpage) static BUFHEAD * newbuf(hashp, addr, prev_bp) HTAB *hashp; - u_int addr; + u_int32_t addr; BUFHEAD *prev_bp; { register BUFHEAD *bp; /* The buffer we're going to use */ @@ -165,7 +167,7 @@ newbuf(hashp, addr, prev_bp) register BUFHEAD *next_xbp; SEGMENT segp; int segment_ndx; - u_short oaddr, *shortp; + u_int16_t oaddr, *shortp; oaddr = 0; bp = LRU; @@ -177,10 +179,16 @@ newbuf(hashp, addr, prev_bp) /* Allocate a new one */ if ((bp = (BUFHEAD *)malloc(sizeof(BUFHEAD))) == NULL) return (NULL); +#ifdef PURIFY + memset(bp, 0xff, sizeof(BUFHEAD)); +#endif if ((bp->page = (char *)malloc(hashp->BSIZE)) == NULL) { free(bp); return (NULL); } +#ifdef PURIFY + memset(bp->page, 0xff, hashp->BSIZE); +#endif if (hashp->nbufs) hashp->nbufs--; } else { @@ -195,7 +203,7 @@ newbuf(hashp, addr, prev_bp) * Set oaddr before __put_page so that you get it * before bytes are swapped. */ - shortp = (u_short *)bp->page; + shortp = (u_int16_t *)bp->page; if (shortp[0]) oaddr = shortp[shortp[0] - 1]; if ((bp->flags & BUF_MOD) && __put_page(hashp, bp->page, @@ -238,7 +246,7 @@ newbuf(hashp, addr, prev_bp) (oaddr != xbp->addr)) break; - shortp = (u_short *)xbp->page; + shortp = (u_int16_t *)xbp->page; if (shortp[0]) /* set before __put_page */ oaddr = shortp[shortp[0] - 1]; diff --git a/lib/libc/db/hash/hash_log2.c b/lib/libc/db/hash/hash_log2.c index b773707..c8c56bf 100644 --- a/lib/libc/db/hash/hash_log2.c +++ b/lib/libc/db/hash/hash_log2.c @@ -1,5 +1,5 @@ /*- - * 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 @@ -35,16 +35,18 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)hash_log2.c 8.1 (Berkeley) 6/4/93"; +static char sccsid[] = "@(#)hash_log2.c 8.2 (Berkeley) 5/31/94"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> -u_int +#include <db.h> + +u_int32_t __log2(num) - u_int num; + u_int32_t num; { - register u_int i, limit; + register u_int32_t i, limit; limit = 1; for (i = 0; limit < num; limit = limit << 1, i++); diff --git a/lib/libc/db/hash/hash_page.c b/lib/libc/db/hash/hash_page.c index 2b2f572..e1dfe6b 100644 --- a/lib/libc/db/hash/hash_page.c +++ b/lib/libc/db/hash/hash_page.c @@ -1,5 +1,5 @@ /*- - * 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 @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)hash_page.c 8.4 (Berkeley) 2/21/94"; +static char sccsid[] = "@(#)hash_page.c 8.7 (Berkeley) 8/16/94"; #endif /* LIBC_SCCS and not lint */ /* @@ -72,19 +72,19 @@ static char sccsid[] = "@(#)hash_page.c 8.4 (Berkeley) 2/21/94"; #include "page.h" #include "extern.h" -static u_long *fetch_bitmap __P((HTAB *, int)); -static u_long first_free __P((u_long)); +static u_int32_t *fetch_bitmap __P((HTAB *, int)); +static u_int32_t first_free __P((u_int32_t)); static int open_temp __P((HTAB *)); -static u_short overflow_page __P((HTAB *)); +static u_int16_t overflow_page __P((HTAB *)); static void putpair __P((char *, const DBT *, const DBT *)); -static void squeeze_key __P((u_short *, const DBT *, const DBT *)); +static void squeeze_key __P((u_int16_t *, const DBT *, const DBT *)); static int ugly_split - __P((HTAB *, u_int, BUFHEAD *, BUFHEAD *, int, int)); + __P((HTAB *, u_int32_t, BUFHEAD *, BUFHEAD *, int, int)); #define PAGE_INIT(P) { \ - ((u_short *)(P))[0] = 0; \ - ((u_short *)(P))[1] = hashp->BSIZE - 3 * sizeof(u_short); \ - ((u_short *)(P))[2] = hashp->BSIZE; \ + ((u_int16_t *)(P))[0] = 0; \ + ((u_int16_t *)(P))[1] = hashp->BSIZE - 3 * sizeof(u_int16_t); \ + ((u_int16_t *)(P))[2] = hashp->BSIZE; \ } /* @@ -97,9 +97,9 @@ putpair(p, key, val) char *p; const DBT *key, *val; { - register u_short *bp, n, off; + register u_int16_t *bp, n, off; - bp = (u_short *)p; + bp = (u_int16_t *)p; /* Enter the key first. */ n = bp[0]; @@ -115,7 +115,7 @@ putpair(p, key, val) /* Adjust page info. */ bp[0] = n; - bp[n + 1] = off - ((n + 3) * sizeof(u_short)); + bp[n + 1] = off - ((n + 3) * sizeof(u_int16_t)); bp[n + 2] = off; } @@ -130,11 +130,11 @@ __delpair(hashp, bufp, ndx) BUFHEAD *bufp; register int ndx; { - register u_short *bp, newoff; + register u_int16_t *bp, newoff; register int n; - u_short pairlen; + u_int16_t pairlen; - bp = (u_short *)bufp->page; + bp = (u_int16_t *)bufp->page; n = bp[0]; if (bp[ndx + 1] < REAL_KEY) @@ -165,7 +165,7 @@ __delpair(hashp, bufp, ndx) } /* Finally adjust the page data */ bp[n] = OFFSET(bp) + pairlen; - bp[n - 1] = bp[n + 1] + pairlen + 2 * sizeof(u_short); + bp[n - 1] = bp[n + 1] + pairlen + 2 * sizeof(u_int16_t); bp[0] = n - 2; hashp->NKEYS--; @@ -180,18 +180,18 @@ __delpair(hashp, bufp, ndx) extern int __split_page(hashp, obucket, nbucket) HTAB *hashp; - u_int obucket, nbucket; + u_int32_t obucket, nbucket; { register BUFHEAD *new_bufp, *old_bufp; - register u_short *ino; + register u_int16_t *ino; register char *np; DBT key, val; int n, ndx, retval; - u_short copyto, diff, off, moved; + u_int16_t copyto, diff, off, moved; char *op; - copyto = (u_short)hashp->BSIZE; - off = (u_short)hashp->BSIZE; + copyto = (u_int16_t)hashp->BSIZE; + off = (u_int16_t)hashp->BSIZE; old_bufp = __get_buf(hashp, obucket, NULL, 0); if (old_bufp == NULL) return (-1); @@ -202,7 +202,7 @@ __split_page(hashp, obucket, nbucket) old_bufp->flags |= (BUF_MOD | BUF_PIN); new_bufp->flags |= (BUF_MOD | BUF_PIN); - ino = (u_short *)(op = old_bufp->page); + ino = (u_int16_t *)(op = old_bufp->page); np = new_bufp->page; moved = 0; @@ -244,13 +244,13 @@ __split_page(hashp, obucket, nbucket) /* Now clean up the page */ ino[0] -= moved; - FREESPACE(ino) = copyto - sizeof(u_short) * (ino[0] + 3); + FREESPACE(ino) = copyto - sizeof(u_int16_t) * (ino[0] + 3); OFFSET(ino) = copyto; #ifdef DEBUG3 (void)fprintf(stderr, "split %d/%d\n", - ((u_short *)np)[0] / 2, - ((u_short *)op)[0] / 2); + ((u_int16_t *)np)[0] / 2, + ((u_int16_t *)op)[0] / 2); #endif /* unpin both pages */ old_bufp->flags &= ~BUF_PIN; @@ -276,28 +276,28 @@ __split_page(hashp, obucket, nbucket) static int ugly_split(hashp, obucket, old_bufp, new_bufp, copyto, moved) HTAB *hashp; - u_int obucket; /* Same as __split_page. */ + u_int32_t obucket; /* Same as __split_page. */ BUFHEAD *old_bufp, *new_bufp; int copyto; /* First byte on page which contains key/data values. */ int moved; /* Number of pairs moved to new page. */ { register BUFHEAD *bufp; /* Buffer header for ino */ - register u_short *ino; /* Page keys come off of */ - register u_short *np; /* New page */ - register u_short *op; /* Page keys go on to if they aren't moving */ + register u_int16_t *ino; /* Page keys come off of */ + register u_int16_t *np; /* New page */ + register u_int16_t *op; /* Page keys go on to if they aren't moving */ BUFHEAD *last_bfp; /* Last buf header OVFL needing to be freed */ DBT key, val; SPLIT_RETURN ret; - u_short n, off, ov_addr, scopyto; + u_int16_t n, off, ov_addr, scopyto; char *cino; /* Character value of ino */ bufp = old_bufp; - ino = (u_short *)old_bufp->page; - np = (u_short *)new_bufp->page; - op = (u_short *)old_bufp->page; + ino = (u_int16_t *)old_bufp->page; + np = (u_int16_t *)new_bufp->page; + op = (u_int16_t *)old_bufp->page; last_bfp = NULL; - scopyto = (u_short)copyto; /* ANSI */ + scopyto = (u_int16_t)copyto; /* ANSI */ n = ino[0] - 1; while (n < ino[0]) { @@ -308,16 +308,16 @@ ugly_split(hashp, obucket, old_bufp, new_bufp, copyto, moved) old_bufp = ret.oldp; if (!old_bufp) return (-1); - op = (u_short *)old_bufp->page; + op = (u_int16_t *)old_bufp->page; new_bufp = ret.newp; if (!new_bufp) return (-1); - np = (u_short *)new_bufp->page; + np = (u_int16_t *)new_bufp->page; bufp = ret.nextp; if (!bufp) return (0); cino = (char *)bufp->page; - ino = (u_short *)cino; + ino = (u_int16_t *)cino; last_bfp = ret.nextp; } else if (ino[n + 1] == OVFLPAGE) { ov_addr = ino[n]; @@ -327,14 +327,14 @@ ugly_split(hashp, obucket, old_bufp, new_bufp, copyto, moved) */ ino[0] -= (moved + 2); FREESPACE(ino) = - scopyto - sizeof(u_short) * (ino[0] + 3); + scopyto - sizeof(u_int16_t) * (ino[0] + 3); OFFSET(ino) = scopyto; bufp = __get_buf(hashp, ov_addr, bufp, 0); if (!bufp) return (-1); - ino = (u_short *)bufp->page; + ino = (u_int16_t *)bufp->page; n = 1; scopyto = hashp->BSIZE; moved = 0; @@ -362,7 +362,7 @@ ugly_split(hashp, obucket, old_bufp, new_bufp, copyto, moved) __add_ovflpage(hashp, old_bufp); if (!old_bufp) return (-1); - op = (u_short *)old_bufp->page; + op = (u_int16_t *)old_bufp->page; putpair((char *)op, &key, &val); } old_bufp->flags |= BUF_MOD; @@ -375,7 +375,7 @@ ugly_split(hashp, obucket, old_bufp, new_bufp, copyto, moved) __add_ovflpage(hashp, new_bufp); if (!new_bufp) return (-1); - np = (u_short *)new_bufp->page; + np = (u_int16_t *)new_bufp->page; putpair((char *)np, &key, &val); } new_bufp->flags |= BUF_MOD; @@ -400,10 +400,10 @@ __addel(hashp, bufp, key, val) BUFHEAD *bufp; const DBT *key, *val; { - register u_short *bp, *sop; + register u_int16_t *bp, *sop; int do_expand; - bp = (u_short *)bufp->page; + bp = (u_int16_t *)bufp->page; do_expand = 0; while (bp[0] && (bp[2] < REAL_KEY || bp[bp[0]] < REAL_KEY)) /* Exception case */ @@ -415,7 +415,7 @@ __addel(hashp, bufp, key, val) 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 /* Try to squeeze key on this page */ if (FREESPACE(bp) > PAIRSIZE(key, val)) { @@ -425,7 +425,7 @@ __addel(hashp, bufp, key, val) 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; } if (PAIRFITS(bp, key, val)) @@ -435,7 +435,7 @@ __addel(hashp, bufp, key, val) bufp = __add_ovflpage(hashp, bufp); if (!bufp) return (-1); - sop = (u_short *)bufp->page; + sop = (u_int16_t *)bufp->page; if (PAIRFITS(sop, key, val)) putpair((char *)sop, key, val); @@ -466,12 +466,12 @@ __add_ovflpage(hashp, bufp) HTAB *hashp; BUFHEAD *bufp; { - register u_short *sp; - u_short ndx, ovfl_num; + register u_int16_t *sp; + u_int16_t ndx, ovfl_num; #ifdef DEBUG1 int tmp1, tmp2; #endif - sp = (u_short *)bufp->page; + sp = (u_int16_t *)bufp->page; /* Check if we are dynamically determining the fill factor */ if (hashp->FFACTOR == DEF_FFACTOR) { @@ -518,12 +518,12 @@ extern int __get_page(hashp, p, bucket, is_bucket, is_disk, is_bitmap) HTAB *hashp; char *p; - u_int bucket; + u_int32_t bucket; int is_bucket, is_disk, is_bitmap; { register int fd, page, size; int rsize; - u_short *bp; + u_int16_t *bp; fd = hashp->fp; size = hashp->BSIZE; @@ -539,7 +539,7 @@ __get_page(hashp, p, bucket, is_bucket, is_disk, is_bitmap) if ((lseek(fd, (off_t)page << hashp->BSHIFT, SEEK_SET) == -1) || ((rsize = read(fd, p, size)) == -1)) return (-1); - bp = (u_short *)p; + bp = (u_int16_t *)p; if (!rsize) bp[0] = 0; /* We hit the EOF, so initialize a new page */ else @@ -556,7 +556,7 @@ __get_page(hashp, p, bucket, is_bucket, is_disk, is_bitmap) if (is_bitmap) { max = hashp->BSIZE >> 2; /* divide by 4 */ for (i = 0; i < max; i++) - M_32_SWAP(((long *)p)[i]); + M_32_SWAP(((int *)p)[i]); } else { M_16_SWAP(bp[0]); max = bp[0] + 2; @@ -578,7 +578,7 @@ extern int __put_page(hashp, p, bucket, is_bucket, is_bitmap) HTAB *hashp; char *p; - u_int bucket; + u_int32_t bucket; int is_bucket, is_bitmap; { register int fd, page, size; @@ -596,11 +596,11 @@ __put_page(hashp, p, bucket, is_bucket, is_bitmap) if (is_bitmap) { max = hashp->BSIZE >> 2; /* divide by 4 */ for (i = 0; i < max; i++) - M_32_SWAP(((long *)p)[i]); + M_32_SWAP(((int *)p)[i]); } else { - max = ((u_short *)p)[0] + 2; + max = ((u_int16_t *)p)[0] + 2; for (i = 0; i <= max; i++) - M_16_SWAP(((u_short *)p)[i]); + M_16_SWAP(((u_int16_t *)p)[i]); } } if (is_bucket) @@ -624,14 +624,14 @@ __put_page(hashp, p, bucket, is_bucket, is_bitmap) * once they are read in. */ extern int -__init_bitmap(hashp, pnum, nbits, ndx) +__ibitmap(hashp, pnum, nbits, ndx) HTAB *hashp; int pnum, nbits, ndx; { - u_long *ip; + u_int32_t *ip; int clearbytes, clearints; - if ((ip = (u_long *)malloc(hashp->BSIZE)) == NULL) + if ((ip = (u_int32_t *)malloc(hashp->BSIZE)) == NULL) return (1); hashp->nmaps++; clearints = ((nbits - 1) >> INT_BYTE_SHIFT) + 1; @@ -641,16 +641,16 @@ __init_bitmap(hashp, pnum, nbits, ndx) hashp->BSIZE - clearbytes); ip[clearints - 1] = ALL_SET << (nbits & BYTE_MASK); SETBIT(ip, 0); - hashp->BITMAPS[ndx] = (u_short)pnum; + hashp->BITMAPS[ndx] = (u_int16_t)pnum; hashp->mapp[ndx] = ip; return (0); } -static u_long +static u_int32_t first_free(map) - u_long map; + u_int32_t map; { - register u_long i, mask; + register u_int32_t i, mask; mask = 0x1; for (i = 0; i < BITS_PER_MAP; i++) { @@ -661,13 +661,13 @@ first_free(map) return (i); } -static u_short +static u_int16_t overflow_page(hashp) HTAB *hashp; { - register u_long *freep; + register u_int32_t *freep; register int max_free, offset, splitnum; - u_short addr; + u_int16_t addr; int bit, first_page, free_bit, free_page, i, in_use_bits, j; #ifdef DEBUG2 int tmp1, tmp2; @@ -681,9 +681,9 @@ overflow_page(hashp) /* Look through all the free maps to find the first free block */ first_page = hashp->LAST_FREED >>(hashp->BSHIFT + BYTE_SHIFT); for ( i = first_page; i <= free_page; i++ ) { - if (!(freep = (u_long *)hashp->mapp[i]) && + if (!(freep = (u_int32_t *)hashp->mapp[i]) && !(freep = fetch_bitmap(hashp, i))) - return (NULL); + return (0); if (i == free_page) in_use_bits = free_bit; else @@ -713,7 +713,7 @@ overflow_page(hashp) if (offset > SPLITMASK) { if (++splitnum >= NCACHED) { (void)write(STDERR_FILENO, OVMSG, sizeof(OVMSG) - 1); - return (NULL); + return (0); } hashp->OVFL_POINT = splitnum; hashp->SPARES[splitnum] = hashp->SPARES[splitnum-1]; @@ -726,7 +726,7 @@ overflow_page(hashp) free_page++; if (free_page >= NCACHED) { (void)write(STDERR_FILENO, OVMSG, sizeof(OVMSG) - 1); - return (NULL); + return (0); } /* * This is tricky. The 1 indicates that you want the new page @@ -739,9 +739,9 @@ overflow_page(hashp) * don't have to if we tell init_bitmap not to leave it clear * in the first place. */ - if (__init_bitmap(hashp, (int)OADDR_OF(splitnum, offset), - 1, free_page)) - return (NULL); + if (__ibitmap(hashp, + (int)OADDR_OF(splitnum, offset), 1, free_page)) + return (0); hashp->SPARES[splitnum]++; #ifdef DEBUG2 free_bit = 2; @@ -751,7 +751,7 @@ overflow_page(hashp) if (++splitnum >= NCACHED) { (void)write(STDERR_FILENO, OVMSG, sizeof(OVMSG) - 1); - return (NULL); + return (0); } hashp->OVFL_POINT = splitnum; hashp->SPARES[splitnum] = hashp->SPARES[splitnum-1]; @@ -795,7 +795,7 @@ found: for (i = 0; (i < splitnum) && (bit > hashp->SPARES[i]); i++); offset = (i ? bit - hashp->SPARES[i - 1] : bit); if (offset >= SPLITMASK) - return (NULL); /* Out of overflow pages */ + return (0); /* Out of overflow pages */ addr = OADDR_OF(i, offset); #ifdef DEBUG2 (void)fprintf(stderr, "OVERFLOW_PAGE: ADDR: %d BIT: %d PAGE %d\n", @@ -814,16 +814,16 @@ __free_ovflpage(hashp, obufp) HTAB *hashp; BUFHEAD *obufp; { - register u_short addr; - u_long *freep; + register u_int16_t addr; + u_int32_t *freep; int bit_address, free_page, free_bit; - u_short ndx; + u_int16_t ndx; addr = obufp->addr; #ifdef DEBUG1 (void)fprintf(stderr, "Freeing %d\n", addr); #endif - ndx = (((u_short)addr) >> SPLITSHIFT); + ndx = (((u_int16_t)addr) >> SPLITSHIFT); bit_address = (ndx ? hashp->SPARES[ndx - 1] : 0) + (addr & SPLITMASK) - 1; if (bit_address < hashp->LAST_FREED) @@ -879,11 +879,11 @@ open_temp(hashp) */ static void squeeze_key(sp, key, val) - u_short *sp; + u_int16_t *sp; const DBT *key, *val; { register char *p; - u_short free_space, n, off, pageno; + u_int16_t free_space, n, off, pageno; p = (char *)sp; n = sp[0]; @@ -904,14 +904,14 @@ squeeze_key(sp, key, val) OFFSET(sp) = off; } -static u_long * +static u_int32_t * fetch_bitmap(hashp, ndx) HTAB *hashp; int ndx; { if (ndx >= hashp->nmaps) return (NULL); - if ((hashp->mapp[ndx] = (u_long *)malloc(hashp->BSIZE)) == NULL) + if ((hashp->mapp[ndx] = (u_int32_t *)malloc(hashp->BSIZE)) == NULL) return (NULL); if (__get_page(hashp, (char *)hashp->mapp[ndx], hashp->BITMAPS[ndx], 0, 1, 1)) { diff --git a/lib/libc/db/hash/hsearch.c b/lib/libc/db/hash/hsearch.c index e4914b1..cc8f7a4 100644 --- a/lib/libc/db/hash/hsearch.c +++ b/lib/libc/db/hash/hsearch.c @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)hsearch.c 8.3 (Berkeley) 2/21/94"; +static char sccsid[] = "@(#)hsearch.c 8.4 (Berkeley) 7/21/94"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -58,7 +58,7 @@ hcreate(nel) info.nelem = nel; info.bsize = 256; info.ffactor = 8; - info.cachesize = NULL; + info.cachesize = 0; info.hash = NULL; info.lorder = 0; dbp = (DB *)__hash_open(NULL, O_CREAT | O_RDWR, 0600, &info, 0); diff --git a/lib/libc/db/hash/ndbm.c b/lib/libc/db/hash/ndbm.c index 89b9916..2cbbe91 100644 --- a/lib/libc/db/hash/ndbm.c +++ b/lib/libc/db/hash/ndbm.c @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)ndbm.c 8.2 (Berkeley) 9/11/93"; +static char sccsid[] = "@(#)ndbm.c 8.4 (Berkeley) 7/21/94"; #endif /* LIBC_SCCS and not lint */ /* @@ -45,10 +45,10 @@ static char sccsid[] = "@(#)ndbm.c 8.2 (Berkeley) 9/11/93"; #include <sys/param.h> -#include <ndbm.h> #include <stdio.h> #include <string.h> +#include <ndbm.h> #include "hash.h" /* @@ -67,7 +67,7 @@ dbm_open(file, flags, mode) info.bsize = 4096; info.ffactor = 40; info.nelem = 1; - info.cachesize = NULL; + info.cachesize = 0; info.hash = NULL; info.lorder = 0; (void)strcpy(path, file); diff --git a/lib/libc/db/hash/page.h b/lib/libc/db/hash/page.h index dae82ae..0fc0d5a 100644 --- a/lib/libc/db/hash/page.h +++ b/lib/libc/db/hash/page.h @@ -1,5 +1,5 @@ /*- - * 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 @@ -33,7 +33,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)page.h 8.1 (Berkeley) 6/6/93 + * @(#)page.h 8.2 (Berkeley) 5/31/94 */ /* @@ -73,20 +73,20 @@ * You might as well do this up front. */ -#define PAIRSIZE(K,D) (2*sizeof(u_short) + (K)->size + (D)->size) -#define BIGOVERHEAD (4*sizeof(u_short)) -#define KEYSIZE(K) (4*sizeof(u_short) + (K)->size); -#define OVFLSIZE (2*sizeof(u_short)) +#define PAIRSIZE(K,D) (2*sizeof(u_int16_t) + (K)->size + (D)->size) +#define BIGOVERHEAD (4*sizeof(u_int16_t)) +#define KEYSIZE(K) (4*sizeof(u_int16_t) + (K)->size); +#define OVFLSIZE (2*sizeof(u_int16_t)) #define FREESPACE(P) ((P)[(P)[0]+1]) #define OFFSET(P) ((P)[(P)[0]+2]) #define PAIRFITS(P,K,D) \ (((P)[2] >= REAL_KEY) && \ (PAIRSIZE((K),(D)) + OVFLSIZE) <= FREESPACE((P))) -#define PAGE_META(N) (((N)+3) * sizeof(u_short)) +#define PAGE_META(N) (((N)+3) * sizeof(u_int16_t)) typedef struct { BUFHEAD *newp; BUFHEAD *oldp; BUFHEAD *nextp; - u_short next_addr; + u_int16_t next_addr; } SPLIT_RETURN; |