コード例 #1
0
ファイル: hash.c プロジェクト: davidhoover/kent
struct hashEl *hashAddN(struct hash *hash, char *name, int nameSize, void *val)
/* Add name of given size to hash (no need to be zero terminated) */
{
struct hashEl *el;
if (hash->lm) 
    el = lmAlloc(hash->lm, sizeof(*el));
else
    AllocVar(el);
el->hashVal = hashString(name);
int hashVal = el->hashVal & hash->mask;
if (hash->lm)
    {
    el->name = lmAlloc(hash->lm, nameSize+1);
    memcpy(el->name, name, nameSize);
    }
else
    el->name = cloneStringZ(name, nameSize);
el->val = val;
el->next = hash->table[hashVal];
hash->table[hashVal] = el;
hash->elCount += 1;
if (hash->autoExpand && hash->elCount > (int)(hash->size * hash->expansionFactor))
    {
    /* double the size */
    hashResize(hash, digitsBaseTwo(hash->size));
    }
return el;
}
コード例 #2
0
ファイル: hash.c プロジェクト: Cultcoin/compiladores20141
HASH_NODE *hashInsert (HASH_TABLE *Table, char *text, int type, int lineNumber)
{
	HASH_NODE *node;
	int address;
	
	// Check if the table is getting full and resize it
	if (Table->usedEntries > hash_i*HASH_SIZE/2)
	{
		hashResize(Table);
	}

	address = 0;
	node  = hashFind(Table, text, type);

	// First check if it is in the hash
	if (node == 0)
	{
		address = hashAddress(Table, text);
		HASH_NODE *newNode;
		newNode = (HASH_NODE*)calloc(1, sizeof(HASH_NODE));
		newNode -> type = type;
		newNode -> lineNumber = lineNumber;
		newNode -> text = (char*)calloc(sizeof(strlen(text)+1), sizeof(strlen(text)+1));
		strcpy(newNode -> text, text);
		newNode -> next = Table -> node[address];
		Table -> node[address] = newNode;
		Table -> usedEntries++;
		return newNode;
	}
	else
	{		
		return node;
	}
	
}
コード例 #3
0
ファイル: hash.cpp プロジェクト: Maximus5/evil-programmers
PHashLink hashAdd(PHash h,const wchar_t *Key,void* Value)
{
  unsigned Index=hHashFunc(Key) % h->iBucketsNum;
  PHashLink link;
  h->iCount++;
  link=hlAdd(h->pPool,&h->pBuckets[Index],Key,Value);
  if(h->iCount>h->iBucketsNum*4)
  {
    hashResize(h);
  }
  return link;
}
コード例 #4
0
ファイル: hash.cpp プロジェクト: Maximus5/evil-programmers
PHashLink hashSet(PHash h,const wchar_t *Key,const void* Value)
{
  unsigned Index;
  PHashLink link=hFindLinkEx(h,Key,lstrlen(Key),&Index);
  if(link)
  {
    link->pValue=(void*)Value;
    return link;
  }else
  {
    h->iCount++;
    link=hlAdd(h->pPool,&h->pBuckets[Index],Key,Value);
    if(h->iCount>=h->iBucketsNum*2)
    {
      hashResize(h);
    }
    return link;
  }
}