Lines Matching +full:big +full:-

1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
38 * Big key/data handling for the hashing package.
75 * You need to do an insert and the key/data pair is too big
79 *-1 ==> ERROR
90 cp = bufp->page; /* Character pointer of p. */ in __big_insert()
93 key_data = (char *)key->data; in __big_insert()
94 key_size = key->size; in __big_insert()
95 val_data = (char *)val->data; in __big_insert()
96 val_size = val->size; in __big_insert()
99 for (space = FREESPACE(p) - BIGOVERHEAD; key_size; in __big_insert()
100 space = FREESPACE(p) - BIGOVERHEAD) { in __big_insert()
102 off = OFFSET(p) - move_bytes; in __big_insert()
104 key_size -= move_bytes; in __big_insert()
109 FREESPACE(p) = off - PAGE_META(n); in __big_insert()
114 return (-1); in __big_insert()
125 * non-zero would fail. in __big_insert()
127 if (space == val_size && val_size == val->size) in __big_insert()
129 off = OFFSET(p) - move_bytes; in __big_insert()
132 val_size -= move_bytes; in __big_insert()
134 p[n - 2] = FULL_KEY_DATA; in __big_insert()
135 FREESPACE(p) = FREESPACE(p) - move_bytes; in __big_insert()
139 p[n - 2] = FULL_KEY; in __big_insert()
142 p = (u_int16_t *)bufp->page; in __big_insert()
143 cp = bufp->page; in __big_insert()
144 bufp->flags |= BUF_MOD; in __big_insert()
148 for (space = FREESPACE(p) - BIGOVERHEAD; val_size; in __big_insert()
149 space = FREESPACE(p) - BIGOVERHEAD) { in __big_insert()
155 if (space == val_size && val_size == val->size) in __big_insert()
156 move_bytes--; in __big_insert()
157 off = OFFSET(p) - move_bytes; in __big_insert()
159 val_size -= move_bytes; in __big_insert()
164 FREESPACE(p) = off - PAGE_META(n); in __big_insert()
170 return (-1); in __big_insert()
171 cp = bufp->page; in __big_insert()
175 bufp->flags |= BUF_MOD; in __big_insert()
183 * All pages in the big key/data pair except bufp are freed. We cannot
189 *-1 => ERROR
200 bp = (u_int16_t *)bufp->page; in __big_delete()
215 pageno = bp[bp[0] - 1]; in __big_delete()
216 rbufp->flags |= BUF_MOD; in __big_delete()
222 return (-1); /* Error. */ in __big_delete()
223 bp = (u_int16_t *)rbufp->page; in __big_delete()
227 * If we get here then rbufp points to the last page of the big in __big_delete()
228 * key/data pair. Bufp points to the first one -- it should now be in __big_delete()
235 pageno = bp[n - 1]; in __big_delete()
238 bp = (u_int16_t *)bufp->page; in __big_delete()
243 bufp->ovfl = rbufp->ovfl; in __big_delete()
246 bufp->ovfl = NULL; in __big_delete()
247 n -= 2; in __big_delete()
249 FREESPACE(bp) = hashp->BSIZE - PAGE_META(n); in __big_delete()
250 OFFSET(bp) = hashp->BSIZE; in __big_delete()
252 bufp->flags |= BUF_MOD; in __big_delete()
258 hashp->NKEYS--; in __big_delete()
264 * -1 = get next overflow page
265 * -2 means key not found and this is big key/data
266 * -3 error
277 bp = (u_int16_t *)bufp->page; in __find_bigpair()
278 p = bufp->page; in __find_bigpair()
282 for (bytes = hashp->BSIZE - bp[ndx]; in __find_bigpair()
284 bytes = hashp->BSIZE - bp[ndx]) { in __find_bigpair()
286 return (-2); in __find_bigpair()
288 ksize -= bytes; in __find_bigpair()
291 return (-3); in __find_bigpair()
292 p = bufp->page; in __find_bigpair()
301 return (-2); in __find_bigpair()
307 * Given the buffer pointer of the first overflow page of a big pair,
308 * find the end of the big pair
310 * This will set bpp to the buffer header of the last page of the big pair.
312 * of the pair; 0 if there isn't any (i.e. big pair is the last key in the
323 bp = (u_int16_t *)bufp->page; in __find_last_page()
336 pageno = bp[n - 1]; in __find_last_page()
340 bp = (u_int16_t *)bufp->page; in __find_last_page()
361 bp = (u_int16_t *)bufp->page; in __big_return()
363 bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); in __big_return()
365 return (-1); in __big_return()
366 bp = (u_int16_t *)bufp->page; in __big_return()
371 bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); in __big_return()
373 return (-1); in __big_return()
374 bp = (u_int16_t *)bufp->page; in __big_return()
376 save_addr = save_p->addr; in __big_return()
389 len = bp[1] - off; in __big_return()
391 save_addr = bufp->addr; in __big_return()
392 bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); in __big_return()
394 return (-1); in __big_return()
395 bp = (u_int16_t *)bufp->page; in __big_return()
400 val->data = (u_char *)tp + off; in __big_return()
401 val->size = bp[1] - off; in __big_return()
405 hashp->cpage = NULL; in __big_return()
406 hashp->cbucket++; in __big_return()
407 hashp->cndx = 1; in __big_return()
409 hashp->cpage = __get_buf(hashp, in __big_return()
410 bp[bp[0] - 1], bufp, 0); in __big_return()
411 if (!hashp->cpage) in __big_return()
412 return (-1); in __big_return()
413 hashp->cndx = 1; in __big_return()
415 hashp->cpage->page)[0]) { in __big_return()
416 hashp->cbucket++; in __big_return()
417 hashp->cpage = NULL; in __big_return()
424 val->size = (size_t)collect_data(hashp, bufp, (int)len, set_current); in __big_return()
425 if (val->size == (size_t)-1) in __big_return()
426 return (-1); in __big_return()
427 if (save_p->addr != save_addr) { in __big_return()
430 return (-1); in __big_return()
432 memmove(hashp->tmp_buf, (save_p->page) + off, len); in __big_return()
433 val->data = (u_char *)hashp->tmp_buf; in __big_return()
437 * Count how big the total datasize is by recursing through the pages. Then
449 p = bufp->page; in collect_data()
451 mylen = hashp->BSIZE - bp[1]; in collect_data()
452 save_addr = bufp->addr; in collect_data()
456 if (hashp->tmp_buf) in collect_data()
457 free(hashp->tmp_buf); in collect_data()
458 if ((hashp->tmp_buf = (char *)malloc(totlen)) == NULL) in collect_data()
459 return (-1); in collect_data()
461 hashp->cndx = 1; in collect_data()
463 hashp->cpage = NULL; in collect_data()
464 hashp->cbucket++; in collect_data()
466 hashp->cpage = in collect_data()
467 __get_buf(hashp, bp[bp[0] - 1], bufp, 0); in collect_data()
468 if (!hashp->cpage) in collect_data()
469 return (-1); in collect_data()
470 else if (!((u_int16_t *)hashp->cpage->page)[0]) { in collect_data()
471 hashp->cbucket++; in collect_data()
472 hashp->cpage = NULL; in collect_data()
477 xbp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); in collect_data()
480 return (-1); in collect_data()
482 if (bufp->addr != save_addr) { in collect_data()
484 return (-1); in collect_data()
486 memmove(&hashp->tmp_buf[len], (bufp->page) + bp[1], mylen); in collect_data()
491 * Fill in the key and data for this big pair.
496 key->size = (size_t)collect_key(hashp, bufp, 0, val, set); in __big_keydata()
497 if (key->size == (size_t)-1) in __big_keydata()
498 return (-1); in __big_keydata()
499 key->data = (u_char *)hashp->tmp_key; in __big_keydata()
504 * Count how big the total key size is by recursing through the pages. Then
515 p = bufp->page; in collect_key()
517 mylen = hashp->BSIZE - bp[1]; in collect_key()
519 save_addr = bufp->addr; in collect_key()
522 if (hashp->tmp_key != NULL) in collect_key()
523 free(hashp->tmp_key); in collect_key()
524 if ((hashp->tmp_key = (char *)malloc(totlen)) == NULL) in collect_key()
525 return (-1); in collect_key()
527 return (-1); in collect_key()
529 xbp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); in collect_key()
532 return (-1); in collect_key()
534 if (bufp->addr != save_addr) { in collect_key()
535 errno = EINVAL; /* MIS -- OUT OF BUFFERS */ in collect_key()
536 return (-1); in collect_key()
538 memmove(&hashp->tmp_key[len], (bufp->page) + bp[1], mylen); in collect_key()
545 * -1 => error
551 BUFHEAD *big_keyp, /* Pointer to first page containing the big key/data */ in __big_split()
563 /* Now figure out where the big key/data goes */ in __big_split()
565 return (-1); in __big_split()
568 if ( (ret->next_addr = __find_last_page(hashp, &big_keyp)) ) { in __big_split()
569 if (!(ret->nextp = in __big_split()
570 __get_buf(hashp, ret->next_addr, big_keyp, 0))) in __big_split()
571 return (-1); in __big_split()
573 ret->nextp = NULL; in __big_split()
575 /* Now make one of np/op point to the big key/data pair */ in __big_split()
577 assert(np->ovfl == NULL); in __big_split()
584 tmpp->flags |= BUF_MOD; in __big_split()
587 "BIG_SPLIT: %d->ovfl was %d is now %d\n", tmpp->addr, in __big_split()
588 (tmpp->ovfl ? tmpp->ovfl->addr : 0), (bp ? bp->addr : 0)); in __big_split()
590 tmpp->ovfl = bp; /* one of op/np point to big_keyp */ in __big_split()
591 tp = (u_int16_t *)tmpp->page; in __big_split()
602 FREESPACE(tp) = free_space - OVFLSIZE; in __big_split()
606 * pointer to the last page of the big key_data pair. Make sure that in __big_split()
611 ret->newp = np; in __big_split()
612 ret->oldp = op; in __big_split()
614 tp = (u_int16_t *)big_keyp->page; in __big_split()
615 big_keyp->flags |= BUF_MOD; in __big_split()
627 tp[0] -= 2; in __big_split()
632 return (-1); in __big_split()
638 ret->newp = tmpp; in __big_split()
640 ret->oldp = tmpp; in __big_split()