Beispiel #1
0
/* allocate memory and initialize a hash map*/
hashMap *createMap(int tableSize) {
	assert(tableSize > 0);
	hashMap *ht;
	ht = malloc(sizeof(hashMap));
	assert(ht != 0);
	_initMap(ht, tableSize);
	return ht;
}
Beispiel #2
0
/*
	createMap: allocate memory and initialize a hash map
	param1: tableSize - the capacity of the table
	pre: tableSize > 0
	return: newly created hash map of size, tableSize
    post: memory for the hash map has been created
    post: hash map of size tableSize has been initialized
*/
struct hashMap *createMap(int tableSize, int ID) {
	assert(tableSize > 0);

	struct hashMap *ht;
	ht = malloc(sizeof(struct hashMap));
	assert(ht != 0); /* ensure that memory was successfully allocated */

	_initMap(ht, tableSize, ID);
	return ht;
}
/*
Resizes the hash table to be the size newTableSize
 */
void _setTableSize(struct hashMap * ht, int newTableSize)
{
	/*write this*/
	printf("========Resizing..From:%d===To:%d=====\n",ht->tableSize, newTableSize);
	//printf("COUNT %d\n", ht->count);
	int oldSize = ht->tableSize;
	struct hashMap oldHt;
	int u;
	_initMap(&oldHt, newTableSize);
	for(u=0; u < ht->tableSize; ++u){
		oldHt.table[u] = ht->table[u];
	}
	struct hashLink *current;
	int i;
	_initMap(ht, 2*oldSize);
	for(i = 0; i < oldSize; i++){
		current = oldHt.table[i];
		while(current != 0){
			insertMap(ht, current->key, current->value);
			current = current->next;
		}
	}
}
Beispiel #4
0
/*
    _reSizeTable: Resizes the hash map to the size, newCap. Rehashes all of the current keys.
    param1: hashMap - the map
	param2: newCap - the new capacity
	pre: ht is not empty
	pre: newCap is > 0
	post: ht now has tableSize, newCap.
	post: all keys have been re-hashed and inserted into ht
	HINT - use insertMap to re-hash the keys. Everything has been completed for you except the copy/re-hash.
	Free the temp data as you copy/re-hash.
*/
void _reSizeTable(struct hashMap *ht, int newCap) {
	struct hashLink *cur, *del; /* Used to free the old hash links and iterate through them */
    struct hashLink **temp = ht->table; /* pointer to the old table */
    int tempSize = ht->tableSize; /* size of the old table */
    _initMap(ht, newCap, ht->hashID); /* Re-initialize the table */
    int i;
    ValueType tempVal;
    KeyType tempKey;
    struct hashLink *tempHash;
    /* FIX ME */
    for(i =0; i< tempSize; i++){
        if(temp[i]!=NULL){
            tempVal = temp[i]->value;
            tempKey = temp[i]->key;

            insertMap(ht, tempKey, tempVal);

            tempHash = temp[i]->next;

            while(tempHash!= NULL){
                tempVal = tempHash ->value;
                tempKey = tempHash->key;
                insertMap(ht, tempKey, tempVal);

                tempHash=tempHash->next;
            }

        }
        else{
            ;//do nothing
        }
    }
    free(temp);
    free(tempHash);
    free(cur);
    free(del);

    return;
}
Beispiel #5
0
CPlayScene::CPlayScene(void)
{	
	initLoading();

	m_LocalMoneyTimeChecker = 0;
	m_StageElapsedTime = 0;

	_initBackground();
	_initMap();
	_initUI();
	loadCharacterInfo();	
	
	

	// player초기화
	m_pPlayer = CPlayer::GetInstance();
	m_pPlayer->ReadyToPlay();

	// police creator 초기화
	m_pPoliceCreator = CPoliceCreator::Create();

	// 장애물 생성기 초기화
	m_pMapObstacleManager = MapObstaclManager::Create();
	AddChild(m_pMapObstacleManager, 2);
	

	// temporary
	// FPS를 표시하고, 콘솔창을 띄움
	m_pShowMouseStatus = NNLabel::Create( L"cursor position", L"맑은 고딕", 35.f );
	m_pShowMouseStatus->SetPosition(0.0f, 0.0f);
	AddChild( m_pShowMouseStatus , 20);
	// END TEMP
	m_pShowMeatPoint = NNLabel::Create( L"Local Money", L"맑은 고딕", 30.f );
	m_pShowMeatPoint->SetPosition(0.0f, 35.0f);
	AddChild( m_pShowMeatPoint , 20);

	RemoveChild(tmp);
}
Beispiel #6
0
/*
Resizes the hash table to be the size newTableSize
*/
void _setTableSize(struct hashMap * ht, int newTableSize)
{
    struct hashLink *last, *current;

    _initMap(ht, newTableSize);

    for (int i = 0; i < ht -> tableSize; i++)
    {
        current = ht -> table[i];

        while(current != 0)
        {

	   	    insertMap(ht, current -> key, current -> value);

	   	    last = current;

	   	    current = current -> next;

	   	    free(last);
	   	}
    }
}
Beispiel #7
0
/*
 Resizes the hash table to be the size newTableSize
 */
void _setTableSize(struct hashMap * ht, int newTableSize) //group 5 worksheet 38
{
    
    hashLink **oldTable = ht->table;
    
    _initMap(ht, newTableSize);
    
    for (int i = 0; i < ht->tableSize; i++)
    {
        hashLink *currentLink = ht->table[i];
        hashLink *nextLink;
        
        while (currentLink != NULL)
        {
            insertMap(ht, currentLink->key, currentLink->value);
            nextLink = currentLink->next;
            currentLink = nextLink;
        }
    }
    
    
    free(oldTable);
    
}