Ejemplo n.º 1
0
static pool_tRef allocNode( ptree_sTable *tp,
			    void *key)
{
  pool_tRef    nr;
  ptree_sNode  *np;
  pool_tRef 	 fr;
  ptree_sNode	 *fp;
  pool_tRef	or;
  ptree_sNode  *op;
  pool_tRef	 ar;
  ptree_sAlloc *ap;
  int          i;
  pwr_tStatus sts;
  ptree_sGtable *gttp = tp->g; 

  nr = gttp->free;

  if (nr == pool_cNRef) {
    gttp->nMalloc++;
    ar = pool_RefAlloc( &sts, tp->php, gttp->allocCount * gttp->recordSize +
			sizeof(ptree_sAlloc));
    ap = (ptree_sAlloc *) pool_Address( &sts, tp->php, ar);
    ap->next = gttp->firstAlloc;
    gttp->firstAlloc = ar;
    nr = fr = (pool_tRef)( ((ptree_sAlloc *) ar) + 1);
    np = fp = (ptree_sNode *)( ap + 1);
    if (fr == pool_cNRef)
      return fr;
    fr = gttp->recordSize + fr;
    fp = (ptree_sNode *) (gttp->recordSize + (char *) fp);
    gttp->free = fr;
    gttp->nFree += gttp->allocCount;
    for (i = 1, op = fp, or = fr; i < gttp->allocCount - 1; i++) {
      fp = (ptree_sNode *) (gttp->recordSize + (char *) fp);
      fr = gttp->recordSize + fr;
      op->right = fr;
      op = fp;
    }
  } 
  else {
    np = pool_Address( &sts, tp->php, gttp->free);
    gttp->free = np->right;
  }
  gttp->nAlloc++;
  gttp->nFree--;
  np->left = np->right = np->parent = gttp->null;
  if (key != NULL)
    memcpy(gttp->keyOffset + (char *) np,  key, gttp->keySize);
  return nr;
}
Ejemplo n.º 2
0
hash_sTable *
hash_Create (
  pwr_tStatus		*sts,
  pool_sHead		*php,
  hash_sTable		*htp,
  hash_sGtable		*ghtp,
  pwr_tBoolean		(*comp_f) (const void *, void *),	/* Key comparison routine */
  pwr_tUInt32		(*xform_f) (const void *, size_t)	/* Key transformation routine */
)
{
  pwr_tUInt32		i;
  pool_sQlink		*lh;

  memset(htp, 0, sizeof(*htp));

  htp->php = php;
  ghtp->inits++;

  if (!ghtp->flags.b.created) {

    ghtp->size = nextPrime(ghtp->size);

    ghtp->table = pool_RefAlloc(sts, php, sizeof(hash_sEntry) * ghtp->size);
    if (ghtp->table == pool_cNRef) return NULL;
    htp->tp = pool_Address(sts, php, ghtp->table);
    if (htp->tp == NULL) return NULL;
    for (i = 0, lh = htp->tp; i < ghtp->size; i++, lh++)
      pool_Qinit(sts, php, lh);

    ghtp->flags.b.created = 1;
  } else {
    htp->tp = pool_Address(sts, php, ghtp->table);
  }

  htp->ghtp = ghtp;
  htp->comp_f = comp_f;
  htp->xform_f = xform_f;

  pwr_Return(htp, sts, HASH__SUCCESS);
}