hash.c (190489) | hash.c (190491) |
---|---|
1/*- 2 * Copyright (c) 1990, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Margo Seltzer. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 20 unchanged lines hidden (view full) --- 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 */ 32 33#if defined(LIBC_SCCS) && !defined(lint) 34static char sccsid[] = "@(#)hash.c 8.9 (Berkeley) 6/16/94"; 35#endif /* LIBC_SCCS and not lint */ 36#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1990, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Margo Seltzer. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 20 unchanged lines hidden (view full) --- 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 */ 32 33#if defined(LIBC_SCCS) && !defined(lint) 34static char sccsid[] = "@(#)hash.c 8.9 (Berkeley) 6/16/94"; 35#endif /* LIBC_SCCS and not lint */ 36#include <sys/cdefs.h> |
37__FBSDID("$FreeBSD: head/lib/libc/db/hash/hash.c 190489 2009-03-28 06:23:10Z delphij $"); | 37__FBSDID("$FreeBSD: head/lib/libc/db/hash/hash.c 190491 2009-03-28 06:30:43Z delphij $"); |
38 39#include "namespace.h" 40#include <sys/param.h> 41#include <sys/stat.h> 42 43#include <errno.h> 44#include <fcntl.h> 45#include <stdio.h> --- 488 unchanged lines hidden (view full) --- 534 535static int 536hash_put(const DB *dbp, DBT *key, const DBT *data, u_int32_t flag) 537{ 538 HTAB *hashp; 539 540 hashp = (HTAB *)dbp->internal; 541 if (flag && flag != R_NOOVERWRITE) { | 38 39#include "namespace.h" 40#include <sys/param.h> 41#include <sys/stat.h> 42 43#include <errno.h> 44#include <fcntl.h> 45#include <stdio.h> --- 488 unchanged lines hidden (view full) --- 534 535static int 536hash_put(const DB *dbp, DBT *key, const DBT *data, u_int32_t flag) 537{ 538 HTAB *hashp; 539 540 hashp = (HTAB *)dbp->internal; 541 if (flag && flag != R_NOOVERWRITE) { |
542 hashp->error = EINVAL; 543 errno = EINVAL; | 542 hashp->error = errno = EINVAL; |
544 return (ERROR); 545 } 546 if ((hashp->flags & O_ACCMODE) == O_RDONLY) { 547 hashp->error = errno = EPERM; 548 return (ERROR); 549 } 550 return (hash_access(hashp, flag == R_NOOVERWRITE ? 551 HASH_PUTNEW : HASH_PUT, (DBT *)key, (DBT *)data)); --- 162 unchanged lines hidden (view full) --- 714#ifdef HASH_STATISTICS 715 hash_accesses++; 716#endif 717 if ((hashp->cbucket < 0) || (flag == R_FIRST)) { 718 hashp->cbucket = 0; 719 hashp->cndx = 1; 720 hashp->cpage = NULL; 721 } | 543 return (ERROR); 544 } 545 if ((hashp->flags & O_ACCMODE) == O_RDONLY) { 546 hashp->error = errno = EPERM; 547 return (ERROR); 548 } 549 return (hash_access(hashp, flag == R_NOOVERWRITE ? 550 HASH_PUTNEW : HASH_PUT, (DBT *)key, (DBT *)data)); --- 162 unchanged lines hidden (view full) --- 713#ifdef HASH_STATISTICS 714 hash_accesses++; 715#endif 716 if ((hashp->cbucket < 0) || (flag == R_FIRST)) { 717 hashp->cbucket = 0; 718 hashp->cndx = 1; 719 hashp->cpage = NULL; 720 } |
722 | 721 next_bucket: |
723 for (bp = NULL; !bp || !bp[0]; ) { 724 if (!(bufp = hashp->cpage)) { 725 for (bucket = hashp->cbucket; 726 bucket <= hashp->MAX_BUCKET; 727 bucket++, hashp->cndx = 1) { 728 bufp = __get_buf(hashp, bucket, NULL, 0); 729 if (!bufp) 730 return (ERROR); 731 hashp->cpage = bufp; 732 bp = (u_int16_t *)bufp->page; 733 if (bp[0]) 734 break; 735 } 736 hashp->cbucket = bucket; 737 if ((u_int32_t)hashp->cbucket > hashp->MAX_BUCKET) { 738 hashp->cbucket = -1; 739 return (ABNORMAL); 740 } | 722 for (bp = NULL; !bp || !bp[0]; ) { 723 if (!(bufp = hashp->cpage)) { 724 for (bucket = hashp->cbucket; 725 bucket <= hashp->MAX_BUCKET; 726 bucket++, hashp->cndx = 1) { 727 bufp = __get_buf(hashp, bucket, NULL, 0); 728 if (!bufp) 729 return (ERROR); 730 hashp->cpage = bufp; 731 bp = (u_int16_t *)bufp->page; 732 if (bp[0]) 733 break; 734 } 735 hashp->cbucket = bucket; 736 if ((u_int32_t)hashp->cbucket > hashp->MAX_BUCKET) { 737 hashp->cbucket = -1; 738 return (ABNORMAL); 739 } |
741 } else | 740 } else { |
742 bp = (u_int16_t *)hashp->cpage->page; | 741 bp = (u_int16_t *)hashp->cpage->page; |
742 if (flag == R_NEXT) { 743 hashp->cndx += 2; 744 if (hashp->cndx > bp[0]) { 745 hashp->cpage = NULL; 746 hashp->cbucket++; 747 hashp->cndx = 1; 748 goto next_bucket; 749 } 750 } 751 } |
|
743 744#ifdef DEBUG 745 assert(bp); 746 assert(bufp); 747#endif 748 while (bp[hashp->cndx + 1] == OVFLPAGE) { 749 bufp = hashp->cpage = 750 __get_buf(hashp, bp[hashp->cndx], bufp, 0); --- 11 unchanged lines hidden (view full) --- 762 if (bp[ndx + 1] < REAL_KEY) { 763 if (__big_keydata(hashp, bufp, key, data, 1)) 764 return (ERROR); 765 } else { 766 key->data = (u_char *)hashp->cpage->page + bp[ndx]; 767 key->size = (ndx > 1 ? bp[ndx - 1] : hashp->BSIZE) - bp[ndx]; 768 data->data = (u_char *)hashp->cpage->page + bp[ndx + 1]; 769 data->size = bp[ndx] - bp[ndx + 1]; | 752 753#ifdef DEBUG 754 assert(bp); 755 assert(bufp); 756#endif 757 while (bp[hashp->cndx + 1] == OVFLPAGE) { 758 bufp = hashp->cpage = 759 __get_buf(hashp, bp[hashp->cndx], bufp, 0); --- 11 unchanged lines hidden (view full) --- 771 if (bp[ndx + 1] < REAL_KEY) { 772 if (__big_keydata(hashp, bufp, key, data, 1)) 773 return (ERROR); 774 } else { 775 key->data = (u_char *)hashp->cpage->page + bp[ndx]; 776 key->size = (ndx > 1 ? bp[ndx - 1] : hashp->BSIZE) - bp[ndx]; 777 data->data = (u_char *)hashp->cpage->page + bp[ndx + 1]; 778 data->size = bp[ndx] - bp[ndx + 1]; |
770 ndx += 2; 771 if (ndx > bp[0]) { 772 hashp->cpage = NULL; 773 hashp->cbucket++; 774 hashp->cndx = 1; 775 } else 776 hashp->cndx = ndx; | |
777 } 778 return (SUCCESS); 779} 780 781/********************************* UTILITIES ************************/ 782 783/* 784 * Returns: --- 179 unchanged lines hidden --- | 779 } 780 return (SUCCESS); 781} 782 783/********************************* UTILITIES ************************/ 784 785/* 786 * Returns: --- 179 unchanged lines hidden --- |