filehash/ffdb_page.c
int
ffdb_rearrage_pages_on_close (ffdb_htab_t* hashp)
{
  pgno_t funused, lunused;
  pgno_t dlast, dfirst;
  unsigned int num_unused, num_pages;
  unsigned int num_page_moved;

  /* Find out how many pages are not used by reguler hash pages */
  num_unused = hashp->hdr.high_mask - hashp->hdr.max_bucket;
  if (num_unused == 0)
    return 0;

  /* First and last unused page */
  BUCKET_TO_PAGE(hashp->hdr.max_bucket + 1, funused);
  BUCKET_TO_PAGE(hashp->hdr.high_mask, lunused);
#if 1
  fprintf (stderr, "There are %d pages (buckets) not used starting at page %d and end at %d on last level %d\n",
	   num_unused, funused, lunused, hashp->hdr.ovfl_point);
#endif

  /* This is the last page used so far */
  dlast = hashp->hdr.spares[hashp->hdr.ovfl_point + 1] - 1;
  assert (dlast > 0);
  assert (dlast > lunused);

#if 0
  fprintf (stderr, "Last data page = %d\n", dlast);
#endif

  /* Now we need to figure out what pages to move
   * These pages may contain overflow pages and data pages
   * which require different treatment. We move data pages
   * first
   */
  num_pages = dlast - lunused;
  num_page_moved = (num_pages < num_unused) ? num_pages : num_unused;

  /* First page to be moved */
  dfirst = dlast - num_page_moved + 1;
  /* Update last free page to be used */
  lunused = funused + num_page_moved  - 1;

#if 1
  fprintf (stderr, "We are going to move %d pages from %d to %d to new pages from %d to %d\n", num_page_moved, dfirst, dlast, funused, lunused);
#endif

  /* move data pages first */
  _ffdb_move_pages (hashp, HASH_DATA_PAGE, dfirst, dlast,
		    funused, lunused);

  /* move overflow page next */
  _ffdb_move_pages (hashp, HASH_BUCKET_PAGE, dfirst, dlast,
		    funused, lunused);

  _ffdb_move_pages (hashp, HASH_FREE_PAGE, dfirst, dlast,
		    funused, lunused);

  hashp->hdr.num_moved_pages = num_page_moved;

  return 0;
}
/**
 * Optional to reorganize the pages to fill holes left by 
 * not fully using all buckets pages at a particular level
 */
Optional to reorganize the pages to fill holes left by
not fully using all buckets pages at a particular level
Optional to reorganize the pages to fill holes left by not fully using all buckets pages at a particular level
int
ffdb_rearrage_pages_on_close (ffdb_htab_t* hashp)
{
  pgno_t funused, lunused;
  pgno_t dlast, dfirst;
  unsigned int num_unused, num_pages;
  unsigned int num_page_moved;
  num_unused = hashp->hdr.high_mask - hashp->hdr.max_bucket;
  if (num_unused == 0)
    return 0;
  BUCKET_TO_PAGE(hashp->hdr.max_bucket + 1, funused);
  BUCKET_TO_PAGE(hashp->hdr.high_mask, lunused);
#if 1
  fprintf (stderr, "There are %d pages (buckets) not used starting at page %d and end at %d on last level %d\n",
	   num_unused, funused, lunused, hashp->hdr.ovfl_point);
#endif
  dlast = hashp->hdr.spares[hashp->hdr.ovfl_point + 1] - 1;
  assert (dlast > 0);
  assert (dlast > lunused);
#if 0
  fprintf (stderr, "Last data page = %d\n", dlast);
#endif
  num_pages = dlast - lunused;
  num_page_moved = (num_pages < num_unused) ? num_pages : num_unused;
  dfirst = dlast - num_page_moved + 1;
  lunused = funused + num_page_moved  - 1;
#if 1
  fprintf (stderr, "We are going to move %d pages from %d to %d to new pages from %d to %d\n", num_page_moved, dfirst, dlast, funused, lunused);
#endif
  _ffdb_move_pages (hashp, HASH_DATA_PAGE, dfirst, dlast,
		    funused, lunused);
  _ffdb_move_pages (hashp, HASH_BUCKET_PAGE, dfirst, dlast,
		    funused, lunused);
  _ffdb_move_pages (hashp, HASH_FREE_PAGE, dfirst, dlast,
		    funused, lunused);
  hashp->hdr.num_moved_pages = num_page_moved;
  return 0;
}
int ffdb_rearrage_pages_on_close ( ffdb_htab_t * hashp ) { pgno_t funused , lunused ; pgno_t dlast , dfirst ; unsigned int num_unused , num_pages ; unsigned int num_page_moved ; num_unused = hashp -> hdr . high_mask - hashp -> hdr . max_bucket ; if ( num_unused == 0 ) return 0 ; BUCKET_TO_PAGE ( hashp -> hdr . max_bucket + 1 , funused ) ; BUCKET_TO_PAGE ( hashp -> hdr . high_mask , lunused ) ; #if 1 fprintf ( stderr , " \n " , num_unused , funused , lunused , hashp -> hdr . ovfl_point ) ; #endif dlast = hashp -> hdr . spares [ hashp -> hdr . ovfl_point + 1 ] - 1 ; assert ( dlast > 0 ) ; assert ( dlast > lunused ) ; #if 0 fprintf ( stderr , " \n " , dlast ) ; #endif num_pages = dlast - lunused ; num_page_moved = ( num_pages < num_unused ) ? num_pages : num_unused ; dfirst = dlast - num_page_moved + 1 ; lunused = funused + num_page_moved - 1 ; #if 1 fprintf ( stderr , " \n " , num_page_moved , dfirst , dlast , funused , lunused ) ; #endif _ffdb_move_pages ( hashp , HASH_DATA_PAGE , dfirst , dlast , funused , lunused ) ; _ffdb_move_pages ( hashp , HASH_BUCKET_PAGE , dfirst , dlast , funused , lunused ) ; _ffdb_move_pages ( hashp , HASH_FREE_PAGE , dfirst , dlast , funused , lunused ) ; hashp -> hdr . num_moved_pages = num_page_moved ; return 0 ; }
Optional to reorganize the pages to fill holes left by
 not fully using all buckets pages at a particular level
Optional to reorganize the pages to fill holes left by not fully using all buckets pages at a particular level
/* Find out how many pages are not used by reguler hash pages */ /* First and last unused page */ /* This is the last page used so far */ /* Now we need to figure out what pages to move
   * These pages may contain overflow pages and data pages
   * which require different treatment. We move data pages
   * first
   */ /* First page to be moved */ /* Update last free page to be used */ /* move data pages first */ /* move overflow page next */