filehash/ffdb_hash.c
static int
_ffdb_expand_table (ffdb_htab_t* hashp)
{
  unsigned int old_bucket, new_bucket;
  int spare_indx, isdoubling, ret;
  pgno_t p;

#ifdef _FFDB_STATISTICS
  hash_expansions++;
#endif
  isdoubling = 0;

  /* The number of buckets is increased by one, obviously */
  new_bucket = ++hashp->hdr.max_bucket;
  
  /* which bucket to split */
  old_bucket = (hashp->hdr.max_bucket & hashp->hdr.low_mask);

  /* If new bucket is greater than high mask, we do doubling again */
  if (new_bucket > hashp->hdr.high_mask) {
    hashp->hdr.low_mask = hashp->hdr.high_mask;
    hashp->hdr.high_mask = new_bucket | hashp->hdr.low_mask;
  }

  /*
   * If the split point is increasing (hdr.max_bucket's log base 2
   * increases), we need to copy the current contents of the spare
   * split bucket to the next bucket.
   */
  spare_indx = __ffdb_log2(hashp->hdr.max_bucket + 1);

  if (spare_indx > hashp->hdr.ovfl_point) {
    /* update current data page value */
    hashp->curr_dpage = INVALID_PGNO;
    hashp->hdr.ovfl_point = spare_indx;
    isdoubling = 1;
  }


  BUCKET_TO_PAGE(new_bucket, p);
  if (p == MAX_PAGES(hashp)) {
    fprintf (stderr, "Reach maximum number of pages %d\n",
	     MAX_PAGES(hashp));
    exit (1);
  }
  
  /* Get a new bucket */
  if (ffdb_new_page (hashp, new_bucket, HASH_BUCKET_PAGE) != 0)
    return -1;

#ifdef _FFDB_DEBUG
  fprintf (stderr, "Get a new expanded page at bucket %d split old bucket %d\n", new_bucket, old_bucket);
#endif

  if (isdoubling) {
    /* Write out meta header here */
    _ffdb_flush_meta (hashp);
    ffdb_pagepool_sync (hashp->mp); 
  }
  
  ret = ffdb_split_bucket (hashp, old_bucket, new_bucket, isdoubling);
  return ret;
}
/**
 * Expand hash table
 * this happens when a bucket cannot hold any more keys
 *
 * We are not checking fill factor because we are trying to save
 * disk space instead of trying to speed up the access
 */
Expand hash table
this happens when a bucket cannot hold any more keys

We are not checking fill factor because we are trying to save
disk space instead of trying to speed up the access
Expand hash table this happens when a bucket cannot hold any more keys We are not checking fill factor because we are trying to save disk space instead of trying to speed up the access
static int
_ffdb_expand_table (ffdb_htab_t* hashp)
{
  unsigned int old_bucket, new_bucket;
  int spare_indx, isdoubling, ret;
  pgno_t p;
#ifdef _FFDB_STATISTICS
  hash_expansions++;
#endif
  isdoubling = 0;
  new_bucket = ++hashp->hdr.max_bucket;
  old_bucket = (hashp->hdr.max_bucket & hashp->hdr.low_mask);
  if (new_bucket > hashp->hdr.high_mask) {
    hashp->hdr.low_mask = hashp->hdr.high_mask;
    hashp->hdr.high_mask = new_bucket | hashp->hdr.low_mask;
  }
  spare_indx = __ffdb_log2(hashp->hdr.max_bucket + 1);
  if (spare_indx > hashp->hdr.ovfl_point) {
    hashp->curr_dpage = INVALID_PGNO;
    hashp->hdr.ovfl_point = spare_indx;
    isdoubling = 1;
  }
  BUCKET_TO_PAGE(new_bucket, p);
  if (p == MAX_PAGES(hashp)) {
    fprintf (stderr, "Reach maximum number of pages %d\n",
	     MAX_PAGES(hashp));
    exit (1);
  }
  if (ffdb_new_page (hashp, new_bucket, HASH_BUCKET_PAGE) != 0)
    return -1;
#ifdef _FFDB_DEBUG
  fprintf (stderr, "Get a new expanded page at bucket %d split old bucket %d\n", new_bucket, old_bucket);
#endif
  if (isdoubling) {
    _ffdb_flush_meta (hashp);
    ffdb_pagepool_sync (hashp->mp); 
  }
  ret = ffdb_split_bucket (hashp, old_bucket, new_bucket, isdoubling);
  return ret;
}
static int _ffdb_expand_table ( ffdb_htab_t * hashp ) { unsigned int old_bucket , new_bucket ; int spare_indx , isdoubling , ret ; pgno_t p ; #ifdef _FFDB_STATISTICS hash_expansions ++ ; #endif isdoubling = 0 ; new_bucket = ++ hashp -> hdr . max_bucket ; old_bucket = ( hashp -> hdr . max_bucket & hashp -> hdr . low_mask ) ; if ( new_bucket > hashp -> hdr . high_mask ) { hashp -> hdr . low_mask = hashp -> hdr . high_mask ; hashp -> hdr . high_mask = new_bucket | hashp -> hdr . low_mask ; } spare_indx = __ffdb_log2 ( hashp -> hdr . max_bucket + 1 ) ; if ( spare_indx > hashp -> hdr . ovfl_point ) { hashp -> curr_dpage = INVALID_PGNO ; hashp -> hdr . ovfl_point = spare_indx ; isdoubling = 1 ; } BUCKET_TO_PAGE ( new_bucket , p ) ; if ( p == MAX_PAGES ( hashp ) ) { fprintf ( stderr , " \n " , MAX_PAGES ( hashp ) ) ; exit ( 1 ) ; } if ( ffdb_new_page ( hashp , new_bucket , HASH_BUCKET_PAGE ) != 0 ) return -1 ; #ifdef _FFDB_DEBUG fprintf ( stderr , " \n " , new_bucket , old_bucket ) ; #endif if ( isdoubling ) { _ffdb_flush_meta ( hashp ) ; ffdb_pagepool_sync ( hashp -> mp ) ; } ret = ffdb_split_bucket ( hashp , old_bucket , new_bucket , isdoubling ) ; return ret ; }
Expand hash table
 this happens when a bucket cannot hold any more keys
Expand hash table this happens when a bucket cannot hold any more keys
/* The number of buckets is increased by one, obviously */ /* which bucket to split */ /* If new bucket is greater than high mask, we do doubling again */ /*
   * If the split point is increasing (hdr.max_bucket's log base 2
   * increases), we need to copy the current contents of the spare
   * split bucket to the next bucket.
   */ /* update current data page value */ /* Get a new bucket */ /* Write out meta header here */