Lines Matching refs:hashp
100 HTAB *hashp; in __hash_open() local
111 if (!(hashp = calloc(1, sizeof(HTAB)))) in __hash_open()
113 hashp->fp = -1; in __hash_open()
121 hashp->flags = flags; in __hash_open()
131 if ((hashp->fp = __dbopen(file, flags, mode, &statbuf)) == -1) in __hash_open()
136 if (!(hashp = init_hash(hashp, file, info))) in __hash_open()
141 hashp->hash = info->hash; in __hash_open()
143 hashp->hash = __default_hash; in __hash_open()
145 hdrsize = read(hashp->fp, &hashp->hdr, sizeof(HASHHDR)); in __hash_open()
147 swap_header(hashp); in __hash_open()
154 if (hashp->MAGIC != HASHMAGIC) in __hash_open()
157 if (hashp->VERSION != HASHVERSION && in __hash_open()
158 hashp->VERSION != OLDHASHVERSION) in __hash_open()
160 if (hashp->hash(CHARKEY, sizeof(CHARKEY)) != in __hash_open()
161 (uint32_t)hashp->H_CHARKEY) in __hash_open()
168 nsegs = (hashp->MAX_BUCKET + 1 + hashp->SGSIZE - 1) / in __hash_open()
169 hashp->SGSIZE; in __hash_open()
170 hashp->nsegs = 0; in __hash_open()
171 if (alloc_segs(hashp, nsegs)) in __hash_open()
178 bpages = (hashp->SPARES[hashp->OVFL_POINT] + in __hash_open()
179 (unsigned int)(hashp->BSIZE << BYTE_SHIFT) - 1) >> in __hash_open()
180 (hashp->BSHIFT + BYTE_SHIFT); in __hash_open()
182 hashp->nmaps = bpages; in __hash_open()
183 (void)memset(&hashp->mapp[0], 0, bpages * sizeof(uint32_t *)); in __hash_open()
188 __buf_init(hashp, info->cachesize); in __hash_open()
190 __buf_init(hashp, DEF_BUFSIZE); in __hash_open()
192 hashp->new_file = new_table; in __hash_open()
193 hashp->save_file = file && (hashp->flags & O_RDWR); in __hash_open()
194 hashp->cbucket = -1; in __hash_open()
197 hdestroy(hashp); in __hash_open()
201 dbp->internal = hashp; in __hash_open()
215 "TABLE POINTER ", hashp, in __hash_open()
216 "BUCKET SIZE ", hashp->BSIZE, in __hash_open()
217 "BUCKET SHIFT ", hashp->BSHIFT, in __hash_open()
218 "DIRECTORY SIZE ", hashp->DSIZE, in __hash_open()
219 "SEGMENT SIZE ", hashp->SGSIZE, in __hash_open()
220 "SEGMENT SHIFT ", hashp->SSHIFT, in __hash_open()
221 "FILL FACTOR ", hashp->FFACTOR, in __hash_open()
222 "MAX BUCKET ", hashp->MAX_BUCKET, in __hash_open()
223 "OVFL POINT ", hashp->OVFL_POINT, in __hash_open()
224 "LAST FREED ", hashp->LAST_FREED, in __hash_open()
225 "HIGH MASK ", hashp->HIGH_MASK, in __hash_open()
226 "LOW MASK ", hashp->LOW_MASK, in __hash_open()
227 "NSEGS ", hashp->nsegs, in __hash_open()
228 "NKEYS ", hashp->NKEYS); in __hash_open()
236 if (hashp != NULL) in __hash_open()
237 (void)close(hashp->fp); in __hash_open()
240 free(hashp); in __hash_open()
248 HTAB *hashp; in hash_close() local
254 hashp = dbp->internal; in hash_close()
255 retval = hdestroy(hashp); in hash_close()
263 HTAB *hashp; in hash_fd() local
268 hashp = dbp->internal; in hash_fd()
269 if (hashp->fp == -1) { in hash_fd()
273 return (hashp->fp); in hash_fd()
278 init_hash(HTAB *hashp, const char *file, const HASHINFO *info) in init_hash() argument
284 hashp->NKEYS = 0; in init_hash()
285 hashp->LORDER = BYTE_ORDER; in init_hash()
286 hashp->BSIZE = DEF_BUCKET_SIZE; in init_hash()
287 hashp->BSHIFT = DEF_BUCKET_SHIFT; in init_hash()
288 hashp->SGSIZE = DEF_SEGSIZE; in init_hash()
289 hashp->SSHIFT = DEF_SEGSIZE_SHIFT; in init_hash()
290 hashp->DSIZE = DEF_DIRSIZE; in init_hash()
291 hashp->FFACTOR = DEF_FFACTOR; in init_hash()
292 hashp->hash = __default_hash; in init_hash()
293 memset(hashp->SPARES, 0, sizeof(hashp->SPARES)); in init_hash()
294 memset(hashp->BITMAPS, 0, sizeof (hashp->BITMAPS)); in init_hash()
300 hashp->BSIZE = MIN(statbuf.st_blksize, MAX_BSIZE); in init_hash()
301 hashp->BSHIFT = __log2((uint32_t)hashp->BSIZE); in init_hash()
307 hashp->BSHIFT = __log2(info->bsize); in init_hash()
308 hashp->BSIZE = 1 << hashp->BSHIFT; in init_hash()
309 if (hashp->BSIZE > MAX_BSIZE) { in init_hash()
315 hashp->FFACTOR = info->ffactor; in init_hash()
317 hashp->hash = info->hash; in init_hash()
326 hashp->LORDER = info->lorder; in init_hash()
330 if (init_htab(hashp, (size_t)nelem)) in init_hash()
333 return (hashp); in init_hash()
342 init_htab(HTAB *hashp, size_t nelem) in init_htab() argument
353 nelem = (nelem - 1) / hashp->FFACTOR + 1; in init_htab()
359 hashp->SPARES[l2] = l2 + 1; in init_htab()
360 hashp->SPARES[l2 + 1] = l2 + 1; in init_htab()
361 hashp->OVFL_POINT = l2; in init_htab()
362 hashp->LAST_FREED = 2; in init_htab()
365 if (__ibitmap(hashp, (int)OADDR_OF(l2, 1), l2 + 1, 0)) in init_htab()
368 hashp->MAX_BUCKET = hashp->LOW_MASK = nbuckets - 1; in init_htab()
369 hashp->HIGH_MASK = (nbuckets << 1) - 1; in init_htab()
371 hashp->HDRPAGES = ((MAX(sizeof(HASHHDR), MINHDRSIZE) - 1) >> in init_htab()
372 hashp->BSHIFT) + 1; in init_htab()
374 nsegs = (nbuckets - 1) / hashp->SGSIZE + 1; in init_htab()
377 if (nsegs > (uint32_t)hashp->DSIZE) in init_htab()
378 hashp->DSIZE = nsegs; in init_htab()
379 return (alloc_segs(hashp, (int)nsegs)); in init_htab()
389 hdestroy(HTAB *hashp) in hdestroy() argument
403 hashp->NKEYS, hashp->MAX_BUCKET, hashp->nsegs); in hdestroy()
407 "spares[%d] = %d\n", i, hashp->SPARES[i]); in hdestroy()
413 if (__buf_free(hashp, 1, hashp->save_file)) in hdestroy()
415 if (hashp->dir) { in hdestroy()
416 free(*hashp->dir); /* Free initial segments */ in hdestroy()
418 while (hashp->exsegs--) in hdestroy()
419 free(hashp->dir[--hashp->nsegs]); in hdestroy()
420 free(hashp->dir); in hdestroy()
422 if (flush_meta(hashp) && !save_errno) in hdestroy()
425 for (i = 0; i < hashp->nmaps; i++) in hdestroy()
426 if (hashp->mapp[i]) in hdestroy()
427 free(hashp->mapp[i]); in hdestroy()
429 if (hashp->fp != -1) in hdestroy()
430 (void)close(hashp->fp); in hdestroy()
432 free(hashp); in hdestroy()
450 HTAB *hashp; in hash_sync() local
460 hashp = dbp->internal; in hash_sync()
461 if (!hashp->save_file) in hash_sync()
463 if (__buf_free(hashp, 0, 1) || flush_meta(hashp)) in hash_sync()
465 hashp->new_file = 0; in hash_sync()
475 flush_meta(HTAB *hashp) in flush_meta() argument
484 if (!hashp->save_file) in flush_meta()
486 hashp->MAGIC = HASHMAGIC; in flush_meta()
487 hashp->VERSION = HASHVERSION; in flush_meta()
488 hashp->H_CHARKEY = hashp->hash(CHARKEY, sizeof(CHARKEY)); in flush_meta()
490 fp = hashp->fp; in flush_meta()
491 whdrp = &hashp->hdr; in flush_meta()
494 swap_header_copy(&hashp->hdr, whdrp); in flush_meta()
501 hashp->err = errno; in flush_meta()
505 if (hashp->mapp[i]) in flush_meta()
506 if (__put_page(hashp, (char *)(void *)hashp->mapp[i], in flush_meta()
507 (u_int)hashp->BITMAPS[i], 0, 1)) in flush_meta()
524 HTAB *hashp; in hash_get() local
526 hashp = dbp->internal; in hash_get()
528 hashp->err = errno = EINVAL; in hash_get()
531 return (hash_access(hashp, HASH_GET, __UNCONST(key), data)); in hash_get()
537 HTAB *hashp; in hash_put() local
539 hashp = dbp->internal; in hash_put()
541 hashp->err = errno = EINVAL; in hash_put()
544 if ((hashp->flags & O_ACCMODE) == O_RDONLY) { in hash_put()
545 hashp->err = errno = EPERM; in hash_put()
549 return (hash_access(hashp, flag == R_NOOVERWRITE ? in hash_put()
556 HTAB *hashp; in hash_delete() local
558 hashp = dbp->internal; in hash_delete()
560 hashp->err = errno = EINVAL; in hash_delete()
563 if ((hashp->flags & O_ACCMODE) == O_RDONLY) { in hash_delete()
564 hashp->err = errno = EPERM; in hash_delete()
567 return hash_access(hashp, HASH_DELETE, __UNCONST(key), NULL); in hash_delete()
574 hash_access(HTAB *hashp, ACTION action, DBT *key, DBT *val) in hash_access() argument
588 off = HASH_BSIZE(hashp); in hash_access()
591 rbufp = __get_buf(hashp, __call_hash(hashp, kp, (int)size), NULL, 0); in hash_access()
611 rbufp = __get_buf(hashp, (uint32_t)*bp, rbufp, 0); in hash_access()
620 off = HASH_BSIZE(hashp); in hash_access()
623 __find_bigpair(hashp, rbufp, ndx, kp, (int)size)) > 0) in hash_access()
628 __find_last_page(hashp, &bufp))) { in hash_access()
633 rbufp = __get_buf(hashp, (uint32_t)pageno, in hash_access()
643 off = HASH_BSIZE(hashp); in hash_access()
654 if (__addel(hashp, rbufp, key, val)) { in hash_access()
676 if (__big_return(hashp, rbufp, ndx, val, 0)) in hash_access()
684 if ((__delpair(hashp, rbufp, ndx)) || in hash_access()
685 (__addel(hashp, rbufp, key, val))) { in hash_access()
691 if (__delpair(hashp, rbufp, ndx)) in hash_access()
699 if (ndx != hashp->cndx - 2 || rbufp != hashp->cpage) in hash_access()
702 if (hashp->cndx > 1) { in hash_access()
704 hashp->cndx -= 2; in hash_access()
710 hashp->cbucket--; in hash_access()
711 hashp->cpage = NULL; in hash_access()
712 hashp->cndx = -1; in hash_access()
727 HTAB *hashp; in hash_seq() local
730 hashp = dbp->internal; in hash_seq()
732 hashp->err = errno = EINVAL; in hash_seq()
738 if ((hashp->cbucket < 0) || (flag == R_FIRST)) { in hash_seq()
739 hashp->cbucket = 0; in hash_seq()
740 hashp->cndx = 1; in hash_seq()
741 hashp->cpage = NULL; in hash_seq()
746 if (!(bufp = hashp->cpage)) { in hash_seq()
747 for (bucket = hashp->cbucket; in hash_seq()
748 bucket <= (uint32_t)hashp->MAX_BUCKET; in hash_seq()
750 bufp = __get_buf(hashp, bucket, NULL, 0); in hash_seq()
753 hashp->cpage = bufp; in hash_seq()
758 hashp->cbucket = bucket; in hash_seq()
759 if (hashp->cbucket > hashp->MAX_BUCKET) { in hash_seq()
760 hashp->cbucket = -1; in hash_seq()
763 if (hashp->cndx == -1) { in hash_seq()
765 hashp->cndx = 1; in hash_seq()
766 while (bp[hashp->cndx - 1] != 0) in hash_seq()
767 hashp->cndx += 2; in hash_seq()
770 hashp->cndx = 1; in hash_seq()
775 if (hashp->cndx > bp[0]) { in hash_seq()
776 hashp->cpage = NULL; in hash_seq()
777 hashp->cbucket++; in hash_seq()
778 hashp->cndx = 1; in hash_seq()
787 while (bp[hashp->cndx + 1] == OVFLPAGE) { in hash_seq()
788 bufp = hashp->cpage = in hash_seq()
789 __get_buf(hashp, (uint32_t)bp[hashp->cndx], bufp, in hash_seq()
794 hashp->cndx = 1; in hash_seq()
797 hashp->cpage = NULL; in hash_seq()
798 ++hashp->cbucket; in hash_seq()
801 ndx = hashp->cndx; in hash_seq()
803 if (__big_keydata(hashp, bufp, key, data, 1)) in hash_seq()
805 hashp->cndx = 1; in hash_seq()
807 if (hashp->cpage == NULL) in hash_seq()
809 key->data = (uint8_t *)hashp->cpage->page + bp[ndx]; in hash_seq()
810 key->size = (ndx > 1 ? bp[ndx - 1] : HASH_BSIZE(hashp)) - bp[ndx]; in hash_seq()
811 data->data = (uint8_t *)hashp->cpage->page + bp[ndx + 1]; in hash_seq()
813 hashp->cndx += 2; in hash_seq()
826 __expand_table(HTAB *hashp) in __expand_table() argument
835 new_bucket = ++hashp->MAX_BUCKET; in __expand_table()
836 old_bucket = (hashp->MAX_BUCKET & hashp->LOW_MASK); in __expand_table()
838 new_segnum = new_bucket >> hashp->SSHIFT; in __expand_table()
841 if (new_segnum >= hashp->nsegs) { in __expand_table()
843 if (new_segnum >= hashp->DSIZE) { in __expand_table()
845 dirsize = hashp->DSIZE * sizeof(SEGMENT *); in __expand_table()
846 if (!hash_realloc(&hashp->dir, dirsize, dirsize << 1)) in __expand_table()
850 hashp->DSIZE = (uint32_t)dirsize; in __expand_table()
852 if ((hashp->dir[new_segnum] = in __expand_table()
853 calloc((size_t)hashp->SGSIZE, sizeof(SEGMENT))) == NULL) in __expand_table()
855 hashp->exsegs++; in __expand_table()
856 hashp->nsegs++; in __expand_table()
863 spare_ndx = __log2((uint32_t)(hashp->MAX_BUCKET + 1)); in __expand_table()
864 if (spare_ndx > hashp->OVFL_POINT) { in __expand_table()
865 hashp->SPARES[spare_ndx] = hashp->SPARES[hashp->OVFL_POINT]; in __expand_table()
866 hashp->OVFL_POINT = spare_ndx; in __expand_table()
869 if (new_bucket > (uint32_t)hashp->HIGH_MASK) { in __expand_table()
871 hashp->LOW_MASK = hashp->HIGH_MASK; in __expand_table()
872 hashp->HIGH_MASK = new_bucket | hashp->LOW_MASK; in __expand_table()
875 return (__split_page(hashp, old_bucket, new_bucket)); in __expand_table()
897 __call_hash(HTAB *hashp, char *k, int len) in __call_hash() argument
901 n = hashp->hash(k, (size_t)len); in __call_hash()
902 bucket = n & hashp->HIGH_MASK; in __call_hash()
903 if (bucket > hashp->MAX_BUCKET) in __call_hash()
904 bucket = bucket & hashp->LOW_MASK; in __call_hash()
914 alloc_segs(HTAB *hashp, int nsegs) in alloc_segs() argument
921 hashp->dir = calloc((size_t)hashp->DSIZE, sizeof(SEGMENT *)); in alloc_segs()
922 if (hashp->dir == NULL) { in alloc_segs()
924 (void)hdestroy(hashp); in alloc_segs()
928 hashp->nsegs = nsegs; in alloc_segs()
932 store = calloc((size_t)(nsegs << hashp->SSHIFT), sizeof(SEGMENT)); in alloc_segs()
935 (void)hdestroy(hashp); in alloc_segs()
940 hashp->dir[i] = &store[i << hashp->SSHIFT]; in alloc_segs()
977 swap_header(HTAB *hashp) in swap_header() argument
982 hdrp = &hashp->hdr; in swap_header()