2 * Copyright (c) 1990, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 #if defined(LIBC_SCCS) && !defined(lint)
38 static char sccsid
[] = "@(#)hash.c 8.9 (Berkeley) 6/16/94";
39 #endif /* LIBC_SCCS and not lint */
41 #include <sys/param.h>
59 static int alloc_segs
__P((HTAB
*, int));
60 static int flush_meta
__P((HTAB
*));
61 static int hash_access
__P((HTAB
*, ACTION
, DBT
*, DBT
*));
62 static int hash_close
__P((DB
*));
63 static int hash_delete
__P((const DB
*, const DBT
*, u_int32_t
));
64 static int hash_fd
__P((const DB
*));
65 static int hash_get
__P((const DB
*, const DBT
*, DBT
*, u_int32_t
));
66 static int hash_put
__P((const DB
*, DBT
*, const DBT
*, u_int32_t
));
67 static void *hash_realloc
__P((SEGMENT
**, int, int));
68 static int hash_seq
__P((const DB
*, DBT
*, DBT
*, u_int32_t
));
69 static int hash_sync
__P((const DB
*, u_int32_t
));
70 static int hdestroy
__P((HTAB
*));
71 static HTAB
*init_hash
__P((HTAB
*, const char *, HASHINFO
*));
72 static int init_htab
__P((HTAB
*, int));
73 #if BYTE_ORDER == LITTLE_ENDIAN
74 static void swap_header
__P((HTAB
*));
75 static void swap_header_copy
__P((HASHHDR
*, HASHHDR
*));
78 /* Fast arithmetic, relying on powers of 2, */
79 #define MOD(x, y) ((x) & ((y) - 1))
81 #define RETURN_ERROR(ERR, LOC) { save_errno = ERR; goto LOC; }
88 #ifdef HASH_STATISTICS
89 int hash_accesses
, hash_collisions
, hash_expansions
, hash_overflows
;
92 /************************** INTERFACE ROUTINES ***************************/
96 __hash_open(file
, flags
, mode
, info
, dflags
)
98 int flags
, mode
, dflags
;
99 const HASHINFO
*info
; /* Special directives for create */
104 int bpages
, hdrsize
, new_table
, nsegs
, save_errno
;
106 if ((flags
& O_ACCMODE
) == O_WRONLY
) {
111 if (!(hashp
= (HTAB
*)calloc(1, sizeof(HTAB
))))
116 * Even if user wants write only, we need to be able to read
117 * the actual file, so we need to open it read/write. But, the
118 * field in the hashp structure needs to be accurate so that
119 * we can check accesses.
121 hashp
->flags
= flags
;
124 if (!file
|| (flags
& O_TRUNC
) ||
125 (stat(file
, &statbuf
) && (errno
== ENOENT
))) {
127 errno
= 0; /* Just in case someone looks at errno */
131 if ((hashp
->fp
= open(file
, flags
, mode
)) == -1)
132 RETURN_ERROR(errno
, error0
);
133 (void)fcntl(hashp
->fp
, F_SETFD
, 1);
136 if (!(hashp
= init_hash(hashp
, file
, (HASHINFO
*)info
)))
137 RETURN_ERROR(errno
, error1
);
139 /* Table already exists */
140 if (info
&& info
->hash
)
141 hashp
->hash
= info
->hash
;
143 hashp
->hash
= __default_hash
;
145 hdrsize
= read(hashp
->fp
, &hashp
->hdr
, sizeof(HASHHDR
));
146 #if BYTE_ORDER == LITTLE_ENDIAN
150 RETURN_ERROR(errno
, error1
);
151 if (hdrsize
!= sizeof(HASHHDR
))
152 RETURN_ERROR(EFTYPE
, error1
);
153 /* Verify file type, versions and hash function */
154 if (hashp
->MAGIC
!= HASHMAGIC
)
155 RETURN_ERROR(EFTYPE
, error1
);
156 #define OLDHASHVERSION 1
157 if (hashp
->VERSION
!= HASHVERSION
&&
158 hashp
->VERSION
!= OLDHASHVERSION
)
159 RETURN_ERROR(EFTYPE
, error1
);
160 if (hashp
->hash(CHARKEY
, sizeof(CHARKEY
)) != hashp
->H_CHARKEY
)
161 RETURN_ERROR(EFTYPE
, error1
);
163 * Figure out how many segments we need. Max_Bucket is the
164 * maximum bucket number, so the number of buckets is
167 nsegs
= (hashp
->MAX_BUCKET
+ 1 + hashp
->SGSIZE
- 1) /
170 if (alloc_segs(hashp
, nsegs
))
172 * If alloc_segs fails, table will have been destroyed
173 * and errno will have been set.
176 /* Read in bitmaps */
177 bpages
= (hashp
->SPARES
[hashp
->OVFL_POINT
] +
178 (hashp
->BSIZE
<< BYTE_SHIFT
) - 1) >>
179 (hashp
->BSHIFT
+ BYTE_SHIFT
);
181 hashp
->nmaps
= bpages
;
182 (void)memset(&hashp
->mapp
[0], 0, bpages
* sizeof(u_int32_t
*));
185 /* Initialize Buffer Manager */
186 if (info
&& info
->cachesize
)
187 __buf_init(hashp
, info
->cachesize
);
189 __buf_init(hashp
, DEF_BUFSIZE
);
191 hashp
->new_file
= new_table
;
192 hashp
->save_file
= file
&& (hashp
->flags
& O_RDWR
);
194 if (!(dbp
= (DB
*)malloc(sizeof(DB
)))) {
200 dbp
->internal
= hashp
;
201 dbp
->close
= hash_close
;
202 dbp
->del
= hash_delete
;
207 dbp
->sync
= hash_sync
;
211 (void)fprintf(stderr
,
212 "%s\n%s%x\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n%s%x\n%s%x\n%s%d\n%s%d\n",
214 "TABLE POINTER ", hashp
,
215 "BUCKET SIZE ", hashp
->BSIZE
,
216 "BUCKET SHIFT ", hashp
->BSHIFT
,
217 "DIRECTORY SIZE ", hashp
->DSIZE
,
218 "SEGMENT SIZE ", hashp
->SGSIZE
,
219 "SEGMENT SHIFT ", hashp
->SSHIFT
,
220 "FILL FACTOR ", hashp
->FFACTOR
,
221 "MAX BUCKET ", hashp
->MAX_BUCKET
,
222 "OVFL POINT ", hashp
->OVFL_POINT
,
223 "LAST FREED ", hashp
->LAST_FREED
,
224 "HIGH MASK ", hashp
->HIGH_MASK
,
225 "LOW MASK ", hashp
->LOW_MASK
,
226 "NSEGS ", hashp
->nsegs
,
227 "NKEYS ", hashp
->NKEYS
);
229 #ifdef HASH_STATISTICS
230 hash_overflows
= hash_accesses
= hash_collisions
= hash_expansions
= 0;
236 (void)close(hashp
->fp
);
254 hashp
= (HTAB
*)dbp
->internal
;
255 retval
= hdestroy(hashp
);
269 hashp
= (HTAB
*)dbp
->internal
;
270 if (hashp
->fp
== -1) {
277 /************************** LOCAL CREATION ROUTINES **********************/
279 init_hash(hashp
, file
, info
)
289 hashp
->LORDER
= BYTE_ORDER
;
290 hashp
->BSIZE
= DEF_BUCKET_SIZE
;
291 hashp
->BSHIFT
= DEF_BUCKET_SHIFT
;
292 hashp
->SGSIZE
= DEF_SEGSIZE
;
293 hashp
->SSHIFT
= DEF_SEGSIZE_SHIFT
;
294 hashp
->DSIZE
= DEF_DIRSIZE
;
295 hashp
->FFACTOR
= DEF_FFACTOR
;
296 hashp
->hash
= __default_hash
;
297 memset(hashp
->SPARES
, 0, sizeof(hashp
->SPARES
));
298 memset(hashp
->BITMAPS
, 0, sizeof (hashp
->BITMAPS
));
300 /* Fix bucket size to be optimal for file system */
302 if (stat(file
, &statbuf
))
304 hashp
->BSIZE
= statbuf
.st_blksize
;
305 hashp
->BSHIFT
= __log2(hashp
->BSIZE
);
310 /* Round pagesize up to power of 2 */
311 hashp
->BSHIFT
= __log2(info
->bsize
);
312 hashp
->BSIZE
= 1 << hashp
->BSHIFT
;
313 if (hashp
->BSIZE
> MAX_BSIZE
) {
319 hashp
->FFACTOR
= info
->ffactor
;
321 hashp
->hash
= info
->hash
;
325 if (info
->lorder
!= BIG_ENDIAN
&&
326 info
->lorder
!= LITTLE_ENDIAN
) {
330 hashp
->LORDER
= info
->lorder
;
333 /* init_htab should destroy the table and set errno if it fails */
334 if (init_htab(hashp
, nelem
))
340 * This calls alloc_segs which may run out of memory. Alloc_segs will destroy
341 * the table and set errno, so we just pass the error information along.
343 * Returns 0 on No Error
346 init_htab(hashp
, nelem
)
350 register int nbuckets
, nsegs
;
354 * Divide number of elements by the fill factor and determine a
355 * desired number of buckets. Allocate space for the next greater
356 * power of two number of buckets.
358 nelem
= (nelem
- 1) / hashp
->FFACTOR
+ 1;
360 l2
= __log2(MAX(nelem
, 2));
363 hashp
->SPARES
[l2
] = l2
+ 1;
364 hashp
->SPARES
[l2
+ 1] = l2
+ 1;
365 hashp
->OVFL_POINT
= l2
;
366 hashp
->LAST_FREED
= 2;
368 /* First bitmap page is at: splitpoint l2 page offset 1 */
369 if (__ibitmap(hashp
, OADDR_OF(l2
, 1), l2
+ 1, 0))
372 hashp
->MAX_BUCKET
= hashp
->LOW_MASK
= nbuckets
- 1;
373 hashp
->HIGH_MASK
= (nbuckets
<< 1) - 1;
374 hashp
->HDRPAGES
= ((MAX(sizeof(HASHHDR
), MINHDRSIZE
) - 1) >>
377 nsegs
= (nbuckets
- 1) / hashp
->SGSIZE
+ 1;
378 nsegs
= 1 << __log2(nsegs
);
380 if (nsegs
> hashp
->DSIZE
)
381 hashp
->DSIZE
= nsegs
;
382 return (alloc_segs(hashp
, nsegs
));
385 /********************** DESTROY/CLOSE ROUTINES ************************/
388 * Flushes any changes to the file if necessary and destroys the hashp
389 * structure, freeing all allocated space.
399 #ifdef HASH_STATISTICS
400 (void)fprintf(stderr
, "hdestroy: accesses %ld collisions %ld\n",
401 hash_accesses
, hash_collisions
);
402 (void)fprintf(stderr
, "hdestroy: expansions %ld\n",
404 (void)fprintf(stderr
, "hdestroy: overflows %ld\n",
406 (void)fprintf(stderr
, "keys %ld maxp %d segmentcount %d\n",
407 hashp
->NKEYS
, hashp
->MAX_BUCKET
, hashp
->nsegs
);
409 for (i
= 0; i
< NCACHED
; i
++)
410 (void)fprintf(stderr
,
411 "spares[%d] = %d\n", i
, hashp
->SPARES
[i
]);
414 * Call on buffer manager to free buffers, and if required,
415 * write them to disk.
417 if (__buf_free(hashp
, 1, hashp
->save_file
))
420 free(*hashp
->dir
); /* Free initial segments */
421 /* Free extra segments */
422 while (hashp
->exsegs
--)
423 free(hashp
->dir
[--hashp
->nsegs
]);
426 if (flush_meta(hashp
) && !save_errno
)
429 for (i
= 0; i
< hashp
->nmaps
; i
++)
431 free(hashp
->mapp
[i
]);
434 (void)close(hashp
->fp
);
445 * Write modified pages to disk
452 hash_sync(dbp
, flags
)
466 hashp
= (HTAB
*)dbp
->internal
;
467 if (!hashp
->save_file
)
469 if (__buf_free(hashp
, 0, 1) || flush_meta(hashp
))
478 * -1 indicates that errno should be set
485 #if BYTE_ORDER == LITTLE_ENDIAN
490 if (!hashp
->save_file
)
492 hashp
->MAGIC
= HASHMAGIC
;
493 hashp
->VERSION
= HASHVERSION
;
494 hashp
->H_CHARKEY
= hashp
->hash(CHARKEY
, sizeof(CHARKEY
));
498 #if BYTE_ORDER == LITTLE_ENDIAN
500 swap_header_copy(&hashp
->hdr
, whdrp
);
502 if ((lseek(fp
, (off_t
)0, SEEK_SET
) == -1) ||
503 ((wsize
= write(fp
, whdrp
, sizeof(HASHHDR
))) == -1))
506 if (wsize
!= sizeof(HASHHDR
)) {
508 hashp
->_errno
= errno
;
511 for (i
= 0; i
< NCACHED
; i
++)
513 if (__put_page(hashp
, (char *)hashp
->mapp
[i
],
514 hashp
->BITMAPS
[i
], 0, 1))
519 /*******************************SEARCH ROUTINES *****************************/
521 * All the access routines return
525 * 1 to indicate an external ERROR (i.e. key not found, etc)
526 * -1 to indicate an internal ERROR (i.e. out of memory, etc)
529 hash_get(dbp
, key
, data
, flag
)
537 hashp
= (HTAB
*)dbp
->internal
;
539 hashp
->_errno
= errno
= EINVAL
;
542 return (hash_access(hashp
, HASH_GET
, (DBT
*)key
, data
));
546 hash_put(dbp
, key
, data
, flag
)
554 hashp
= (HTAB
*)dbp
->internal
;
555 if (flag
&& flag
!= R_NOOVERWRITE
) {
556 hashp
->_errno
= errno
= EINVAL
;
559 if ((hashp
->flags
& O_ACCMODE
) == O_RDONLY
) {
560 hashp
->_errno
= errno
= EPERM
;
563 return (hash_access(hashp
, flag
== R_NOOVERWRITE
?
564 HASH_PUTNEW
: HASH_PUT
, (DBT
*)key
, (DBT
*)data
));
568 hash_delete(dbp
, key
, flag
)
571 u_int32_t flag
; /* Ignored */
575 hashp
= (HTAB
*)dbp
->internal
;
576 if (flag
&& flag
!= R_CURSOR
) {
577 hashp
->_errno
= errno
= EINVAL
;
580 if ((hashp
->flags
& O_ACCMODE
) == O_RDONLY
) {
581 hashp
->_errno
= errno
= EPERM
;
584 return (hash_access(hashp
, HASH_DELETE
, (DBT
*)key
, NULL
));
588 * Assume that hashp has been set in wrapper routine.
591 hash_access(hashp
, action
, key
, val
)
596 register BUFHEAD
*rbufp
;
597 BUFHEAD
*bufp
, *save_bufp
;
598 register u_int16_t
*bp
;
599 register int n
, ndx
, off
, size
;
603 #ifdef HASH_STATISTICS
609 kp
= (char *)key
->data
;
610 rbufp
= __get_buf(hashp
, __call_hash(hashp
, kp
, size
), NULL
, 0);
615 /* Pin the bucket chain */
616 rbufp
->flags
|= BUF_PIN
;
617 for (bp
= (u_int16_t
*)rbufp
->page
, n
= *bp
++, ndx
= 1; ndx
< n
;)
618 if (bp
[1] >= REAL_KEY
) {
619 /* Real key/data pair */
620 if (size
== off
- *bp
&&
621 memcmp(kp
, rbufp
->page
+ *bp
, size
) == 0)
624 #ifdef HASH_STATISTICS
629 } else if (bp
[1] == OVFLPAGE
) {
630 rbufp
= __get_buf(hashp
, *bp
, rbufp
, 0);
632 save_bufp
->flags
&= ~BUF_PIN
;
636 bp
= (u_int16_t
*)rbufp
->page
;
640 } else if (bp
[1] < REAL_KEY
) {
642 __find_bigpair(hashp
, rbufp
, ndx
, kp
, size
)) > 0)
647 __find_last_page(hashp
, &bufp
))) {
652 rbufp
= __get_buf(hashp
, pageno
, bufp
, 0);
654 save_bufp
->flags
&= ~BUF_PIN
;
658 bp
= (u_int16_t
*)rbufp
->page
;
663 save_bufp
->flags
&= ~BUF_PIN
;
672 if (__addel(hashp
, rbufp
, key
, val
)) {
673 save_bufp
->flags
&= ~BUF_PIN
;
676 save_bufp
->flags
&= ~BUF_PIN
;
682 save_bufp
->flags
&= ~BUF_PIN
;
689 save_bufp
->flags
&= ~BUF_PIN
;
692 bp
= (u_int16_t
*)rbufp
->page
;
693 if (bp
[ndx
+ 1] < REAL_KEY
) {
694 if (__big_return(hashp
, rbufp
, ndx
, val
, 0))
697 val
->data
= (u_char
*)rbufp
->page
+ (int)bp
[ndx
+ 1];
698 val
->size
= bp
[ndx
] - bp
[ndx
+ 1];
702 if ((__delpair(hashp
, rbufp
, ndx
)) ||
703 (__addel(hashp
, rbufp
, key
, val
))) {
704 save_bufp
->flags
&= ~BUF_PIN
;
709 if (__delpair(hashp
, rbufp
, ndx
))
715 save_bufp
->flags
&= ~BUF_PIN
;
720 hash_seq(dbp
, key
, data
, flag
)
725 register u_int32_t bucket
;
726 register BUFHEAD
*bufp
;
730 hashp
= (HTAB
*)dbp
->internal
;
731 if (flag
&& flag
!= R_FIRST
&& flag
!= R_NEXT
) {
732 hashp
->_errno
= errno
= EINVAL
;
735 #ifdef HASH_STATISTICS
738 if ((hashp
->cbucket
< 0) || (flag
== R_FIRST
)) {
744 for (bp
= NULL
; !bp
|| !bp
[0]; ) {
745 if (!(bufp
= hashp
->cpage
)) {
746 for (bucket
= hashp
->cbucket
;
747 bucket
<= hashp
->MAX_BUCKET
;
748 bucket
++, hashp
->cndx
= 1) {
749 bufp
= __get_buf(hashp
, bucket
, NULL
, 0);
753 bp
= (u_int16_t
*)bufp
->page
;
757 hashp
->cbucket
= bucket
;
758 if (hashp
->cbucket
> hashp
->MAX_BUCKET
) {
763 bp
= (u_int16_t
*)hashp
->cpage
->page
;
769 while (bp
[hashp
->cndx
+ 1] == OVFLPAGE
) {
770 bufp
= hashp
->cpage
=
771 __get_buf(hashp
, bp
[hashp
->cndx
], bufp
, 0);
774 bp
= (u_int16_t
*)(bufp
->page
);
783 if (bp
[ndx
+ 1] < REAL_KEY
) {
784 if (__big_keydata(hashp
, bufp
, key
, data
, 1))
787 key
->data
= (u_char
*)hashp
->cpage
->page
+ bp
[ndx
];
788 key
->size
= (ndx
> 1 ? bp
[ndx
- 1] : hashp
->BSIZE
) - bp
[ndx
];
789 data
->data
= (u_char
*)hashp
->cpage
->page
+ bp
[ndx
+ 1];
790 data
->size
= bp
[ndx
] - bp
[ndx
+ 1];
802 /********************************* UTILITIES ************************/
810 __expand_table(hashp
)
813 u_int32_t old_bucket
, new_bucket
;
814 int dirsize
, new_segnum
, spare_ndx
;
816 #ifdef HASH_STATISTICS
819 new_bucket
= ++hashp
->MAX_BUCKET
;
820 old_bucket
= (hashp
->MAX_BUCKET
& hashp
->LOW_MASK
);
822 new_segnum
= new_bucket
>> hashp
->SSHIFT
;
824 /* Check if we need a new segment */
825 if (new_segnum
>= hashp
->nsegs
) {
826 /* Check if we need to expand directory */
827 if (new_segnum
>= hashp
->DSIZE
) {
828 /* Reallocate directory */
829 dirsize
= hashp
->DSIZE
* sizeof(SEGMENT
*);
830 if (!hash_realloc(&hashp
->dir
, dirsize
, dirsize
<< 1))
832 hashp
->DSIZE
= dirsize
<< 1;
834 if ((hashp
->dir
[new_segnum
] =
835 (SEGMENT
)calloc(hashp
->SGSIZE
, sizeof(SEGMENT
))) == NULL
)
841 * If the split point is increasing (MAX_BUCKET's log base 2
842 * * increases), we need to copy the current contents of the spare
843 * split bucket to the next bucket.
845 spare_ndx
= __log2(hashp
->MAX_BUCKET
+ 1);
846 if (spare_ndx
> hashp
->OVFL_POINT
) {
847 hashp
->SPARES
[spare_ndx
] = hashp
->SPARES
[hashp
->OVFL_POINT
];
848 hashp
->OVFL_POINT
= spare_ndx
;
851 if (new_bucket
> hashp
->HIGH_MASK
) {
852 /* Starting a new doubling */
853 hashp
->LOW_MASK
= hashp
->HIGH_MASK
;
854 hashp
->HIGH_MASK
= new_bucket
| hashp
->LOW_MASK
;
856 /* Relocate records to the new bucket */
857 return (__split_page(hashp
, old_bucket
, new_bucket
));
861 * If realloc guarantees that the pointer is not destroyed if the realloc
862 * fails, then this routine can go away.
865 hash_realloc(p_ptr
, oldsize
, newsize
)
867 int oldsize
, newsize
;
871 if (p
= malloc(newsize
)) {
872 memmove(p
, *p_ptr
, oldsize
);
873 memset((char *)p
+ oldsize
, 0, newsize
- oldsize
);
881 __call_hash(hashp
, k
, len
)
888 n
= hashp
->hash(k
, len
);
889 bucket
= n
& hashp
->HIGH_MASK
;
890 if (bucket
> hashp
->MAX_BUCKET
)
891 bucket
= bucket
& hashp
->LOW_MASK
;
896 * Allocate segment table. On error, destroy the table and set errno.
898 * Returns 0 on success
901 alloc_segs(hashp
, nsegs
)
906 register SEGMENT store
;
911 (SEGMENT
*)calloc(hashp
->DSIZE
, sizeof(SEGMENT
*))) == NULL
) {
913 (void)hdestroy(hashp
);
917 /* Allocate segments */
919 (SEGMENT
)calloc(nsegs
<< hashp
->SSHIFT
, sizeof(SEGMENT
))) == NULL
) {
921 (void)hdestroy(hashp
);
925 for (i
= 0; i
< nsegs
; i
++, hashp
->nsegs
++)
926 hashp
->dir
[i
] = &store
[i
<< hashp
->SSHIFT
];
930 #if BYTE_ORDER == LITTLE_ENDIAN
932 * Hashp->hdr needs to be byteswapped.
935 swap_header_copy(srcp
, destp
)
936 HASHHDR
*srcp
, *destp
;
940 P_32_COPY(srcp
->magic
, destp
->magic
);
941 P_32_COPY(srcp
->version
, destp
->version
);
942 P_32_COPY(srcp
->lorder
, destp
->lorder
);
943 P_32_COPY(srcp
->bsize
, destp
->bsize
);
944 P_32_COPY(srcp
->bshift
, destp
->bshift
);
945 P_32_COPY(srcp
->dsize
, destp
->dsize
);
946 P_32_COPY(srcp
->ssize
, destp
->ssize
);
947 P_32_COPY(srcp
->sshift
, destp
->sshift
);
948 P_32_COPY(srcp
->ovfl_point
, destp
->ovfl_point
);
949 P_32_COPY(srcp
->last_freed
, destp
->last_freed
);
950 P_32_COPY(srcp
->max_bucket
, destp
->max_bucket
);
951 P_32_COPY(srcp
->high_mask
, destp
->high_mask
);
952 P_32_COPY(srcp
->low_mask
, destp
->low_mask
);
953 P_32_COPY(srcp
->ffactor
, destp
->ffactor
);
954 P_32_COPY(srcp
->nkeys
, destp
->nkeys
);
955 P_32_COPY(srcp
->hdrpages
, destp
->hdrpages
);
956 P_32_COPY(srcp
->h_charkey
, destp
->h_charkey
);
957 for (i
= 0; i
< NCACHED
; i
++) {
958 P_32_COPY(srcp
->spares
[i
], destp
->spares
[i
]);
959 P_16_COPY(srcp
->bitmaps
[i
], destp
->bitmaps
[i
]);
972 M_32_SWAP(hdrp
->magic
);
973 M_32_SWAP(hdrp
->version
);
974 M_32_SWAP(hdrp
->lorder
);
975 M_32_SWAP(hdrp
->bsize
);
976 M_32_SWAP(hdrp
->bshift
);
977 M_32_SWAP(hdrp
->dsize
);
978 M_32_SWAP(hdrp
->ssize
);
979 M_32_SWAP(hdrp
->sshift
);
980 M_32_SWAP(hdrp
->ovfl_point
);
981 M_32_SWAP(hdrp
->last_freed
);
982 M_32_SWAP(hdrp
->max_bucket
);
983 M_32_SWAP(hdrp
->high_mask
);
984 M_32_SWAP(hdrp
->low_mask
);
985 M_32_SWAP(hdrp
->ffactor
);
986 M_32_SWAP(hdrp
->nkeys
);
987 M_32_SWAP(hdrp
->hdrpages
);
988 M_32_SWAP(hdrp
->h_charkey
);
989 for (i
= 0; i
< NCACHED
; i
++) {
990 M_32_SWAP(hdrp
->spares
[i
]);
991 M_16_SWAP(hdrp
->bitmaps
[i
]);