hash_bigkey.c (1573) | hash_bigkey.c (14272) |
---|---|
1/*- | 1/*- |
2 * Copyright (c) 1990, 1993 | 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 9 * modification, are permitted provided that the following conditions 10 * are met: --- 19 unchanged lines hidden (view full) --- 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 34 * SUCH DAMAGE. 35 */ 36 37#if defined(LIBC_SCCS) && !defined(lint) | 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 9 * modification, are permitted provided that the following conditions 10 * are met: --- 19 unchanged lines hidden (view full) --- 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 34 * SUCH DAMAGE. 35 */ 36 37#if defined(LIBC_SCCS) && !defined(lint) |
38static char sccsid[] = "@(#)hash_bigkey.c 8.2 (Berkeley) 2/21/94"; | 38static char sccsid[] = "@(#)hash_bigkey.c 8.3 (Berkeley) 5/31/94"; |
39#endif /* LIBC_SCCS and not lint */ 40 41/* 42 * PACKAGE: hash 43 * DESCRIPTION: 44 * Big key/data handling for the hashing package. 45 * 46 * ROUTINES: --- 38 unchanged lines hidden (view full) --- 85 *-1 ==> ERROR 86 */ 87extern int 88__big_insert(hashp, bufp, key, val) 89 HTAB *hashp; 90 BUFHEAD *bufp; 91 const DBT *key, *val; 92{ | 39#endif /* LIBC_SCCS and not lint */ 40 41/* 42 * PACKAGE: hash 43 * DESCRIPTION: 44 * Big key/data handling for the hashing package. 45 * 46 * ROUTINES: --- 38 unchanged lines hidden (view full) --- 85 *-1 ==> ERROR 86 */ 87extern int 88__big_insert(hashp, bufp, key, val) 89 HTAB *hashp; 90 BUFHEAD *bufp; 91 const DBT *key, *val; 92{ |
93 register u_short *p; | 93 register u_int16_t *p; |
94 int key_size, n, val_size; | 94 int key_size, n, val_size; |
95 u_short space, move_bytes, off; | 95 u_int16_t space, move_bytes, off; |
96 char *cp, *key_data, *val_data; 97 98 cp = bufp->page; /* Character pointer of p. */ | 96 char *cp, *key_data, *val_data; 97 98 cp = bufp->page; /* Character pointer of p. */ |
99 p = (u_short *)cp; | 99 p = (u_int16_t *)cp; |
100 101 key_data = (char *)key->data; 102 key_size = key->size; 103 val_data = (char *)val->data; 104 val_size = val->size; 105 106 /* First move the Key */ 107 for (space = FREESPACE(p) - BIGOVERHEAD; key_size; --- 21 unchanged lines hidden (view full) --- 129 memmove(cp + off, val_data, move_bytes); 130 val_data += move_bytes; 131 val_size -= move_bytes; 132 p[n - 2] = FULL_KEY_DATA; 133 FREESPACE(p) = FREESPACE(p) - move_bytes; 134 OFFSET(p) = off; 135 } else 136 p[n - 2] = FULL_KEY; | 100 101 key_data = (char *)key->data; 102 key_size = key->size; 103 val_data = (char *)val->data; 104 val_size = val->size; 105 106 /* First move the Key */ 107 for (space = FREESPACE(p) - BIGOVERHEAD; key_size; --- 21 unchanged lines hidden (view full) --- 129 memmove(cp + off, val_data, move_bytes); 130 val_data += move_bytes; 131 val_size -= move_bytes; 132 p[n - 2] = FULL_KEY_DATA; 133 FREESPACE(p) = FREESPACE(p) - move_bytes; 134 OFFSET(p) = off; 135 } else 136 p[n - 2] = FULL_KEY; |
137 p = (u_short *)bufp->page; | 137 p = (u_int16_t *)bufp->page; |
138 cp = bufp->page; 139 bufp->flags |= BUF_MOD; 140 } 141 142 /* Now move the data */ 143 for (space = FREESPACE(p) - BIGOVERHEAD; val_size; 144 space = FREESPACE(p) - BIGOVERHEAD) { 145 move_bytes = MIN(space, val_size); --- 13 unchanged lines hidden (view full) --- 159 FREESPACE(p) = off - PAGE_META(n); 160 OFFSET(p) = off; 161 if (val_size) { 162 p[n] = FULL_KEY; 163 bufp = __add_ovflpage(hashp, bufp); 164 if (!bufp) 165 return (-1); 166 cp = bufp->page; | 138 cp = bufp->page; 139 bufp->flags |= BUF_MOD; 140 } 141 142 /* Now move the data */ 143 for (space = FREESPACE(p) - BIGOVERHEAD; val_size; 144 space = FREESPACE(p) - BIGOVERHEAD) { 145 move_bytes = MIN(space, val_size); --- 13 unchanged lines hidden (view full) --- 159 FREESPACE(p) = off - PAGE_META(n); 160 OFFSET(p) = off; 161 if (val_size) { 162 p[n] = FULL_KEY; 163 bufp = __add_ovflpage(hashp, bufp); 164 if (!bufp) 165 return (-1); 166 cp = bufp->page; |
167 p = (u_short *)cp; | 167 p = (u_int16_t *)cp; |
168 } else 169 p[n] = FULL_KEY_DATA; 170 bufp->flags |= BUF_MOD; 171 } 172 return (0); 173} 174 175/* --- 8 unchanged lines hidden (view full) --- 184 *-1 => ERROR 185 */ 186extern int 187__big_delete(hashp, bufp) 188 HTAB *hashp; 189 BUFHEAD *bufp; 190{ 191 register BUFHEAD *last_bfp, *rbufp; | 168 } else 169 p[n] = FULL_KEY_DATA; 170 bufp->flags |= BUF_MOD; 171 } 172 return (0); 173} 174 175/* --- 8 unchanged lines hidden (view full) --- 184 *-1 => ERROR 185 */ 186extern int 187__big_delete(hashp, bufp) 188 HTAB *hashp; 189 BUFHEAD *bufp; 190{ 191 register BUFHEAD *last_bfp, *rbufp; |
192 u_short *bp, pageno; | 192 u_int16_t *bp, pageno; |
193 int key_done, n; 194 195 rbufp = bufp; 196 last_bfp = NULL; | 193 int key_done, n; 194 195 rbufp = bufp; 196 last_bfp = NULL; |
197 bp = (u_short *)bufp->page; | 197 bp = (u_int16_t *)bufp->page; |
198 pageno = 0; 199 key_done = 0; 200 201 while (!key_done || (bp[2] != FULL_KEY_DATA)) { 202 if (bp[2] == FULL_KEY || bp[2] == FULL_KEY_DATA) 203 key_done = 1; 204 205 /* --- 6 unchanged lines hidden (view full) --- 212 pageno = bp[bp[0] - 1]; 213 rbufp->flags |= BUF_MOD; 214 rbufp = __get_buf(hashp, pageno, rbufp, 0); 215 if (last_bfp) 216 __free_ovflpage(hashp, last_bfp); 217 last_bfp = rbufp; 218 if (!rbufp) 219 return (-1); /* Error. */ | 198 pageno = 0; 199 key_done = 0; 200 201 while (!key_done || (bp[2] != FULL_KEY_DATA)) { 202 if (bp[2] == FULL_KEY || bp[2] == FULL_KEY_DATA) 203 key_done = 1; 204 205 /* --- 6 unchanged lines hidden (view full) --- 212 pageno = bp[bp[0] - 1]; 213 rbufp->flags |= BUF_MOD; 214 rbufp = __get_buf(hashp, pageno, rbufp, 0); 215 if (last_bfp) 216 __free_ovflpage(hashp, last_bfp); 217 last_bfp = rbufp; 218 if (!rbufp) 219 return (-1); /* Error. */ |
220 bp = (u_short *)rbufp->page; | 220 bp = (u_int16_t *)rbufp->page; |
221 } 222 223 /* 224 * If we get here then rbufp points to the last page of the big 225 * key/data pair. Bufp points to the first one -- it should now be 226 * empty pointing to the next page after this pair. Can't free it 227 * because we don't have the page pointing to it. 228 */ 229 230 /* This is information from the last page of the pair. */ 231 n = bp[0]; 232 pageno = bp[n - 1]; 233 234 /* Now, bp is the first page of the pair. */ | 221 } 222 223 /* 224 * If we get here then rbufp points to the last page of the big 225 * key/data pair. Bufp points to the first one -- it should now be 226 * empty pointing to the next page after this pair. Can't free it 227 * because we don't have the page pointing to it. 228 */ 229 230 /* This is information from the last page of the pair. */ 231 n = bp[0]; 232 pageno = bp[n - 1]; 233 234 /* Now, bp is the first page of the pair. */ |
235 bp = (u_short *)bufp->page; | 235 bp = (u_int16_t *)bufp->page; |
236 if (n > 2) { 237 /* There is an overflow page. */ 238 bp[1] = pageno; 239 bp[2] = OVFLPAGE; 240 bufp->ovfl = rbufp->ovfl; 241 } else 242 /* This is the last page. */ 243 bufp->ovfl = NULL; --- 21 unchanged lines hidden (view full) --- 265extern int 266__find_bigpair(hashp, bufp, ndx, key, size) 267 HTAB *hashp; 268 BUFHEAD *bufp; 269 int ndx; 270 char *key; 271 int size; 272{ | 236 if (n > 2) { 237 /* There is an overflow page. */ 238 bp[1] = pageno; 239 bp[2] = OVFLPAGE; 240 bufp->ovfl = rbufp->ovfl; 241 } else 242 /* This is the last page. */ 243 bufp->ovfl = NULL; --- 21 unchanged lines hidden (view full) --- 265extern int 266__find_bigpair(hashp, bufp, ndx, key, size) 267 HTAB *hashp; 268 BUFHEAD *bufp; 269 int ndx; 270 char *key; 271 int size; 272{ |
273 register u_short *bp; | 273 register u_int16_t *bp; |
274 register char *p; 275 int ksize; | 274 register char *p; 275 int ksize; |
276 u_short bytes; | 276 u_int16_t bytes; |
277 char *kkey; 278 | 277 char *kkey; 278 |
279 bp = (u_short *)bufp->page; | 279 bp = (u_int16_t *)bufp->page; |
280 p = bufp->page; 281 ksize = size; 282 kkey = key; 283 284 for (bytes = hashp->BSIZE - bp[ndx]; 285 bytes <= size && bp[ndx + 1] == PARTIAL_KEY; 286 bytes = hashp->BSIZE - bp[ndx]) { 287 if (memcmp(p + bp[ndx], kkey, bytes)) 288 return (-2); 289 kkey += bytes; 290 ksize -= bytes; 291 bufp = __get_buf(hashp, bp[ndx + 2], bufp, 0); 292 if (!bufp) 293 return (-3); 294 p = bufp->page; | 280 p = bufp->page; 281 ksize = size; 282 kkey = key; 283 284 for (bytes = hashp->BSIZE - bp[ndx]; 285 bytes <= size && bp[ndx + 1] == PARTIAL_KEY; 286 bytes = hashp->BSIZE - bp[ndx]) { 287 if (memcmp(p + bp[ndx], kkey, bytes)) 288 return (-2); 289 kkey += bytes; 290 ksize -= bytes; 291 bufp = __get_buf(hashp, bp[ndx + 2], bufp, 0); 292 if (!bufp) 293 return (-3); 294 p = bufp->page; |
295 bp = (u_short *)p; | 295 bp = (u_int16_t *)p; |
296 ndx = 1; 297 } 298 299 if (bytes != ksize || memcmp(p + bp[ndx], kkey, bytes)) { 300#ifdef HASH_STATISTICS 301 ++hash_collisions; 302#endif 303 return (-2); --- 5 unchanged lines hidden (view full) --- 309 * Given the buffer pointer of the first overflow page of a big pair, 310 * find the end of the big pair 311 * 312 * This will set bpp to the buffer header of the last page of the big pair. 313 * It will return the pageno of the overflow page following the last page 314 * of the pair; 0 if there isn't any (i.e. big pair is the last key in the 315 * bucket) 316 */ | 296 ndx = 1; 297 } 298 299 if (bytes != ksize || memcmp(p + bp[ndx], kkey, bytes)) { 300#ifdef HASH_STATISTICS 301 ++hash_collisions; 302#endif 303 return (-2); --- 5 unchanged lines hidden (view full) --- 309 * Given the buffer pointer of the first overflow page of a big pair, 310 * find the end of the big pair 311 * 312 * This will set bpp to the buffer header of the last page of the big pair. 313 * It will return the pageno of the overflow page following the last page 314 * of the pair; 0 if there isn't any (i.e. big pair is the last key in the 315 * bucket) 316 */ |
317extern u_short | 317extern u_int16_t |
318__find_last_page(hashp, bpp) 319 HTAB *hashp; 320 BUFHEAD **bpp; 321{ 322 BUFHEAD *bufp; | 318__find_last_page(hashp, bpp) 319 HTAB *hashp; 320 BUFHEAD **bpp; 321{ 322 BUFHEAD *bufp; |
323 u_short *bp, pageno; | 323 u_int16_t *bp, pageno; |
324 int n; 325 326 bufp = *bpp; | 324 int n; 325 326 bufp = *bpp; |
327 bp = (u_short *)bufp->page; | 327 bp = (u_int16_t *)bufp->page; |
328 for (;;) { 329 n = bp[0]; 330 331 /* 332 * This is the last page if: the tag is FULL_KEY_DATA and 333 * either only 2 entries OVFLPAGE marker is explicit there 334 * is freespace on the page. 335 */ 336 if (bp[2] == FULL_KEY_DATA && 337 ((n == 2) || (bp[n] == OVFLPAGE) || (FREESPACE(bp)))) 338 break; 339 340 pageno = bp[n - 1]; 341 bufp = __get_buf(hashp, pageno, bufp, 0); 342 if (!bufp) 343 return (0); /* Need to indicate an error! */ | 328 for (;;) { 329 n = bp[0]; 330 331 /* 332 * This is the last page if: the tag is FULL_KEY_DATA and 333 * either only 2 entries OVFLPAGE marker is explicit there 334 * is freespace on the page. 335 */ 336 if (bp[2] == FULL_KEY_DATA && 337 ((n == 2) || (bp[n] == OVFLPAGE) || (FREESPACE(bp)))) 338 break; 339 340 pageno = bp[n - 1]; 341 bufp = __get_buf(hashp, pageno, bufp, 0); 342 if (!bufp) 343 return (0); /* Need to indicate an error! */ |
344 bp = (u_short *)bufp->page; | 344 bp = (u_int16_t *)bufp->page; |
345 } 346 347 *bpp = bufp; 348 if (bp[0] > 2) 349 return (bp[3]); 350 else 351 return (0); 352} --- 6 unchanged lines hidden (view full) --- 359__big_return(hashp, bufp, ndx, val, set_current) 360 HTAB *hashp; 361 BUFHEAD *bufp; 362 int ndx; 363 DBT *val; 364 int set_current; 365{ 366 BUFHEAD *save_p; | 345 } 346 347 *bpp = bufp; 348 if (bp[0] > 2) 349 return (bp[3]); 350 else 351 return (0); 352} --- 6 unchanged lines hidden (view full) --- 359__big_return(hashp, bufp, ndx, val, set_current) 360 HTAB *hashp; 361 BUFHEAD *bufp; 362 int ndx; 363 DBT *val; 364 int set_current; 365{ 366 BUFHEAD *save_p; |
367 u_short *bp, len, off, save_addr; | 367 u_int16_t *bp, len, off, save_addr; |
368 char *tp; 369 | 368 char *tp; 369 |
370 bp = (u_short *)bufp->page; | 370 bp = (u_int16_t *)bufp->page; |
371 while (bp[ndx + 1] == PARTIAL_KEY) { 372 bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); 373 if (!bufp) 374 return (-1); | 371 while (bp[ndx + 1] == PARTIAL_KEY) { 372 bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); 373 if (!bufp) 374 return (-1); |
375 bp = (u_short *)bufp->page; | 375 bp = (u_int16_t *)bufp->page; |
376 ndx = 1; 377 } 378 379 if (bp[ndx + 1] == FULL_KEY) { 380 bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); 381 if (!bufp) 382 return (-1); | 376 ndx = 1; 377 } 378 379 if (bp[ndx + 1] == FULL_KEY) { 380 bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); 381 if (!bufp) 382 return (-1); |
383 bp = (u_short *)bufp->page; | 383 bp = (u_int16_t *)bufp->page; |
384 save_p = bufp; 385 save_addr = save_p->addr; 386 off = bp[1]; 387 len = 0; 388 } else 389 if (!FREESPACE(bp)) { 390 /* 391 * This is a hack. We can't distinguish between --- 4 unchanged lines hidden (view full) --- 396 */ 397 off = bp[bp[0]]; 398 len = bp[1] - off; 399 save_p = bufp; 400 save_addr = bufp->addr; 401 bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); 402 if (!bufp) 403 return (-1); | 384 save_p = bufp; 385 save_addr = save_p->addr; 386 off = bp[1]; 387 len = 0; 388 } else 389 if (!FREESPACE(bp)) { 390 /* 391 * This is a hack. We can't distinguish between --- 4 unchanged lines hidden (view full) --- 396 */ 397 off = bp[bp[0]]; 398 len = bp[1] - off; 399 save_p = bufp; 400 save_addr = bufp->addr; 401 bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); 402 if (!bufp) 403 return (-1); |
404 bp = (u_short *)bufp->page; | 404 bp = (u_int16_t *)bufp->page; |
405 } else { 406 /* The data is all on one page. */ 407 tp = (char *)bp; 408 off = bp[bp[0]]; 409 val->data = (u_char *)tp + off; 410 val->size = bp[1] - off; 411 if (set_current) { 412 if (bp[0] == 2) { /* No more buckets in 413 * chain */ 414 hashp->cpage = NULL; 415 hashp->cbucket++; 416 hashp->cndx = 1; 417 } else { 418 hashp->cpage = __get_buf(hashp, 419 bp[bp[0] - 1], bufp, 0); 420 if (!hashp->cpage) 421 return (-1); 422 hashp->cndx = 1; | 405 } else { 406 /* The data is all on one page. */ 407 tp = (char *)bp; 408 off = bp[bp[0]]; 409 val->data = (u_char *)tp + off; 410 val->size = bp[1] - off; 411 if (set_current) { 412 if (bp[0] == 2) { /* No more buckets in 413 * chain */ 414 hashp->cpage = NULL; 415 hashp->cbucket++; 416 hashp->cndx = 1; 417 } else { 418 hashp->cpage = __get_buf(hashp, 419 bp[bp[0] - 1], bufp, 0); 420 if (!hashp->cpage) 421 return (-1); 422 hashp->cndx = 1; |
423 if (!((u_short *) | 423 if (!((u_int16_t *) |
424 hashp->cpage->page)[0]) { 425 hashp->cbucket++; 426 hashp->cpage = NULL; 427 } 428 } 429 } 430 return (0); 431 } --- 15 unchanged lines hidden (view full) --- 447 * allocate a buffer and copy the data as you recurse up. 448 */ 449static int 450collect_data(hashp, bufp, len, set) 451 HTAB *hashp; 452 BUFHEAD *bufp; 453 int len, set; 454{ | 424 hashp->cpage->page)[0]) { 425 hashp->cbucket++; 426 hashp->cpage = NULL; 427 } 428 } 429 } 430 return (0); 431 } --- 15 unchanged lines hidden (view full) --- 447 * allocate a buffer and copy the data as you recurse up. 448 */ 449static int 450collect_data(hashp, bufp, len, set) 451 HTAB *hashp; 452 BUFHEAD *bufp; 453 int len, set; 454{ |
455 register u_short *bp; | 455 register u_int16_t *bp; |
456 register char *p; 457 BUFHEAD *xbp; | 456 register char *p; 457 BUFHEAD *xbp; |
458 u_short save_addr; | 458 u_int16_t save_addr; |
459 int mylen, totlen; 460 461 p = bufp->page; | 459 int mylen, totlen; 460 461 p = bufp->page; |
462 bp = (u_short *)p; | 462 bp = (u_int16_t *)p; |
463 mylen = hashp->BSIZE - bp[1]; 464 save_addr = bufp->addr; 465 466 if (bp[2] == FULL_KEY_DATA) { /* End of Data */ 467 totlen = len + mylen; 468 if (hashp->tmp_buf) 469 free(hashp->tmp_buf); 470 if ((hashp->tmp_buf = (char *)malloc(totlen)) == NULL) 471 return (-1); 472 if (set) { 473 hashp->cndx = 1; 474 if (bp[0] == 2) { /* No more buckets in chain */ 475 hashp->cpage = NULL; 476 hashp->cbucket++; 477 } else { 478 hashp->cpage = 479 __get_buf(hashp, bp[bp[0] - 1], bufp, 0); 480 if (!hashp->cpage) 481 return (-1); | 463 mylen = hashp->BSIZE - bp[1]; 464 save_addr = bufp->addr; 465 466 if (bp[2] == FULL_KEY_DATA) { /* End of Data */ 467 totlen = len + mylen; 468 if (hashp->tmp_buf) 469 free(hashp->tmp_buf); 470 if ((hashp->tmp_buf = (char *)malloc(totlen)) == NULL) 471 return (-1); 472 if (set) { 473 hashp->cndx = 1; 474 if (bp[0] == 2) { /* No more buckets in chain */ 475 hashp->cpage = NULL; 476 hashp->cbucket++; 477 } else { 478 hashp->cpage = 479 __get_buf(hashp, bp[bp[0] - 1], bufp, 0); 480 if (!hashp->cpage) 481 return (-1); |
482 else if (!((u_short *)hashp->cpage->page)[0]) { | 482 else if (!((u_int16_t *)hashp->cpage->page)[0]) { |
483 hashp->cbucket++; 484 hashp->cpage = NULL; 485 } 486 } 487 } 488 } else { 489 xbp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); 490 if (!xbp || ((totlen = --- 35 unchanged lines hidden (view full) --- 526 BUFHEAD *bufp; 527 int len; 528 DBT *val; 529 int set; 530{ 531 BUFHEAD *xbp; 532 char *p; 533 int mylen, totlen; | 483 hashp->cbucket++; 484 hashp->cpage = NULL; 485 } 486 } 487 } 488 } else { 489 xbp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); 490 if (!xbp || ((totlen = --- 35 unchanged lines hidden (view full) --- 526 BUFHEAD *bufp; 527 int len; 528 DBT *val; 529 int set; 530{ 531 BUFHEAD *xbp; 532 char *p; 533 int mylen, totlen; |
534 u_short *bp, save_addr; | 534 u_int16_t *bp, save_addr; |
535 536 p = bufp->page; | 535 536 p = bufp->page; |
537 bp = (u_short *)p; | 537 bp = (u_int16_t *)p; |
538 mylen = hashp->BSIZE - bp[1]; 539 540 save_addr = bufp->addr; 541 totlen = len + mylen; 542 if (bp[2] == FULL_KEY || bp[2] == FULL_KEY_DATA) { /* End of Key. */ 543 if (hashp->tmp_key != NULL) 544 free(hashp->tmp_key); 545 if ((hashp->tmp_key = (char *)malloc(totlen)) == NULL) --- 22 unchanged lines hidden (view full) --- 568extern int 569__big_split(hashp, op, np, big_keyp, addr, obucket, ret) 570 HTAB *hashp; 571 BUFHEAD *op; /* Pointer to where to put keys that go in old bucket */ 572 BUFHEAD *np; /* Pointer to new bucket page */ 573 /* Pointer to first page containing the big key/data */ 574 BUFHEAD *big_keyp; 575 int addr; /* Address of big_keyp */ | 538 mylen = hashp->BSIZE - bp[1]; 539 540 save_addr = bufp->addr; 541 totlen = len + mylen; 542 if (bp[2] == FULL_KEY || bp[2] == FULL_KEY_DATA) { /* End of Key. */ 543 if (hashp->tmp_key != NULL) 544 free(hashp->tmp_key); 545 if ((hashp->tmp_key = (char *)malloc(totlen)) == NULL) --- 22 unchanged lines hidden (view full) --- 568extern int 569__big_split(hashp, op, np, big_keyp, addr, obucket, ret) 570 HTAB *hashp; 571 BUFHEAD *op; /* Pointer to where to put keys that go in old bucket */ 572 BUFHEAD *np; /* Pointer to new bucket page */ 573 /* Pointer to first page containing the big key/data */ 574 BUFHEAD *big_keyp; 575 int addr; /* Address of big_keyp */ |
576 u_int obucket;/* Old Bucket */ | 576 u_int32_t obucket;/* Old Bucket */ |
577 SPLIT_RETURN *ret; 578{ 579 register BUFHEAD *tmpp; | 577 SPLIT_RETURN *ret; 578{ 579 register BUFHEAD *tmpp; |
580 register u_short *tp; | 580 register u_int16_t *tp; |
581 BUFHEAD *bp; 582 DBT key, val; | 581 BUFHEAD *bp; 582 DBT key, val; |
583 u_int change; 584 u_short free_space, n, off; | 583 u_int32_t change; 584 u_int16_t free_space, n, off; |
585 586 bp = big_keyp; 587 588 /* Now figure out where the big key/data goes */ 589 if (__big_keydata(hashp, big_keyp, &key, &val, 0)) 590 return (-1); 591 change = (__call_hash(hashp, key.data, key.size) != obucket); 592 --- 15 unchanged lines hidden (view full) --- 608 609 tmpp->flags |= BUF_MOD; 610#ifdef DEBUG1 611 (void)fprintf(stderr, 612 "BIG_SPLIT: %d->ovfl was %d is now %d\n", tmpp->addr, 613 (tmpp->ovfl ? tmpp->ovfl->addr : 0), (bp ? bp->addr : 0)); 614#endif 615 tmpp->ovfl = bp; /* one of op/np point to big_keyp */ | 585 586 bp = big_keyp; 587 588 /* Now figure out where the big key/data goes */ 589 if (__big_keydata(hashp, big_keyp, &key, &val, 0)) 590 return (-1); 591 change = (__call_hash(hashp, key.data, key.size) != obucket); 592 --- 15 unchanged lines hidden (view full) --- 608 609 tmpp->flags |= BUF_MOD; 610#ifdef DEBUG1 611 (void)fprintf(stderr, 612 "BIG_SPLIT: %d->ovfl was %d is now %d\n", tmpp->addr, 613 (tmpp->ovfl ? tmpp->ovfl->addr : 0), (bp ? bp->addr : 0)); 614#endif 615 tmpp->ovfl = bp; /* one of op/np point to big_keyp */ |
616 tp = (u_short *)tmpp->page; | 616 tp = (u_int16_t *)tmpp->page; |
617#ifdef DEBUG 618 assert(FREESPACE(tp) >= OVFLSIZE); 619#endif 620 n = tp[0]; 621 off = OFFSET(tp); 622 free_space = FREESPACE(tp); | 617#ifdef DEBUG 618 assert(FREESPACE(tp) >= OVFLSIZE); 619#endif 620 n = tp[0]; 621 off = OFFSET(tp); 622 free_space = FREESPACE(tp); |
623 tp[++n] = (u_short)addr; | 623 tp[++n] = (u_int16_t)addr; |
624 tp[++n] = OVFLPAGE; 625 tp[0] = n; 626 OFFSET(tp) = off; 627 FREESPACE(tp) = free_space - OVFLSIZE; 628 629 /* 630 * Finally, set the new and old return values. BIG_KEYP contains a 631 * pointer to the last page of the big key_data pair. Make sure that 632 * big_keyp has no following page (2 elements) or create an empty 633 * following page. 634 */ 635 636 ret->newp = np; 637 ret->oldp = op; 638 | 624 tp[++n] = OVFLPAGE; 625 tp[0] = n; 626 OFFSET(tp) = off; 627 FREESPACE(tp) = free_space - OVFLSIZE; 628 629 /* 630 * Finally, set the new and old return values. BIG_KEYP contains a 631 * pointer to the last page of the big key_data pair. Make sure that 632 * big_keyp has no following page (2 elements) or create an empty 633 * following page. 634 */ 635 636 ret->newp = np; 637 ret->oldp = op; 638 |
639 tp = (u_short *)big_keyp->page; | 639 tp = (u_int16_t *)big_keyp->page; |
640 big_keyp->flags |= BUF_MOD; 641 if (tp[0] > 2) { 642 /* 643 * There may be either one or two offsets on this page. If 644 * there is one, then the overflow page is linked on normally 645 * and tp[4] is OVFLPAGE. If there are two, tp[4] contains 646 * the second offset and needs to get stuffed in after the 647 * next overflow page is added. --- 20 unchanged lines hidden --- | 640 big_keyp->flags |= BUF_MOD; 641 if (tp[0] > 2) { 642 /* 643 * There may be either one or two offsets on this page. If 644 * there is one, then the overflow page is linked on normally 645 * and tp[4] is OVFLPAGE. If there are two, tp[4] contains 646 * the second offset and needs to get stuffed in after the 647 * next overflow page is added. --- 20 unchanged lines hidden --- |