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 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) { |
542 hashp->error = errno = EINVAL; |
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 } |
721 next_bucket: |
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 } |
740 } else { |
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 } |
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]; |
779 } 780 return (SUCCESS); 781} 782 783/********************************* UTILITIES ************************/ 784 785/* 786 * Returns: --- 179 unchanged lines hidden --- |