filehash/ffdb_hash.c
static int
_ffdb_init_htab (ffdb_htab_t* hashp, int nb, FFDB_HASHINFO* info)
{
  int l2, nbuckets, nhdr_pages;
  unsigned int uinfosize;
  pgno_t i, pg;

  /**
   * log2 of elements
   */
  l2 = __ffdb_log2 (nb);

  /**
   * Number of buckets = 2^l2
   */
  nbuckets = 1 << l2;


  /* Calculate number of header pages */
  /* real header occupies one */
  pg = nhdr_pages = 1;

  /* Check how many user informantion length */
  if (info && info->userinfolen > 0) 
    hashp->hdr.uinfolen = info->userinfolen;
  else
    hashp->hdr.uinfolen = FFDB_DEFAULT_UINFO_LEN;
  uinfosize = hashp->hdr.uinfolen + sizeof(unsigned int);

  /* This is user information */
  hashp->hdr.uinfo_page = pg;

  if (uinfosize % (hashp->hdr.bsize - PAGE_OVERHEAD) == 0)
    nhdr_pages += (uinfosize/(hashp->hdr.bsize - PAGE_OVERHEAD));
  else
    nhdr_pages += (uinfosize/(hashp->hdr.bsize - PAGE_OVERHEAD) + 1);
  hashp->hdr.uinfo_npages = nhdr_pages - pg;

  /* Calculate configuration number of pages */
  pg = nhdr_pages;
  hashp->hdr.cfig_page = pg;
  if (info && info->numconfigs > 0) 
    hashp->hdr.num_cfigs = info->numconfigs;
  else
    hashp->hdr.num_cfigs = 1;

  /* total number of configuration size */
  nhdr_pages += (_ffdb_num_config_info_pages (hashp, hashp->hdr.num_cfigs));
  hashp->hdr.cfig_npages = nhdr_pages - pg;

  /* Assign the number of header pages */
  hashp->hdr.hdrpages = nhdr_pages;

  /* populate spares */
  hashp->hdr.spares[0] = nhdr_pages;

  if (l2 >= 1)
    hashp->hdr.spares[1] = nhdr_pages + 1;
  for (i = 2; i <= l2; i++)
    hashp->hdr.spares[i] = hashp->hdr.spares[i - 1] + POW2(i - 2);

  for (; i < NCACHED; i++)
    hashp->hdr.spares[i] = 0;

  /* initialize free pages */
  for (i = 0; i < NCACHED; i++)
    hashp->hdr.free_pages[i] = INVALID_PGNO;

  /* current spliting level */
  hashp->hdr.ovfl_point = l2;

  /* high mask and low mask value */
  hashp->hdr.max_bucket = hashp->hdr.high_mask = nbuckets - 1;
  hashp->hdr.low_mask = (nbuckets >> 1) - 1;

  return 0;
}
/**
 * Initialize the hash table if this is a new file
 * Initialize hash table with 'nb' number of buckets
 */
Initialize the hash table if this is a new file
Initialize hash table with 'nb' number of buckets
Initialize the hash table if this is a new file Initialize hash table with ' nb ' number of buckets
static int
_ffdb_init_htab (ffdb_htab_t* hashp, int nb, FFDB_HASHINFO* info)
{
  int l2, nbuckets, nhdr_pages;
  unsigned int uinfosize;
  pgno_t i, pg;
  l2 = __ffdb_log2 (nb);
  nbuckets = 1 << l2;
  pg = nhdr_pages = 1;
  if (info && info->userinfolen > 0) 
    hashp->hdr.uinfolen = info->userinfolen;
  else
    hashp->hdr.uinfolen = FFDB_DEFAULT_UINFO_LEN;
  uinfosize = hashp->hdr.uinfolen + sizeof(unsigned int);
  hashp->hdr.uinfo_page = pg;
  if (uinfosize % (hashp->hdr.bsize - PAGE_OVERHEAD) == 0)
    nhdr_pages += (uinfosize/(hashp->hdr.bsize - PAGE_OVERHEAD));
  else
    nhdr_pages += (uinfosize/(hashp->hdr.bsize - PAGE_OVERHEAD) + 1);
  hashp->hdr.uinfo_npages = nhdr_pages - pg;
  pg = nhdr_pages;
  hashp->hdr.cfig_page = pg;
  if (info && info->numconfigs > 0) 
    hashp->hdr.num_cfigs = info->numconfigs;
  else
    hashp->hdr.num_cfigs = 1;
  nhdr_pages += (_ffdb_num_config_info_pages (hashp, hashp->hdr.num_cfigs));
  hashp->hdr.cfig_npages = nhdr_pages - pg;
  hashp->hdr.hdrpages = nhdr_pages;
  hashp->hdr.spares[0] = nhdr_pages;
  if (l2 >= 1)
    hashp->hdr.spares[1] = nhdr_pages + 1;
  for (i = 2; i <= l2; i++)
    hashp->hdr.spares[i] = hashp->hdr.spares[i - 1] + POW2(i - 2);
  for (; i < NCACHED; i++)
    hashp->hdr.spares[i] = 0;
  for (i = 0; i < NCACHED; i++)
    hashp->hdr.free_pages[i] = INVALID_PGNO;
  hashp->hdr.ovfl_point = l2;
  hashp->hdr.max_bucket = hashp->hdr.high_mask = nbuckets - 1;
  hashp->hdr.low_mask = (nbuckets >> 1) - 1;
  return 0;
}
static int _ffdb_init_htab ( ffdb_htab_t * hashp , int nb , FFDB_HASHINFO * info ) { int l2 , nbuckets , nhdr_pages ; unsigned int uinfosize ; pgno_t i , pg ; l2 = __ffdb_log2 ( nb ) ; nbuckets = 1 << l2 ; pg = nhdr_pages = 1 ; if ( info && info -> userinfolen > 0 ) hashp -> hdr . uinfolen = info -> userinfolen ; else hashp -> hdr . uinfolen = FFDB_DEFAULT_UINFO_LEN ; uinfosize = hashp -> hdr . uinfolen + sizeof ( unsigned int ) ; hashp -> hdr . uinfo_page = pg ; if ( uinfosize % ( hashp -> hdr . bsize - PAGE_OVERHEAD ) == 0 ) nhdr_pages += ( uinfosize / ( hashp -> hdr . bsize - PAGE_OVERHEAD ) ) ; else nhdr_pages += ( uinfosize / ( hashp -> hdr . bsize - PAGE_OVERHEAD ) + 1 ) ; hashp -> hdr . uinfo_npages = nhdr_pages - pg ; pg = nhdr_pages ; hashp -> hdr . cfig_page = pg ; if ( info && info -> numconfigs > 0 ) hashp -> hdr . num_cfigs = info -> numconfigs ; else hashp -> hdr . num_cfigs = 1 ; nhdr_pages += ( _ffdb_num_config_info_pages ( hashp , hashp -> hdr . num_cfigs ) ) ; hashp -> hdr . cfig_npages = nhdr_pages - pg ; hashp -> hdr . hdrpages = nhdr_pages ; hashp -> hdr . spares [ 0 ] = nhdr_pages ; if ( l2 >= 1 ) hashp -> hdr . spares [ 1 ] = nhdr_pages + 1 ; for ( i = 2 ; i <= l2 ; i ++ ) hashp -> hdr . spares [ i ] = hashp -> hdr . spares [ i - 1 ] + POW2 ( i - 2 ) ; for ( ; i < NCACHED ; i ++ ) hashp -> hdr . spares [ i ] = 0 ; for ( i = 0 ; i < NCACHED ; i ++ ) hashp -> hdr . free_pages [ i ] = INVALID_PGNO ; hashp -> hdr . ovfl_point = l2 ; hashp -> hdr . max_bucket = hashp -> hdr . high_mask = nbuckets - 1 ; hashp -> hdr . low_mask = ( nbuckets >> 1 ) - 1 ; return 0 ; }
Initialize the hash table if this is a new file
 Initialize hash table with 'nb' number of buckets
Initialize the hash table if this is a new file Initialize hash table with ' nb ' number of buckets
/**
   * log2 of elements
   */ /**
   * Number of buckets = 2^l2
   */ /* Calculate number of header pages */ /* real header occupies one */ /* Check how many user informantion length */ /* This is user information */ /* Calculate configuration number of pages */ /* total number of configuration size */ /* Assign the number of header pages */ /* populate spares */ /* initialize free pages */ /* current spliting level */ /* high mask and low mask value */