示例#1
0
		virtual void Clear()
		{
            for_each(antMap.begin(), antMap.end(), deleteMap());
            for_each(foodMap.begin(), foodMap.end(), deleteMap());
			antMap.clear();
			foodMap.clear();
		}
    //------------------------------
	KinematicsIntermediateData::~KinematicsIntermediateData()
	{
		// delete joints
		deleteVectorFW(mJoints);

		// delete joint instances
		deleteVectorFW(mInstanceJoints);

		// delete kinematic models
		deleteMap(mKinematicsModels);

		// delete kinematic controllers
		deleteMap(mKinematicsControllers);

		// delete  instance kinematics scenes
		deleteVector(mInstanceKinematicsScenes);
	}
示例#3
0
int main (int argc, const char * argv[]) {
	const char* filename;
	struct hashMap *hashTable;
	int tableSize = 10;
	clock_t timer;
	FILE *fileptr;
    /*
     this part is using command line arguments, you can use them if you wish
     but it is not required. DO NOT remove this code though, we will use it for
     testing your program.

     if you wish not to use command line arguments manually type in your
     filename and path in the else case.
     */
    if(argc == 2)
        filename = argv[1];
    else
        filename = "input2.txt"; /*specify your input text file here*/

    printf("opening file: %s\n", filename);

	timer = clock();

	hashTable = createMap(tableSize);

    /*... concordance code goes here ...*/
    FILE *ifp;
    char *mode = "r";
    char *word, key;
    ifp = fopen(filename, mode);
    assert(ifp);
    while((word = getWord(ifp)) != NULL){
            if(word)
                insertMap(hashTable, word, 1);
    }
    fclose(ifp);
	/*... concordance code ends here ...*/

	printMap(hashTable);
	timer = clock() - timer;
	printf("\nconcordance ran in %f seconds\n", (float)timer / (float)CLOCKS_PER_SEC);
	printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
    printf("Table count = %d\n", size(hashTable));
	printf("Table capacity = %d\n", capacity(hashTable));
	printf("Table load = %f\n", tableLoad(hashTable));

    printf("Deleting keys\n");

	removeKey(hashTable, "bitter");
	removeKey(hashTable, "me");
	removeKey(hashTable, "the");
//	printMap(hashTable);

	deleteMap(hashTable);
	printf("\nDeleted the table\n");
	return 0;
}
示例#4
0
void ServicesDb::deleteUser(long userId)
{
  QSqlQuery maps = _exec("SELECT id FROM maps WHERE user_id=:user_id", (qlonglong)userId);

  // delete all the maps owned by this user
  while (maps.next())
  {
    long mapId = maps.value(0).toLongLong();
    deleteMap(mapId);
  }

  _exec("DELETE FROM users WHERE id=:id", (qlonglong)userId);
}
示例#5
0
bool DataGrid::createMap(unsigned const int w, unsigned const int h) {
	if (w != 0 && h != 0) {
		deleteMap();
		_width = w;
		_height = h;
		_data = new int*[width()];
		if (_data != 0) {
			for (unsigned int x = 0; x < width(); x++)
				_data[x] = new int[height()];
		}
		return true;
	}
	return false;
}
示例#6
0
Map Map::operator= (Map m)
{
  deleteMap();
  createMap(m.levels, m.width, m.height);

  for( int i = 0; i < levels; i++ )
    for( int j = 0; j < height; j++ )
      for( int k = 0; k < width; k++ )
      {
        cubes[i][j][k].setInfection(m.cubes[i][j][k].getInfection());
        cubes[i][j][k].setTransparent(m.cubes[i][j][k].isTransparent());
      }

  return *this;
}
示例#7
0
void CGameLayer::switchMap(int mapid,int cx,int cy)
{
	deleteMap();
	m_pMap = GameMap::create();
	if ( !m_pMap )
	{
		return ;
	}

	gNetDispatcher->Lock();
	m_pMap->retain();

	m_mapLoader.setMapID(mapid,cx,cy);
	m_mapLoader.loadAsync();
}
示例#8
0
bool Map::createMap( int l, int w, int h )
{
  width = w;
  height = h;
  levels = l;
  error = false;

  if(cubes)
    deleteMap();
  
  cubes = new Cube**[levels];
  if(!cubes)
  {
    error = true;
    return !error;
  }

  for( int i = 0; i < levels; i++ )
  {
    cubes[i] = new Cube*[height];
    if(!cubes[i])
    {
      error = true;
      return !error;
    }

    for( int j = 0; j < height; j++ )
    {
      cubes[i][j] = new Cube[width];
      if(!cubes[i][j])
      {
        error = true;
        return !error;
      }

      for( int k = 0; k < width; k++ )
      {
        cubes[i][j][k].setInfection(0);
        cubes[i][j][k].setTransparent(true);
      }
    }
  }

  return !error;
}
示例#9
0
Map *Map::copyOf( Map* m )
{
  deleteMap();

  if(!m)
    return NULL;

  createMap(m->levels, m->width, m->height);

  for( int i = 0; i < levels; i++ )
    for( int j = 0; j < height; j++ )
      for( int k = 0; k < width; k++ )
      {
        cubes[i][j][k].setInfection(m->cubes[i][j][k].getInfection());
        cubes[i][j][k].setTransparent(m->cubes[i][j][k].isTransparent());
      }

  return this;
}
示例#10
0
int main(int argc, char** argv) {
  HashMap* map = newMap(40, &testHashFunction, &testComparator, &testKeyCopy);
  Hash key = 0;
  Key testKeyPtr = (Key) &key;
  incrementKeyValue(map, testKeyPtr);
  incrementKeyValue(map, testKeyPtr);
  incrementKeyValue(map, testKeyPtr);
  Hash key2 = 20;
  Key testKeyPtr2 = (Key) &key2;
  incrementKeyValue(map, testKeyPtr2);
  incrementKeyValue(map, testKeyPtr2);
  printf("key = %d\n", get(map, testKeyPtr));
  printf("key2 = %d\n", get(map, testKeyPtr2));
  Hash key3 = 18;
  Key testKeyPtr3 = (Key) &key3;
  incrementKeyValue(map, testKeyPtr3);
  incrementKeyValue(map, testKeyPtr3);
  incrementKeyValue(map, testKeyPtr3);
  incrementKeyValue(map, testKeyPtr3);
  printf("key3 = \%d\n", get(map, testKeyPtr3));
  deleteMap(map);
}
示例#11
0
DataGrid::~DataGrid() {
	deleteMap();
}
示例#12
0
文件: main.c 项目: wsims/CS261
int main (int argc, const char * argv[]) {
	const char* filename;
	struct hashMap *hashTable;
	int tableSize = 10;
	clock_t timer;
	FILE *fileptr;
    /*
     this part is using command line arguments, you can use them if you wish
     but it is not required. DO NOT remove this code though, we will use it for
     testing your program.

     if you wish not to use command line arguments manually type in your
     filename and path in the else case.
     */
    if(argc == 2)
        filename = argv[1];
    else
        filename = "input1.txt"; /*specify your input text file here*/

    printf("opening file: %s\n", filename);

	timer = clock();

	hashTable = createMap(tableSize);

    /*... concordance code goes here ...*/
    fileptr = fopen(filename, "r");
    if (fileptr != NULL) {
        int *val, *x;
        char *word;
        while ((word = getWord(fileptr))) {
            if (containsKey(hashTable, word)) {
                val = (int *) atMap(hashTable, word);
                (*val) ++;
                free(word);
            } else {
                x = malloc(sizeof(int));
                *x = 1;
                insertMap(hashTable, word, x);
            }
        }
        fclose(fileptr);
    } else printf("Error opening file.\n");
	/*... concordance code ends here ...*/

	printMap(hashTable, keyPrint, valPrint);
	timer = clock() - timer;
	printf("\nconcordance ran in %f seconds\n", (float)timer / (float)CLOCKS_PER_SEC);
	printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
    printf("Table count = %d\n", size(hashTable));
	printf("Table capacity = %d\n", capacity(hashTable));
	printf("Table load = %f\n", tableLoad(hashTable));

	printf("Deleting keys\n");

	removeKey(hashTable, "and");
	removeKey(hashTable, "me");
	removeKey(hashTable, "the");
    printMap(hashTable, keyPrint, valPrint);
    printKeyValues(hashTable, keyPrint, valPrint);
         /* Test out the iterator */
#ifdef ITERATOR_IN
         struct mapItr *myItr;
         myItr = createMapIterator(hashTable);

         KeyType  key;

         /* Free up our keys and values using our iterator!!  Also printing them as we go along */
         while(hasNextMap(myItr))
           {
             key = nextMap(myItr);
             int *value = atMap(hashTable,key);
             printf("Freeing ...Key = %s, value = %d \n", key, *value);
             free(value);  /* To match the malloc above*/
             free(key);

           }
#endif


        deleteMap(hashTable);
	printf("\nDeleted the table\n");
	return 0;
}
示例#13
0
int main (int argc, const char * argv[]) {
    const char* filename;
    struct hashMap *hashTable;
    int tableSize = 10;
    clock_t timer;
    FILE *fileptr;
    /*
     this part is using command line arguments, you can use them if you wish
     but it is not required. DO NOT remove this code though, we will use it for
     testing your program.

     if you wish not to use command line arguments manually type in your
     filename and path in the else case.
     */
    if(argc >= 2)
        filename = argv[1];
    else
        filename = "input1.txt"; /*specify your input text file here*/

    printf("opening file: %s\n", filename);

    fileptr = fopen(filename, "r");
    if(fileptr == NULL) {
        char err[255];
        sprintf(err, "Failure opening file %s; exiting.\n", filename);
        perror(err);
        exit(EXIT_FAILURE);
    }

    timer = clock();

    hashTable = createMap(tableSize);

    char *curr;
    ValueType *val;

    while((curr = getWord(fileptr)) != NULL) {
        if((val = atMap(hashTable, curr)) != NULL)
            (*val)++;
            //insertMap(hashTable, curr, (*val)+1);
        else
            insertMap(hashTable, curr, 1);
        free(curr);
    }

    fclose(fileptr);
    //fclose(outfileptr);

    printMap(hashTable);
    timer = clock() - timer;
    printf("\nconcordance ran in %f seconds\n", (float)timer / (float)CLOCKS_PER_SEC);
    printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
    printf("Table count = %d\n", size(hashTable));
    printf("Table capacity = %d\n", capacity(hashTable));
    printf("Table load = %f\n", tableLoad(hashTable));

    printf("Deleting keys\n");

    removeKey(hashTable, "and");
    removeKey(hashTable, "me");
    removeKey(hashTable, "the");
    //printMap(hashTable);

    deleteMap(hashTable);
    printf("\nDeleted the table\n");
    return 0;
}
示例#14
0
CGameLayer::~CGameLayer()
{
	removeFromParent();
	deleteMap();
}
示例#15
0
int main (int argc, const char * argv[]) {
	const char* filename;
	struct hashMap *hashTable;	
	int tableSize = 10;
	clock_t timer;
	FILE *fileptr;	
    /*
     this part is using command line arguments, you can use them if you wish
     but it is not required. DO NOT remove this code though, we will use it for
     testing your program.
     
     if you wish not to use command line arguments manually type in your
     filename and path in the else case.
     */
    if(argc == 2)
        filename = argv[1];
    else
        filename = "input1.txt"; /*specify your input text file here*/
    
    printf("opening file: %s\n", filename);
    
	timer = clock();
	
	hashTable = createMap(tableSize);	   
	
    /*... concordance code goes here ...*/
	fileptr = fopen(filename, "r");
	char* word;
	char words[95][16];   // store words here to print later
	
  
	int count = 0;  

	// loop over words in filename adding them to the map
	while (( word = getWord(fileptr)))
	  {
	    //words[count] = malloc(strlen(word));
	    strcpy(words[count],word);
	    count++;
	    
	    if (containsKey(hashTable, word))
	      {
		ValueType *val = atMap(hashTable, word);
		(*val)++;
		free(word);
	      }
	    else
	      {
		insertMap(hashTable, word, 1);
	      }
	    
	  }
	fclose(fileptr);

	// loop over words
	printf("word count: %d\n",count);
	printf("table size: %d\n",hashTable->tableSize);

	for (int i=0; i < count; i++)
	  {
	    //int v = val;
	    word = words[i];
	    //printf("%d: ",i);
	    printf("%s: ",word);
	    printf("%d \n",(*atMap(hashTable,word)));
	  }
	/*... concordance code ends here ...*/

	printMap(hashTable);
	timer = clock() - timer;
	printf("\nconcordance ran in %f seconds\n", (float)timer / (float)CLOCKS_PER_SEC);
	printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
	printf("Table count = %d\n", size(hashTable));
	printf("Table capacity = %d\n", capacity(hashTable));
	printf("Table load = %f\n", tableLoad(hashTable));
	
	printf("Deleting keys\n");
	
	removeKey(hashTable, "and");
	removeKey(hashTable, "me");
	removeKey(hashTable, "the");
	printMap(hashTable);
		
	deleteMap(hashTable);
	printf("\nDeleted the table\n");   
	return 0;
}
示例#16
0
void BaseApplication::buttonHit(OgreBites::Button* button)
{
    //over kill for now
    mTypingPassword = false;
    mTypingUsername = false;

    if(button->getName().compare("account") == 0)        
    {
        removeMainMenu();
        setupAccountMenu();      
        return;
    }
        if(button->getName().compare("create") == 0)
        {
            removeAccountMenu();
            setupCreateAccountMenu();
            return;
        }
            if(button->getName().compare("create uname") == 0)
            {
                mTypingUsername = true;
                mUsername = "";
                mUsernameButton->setCaption(mUsername);
                return;
            }
            if(button->getName().compare("create pass") == 0)
            {
                mTypingPassword = true;
                mPassword = "";
                mPasswordButton->setCaption(mPassword);
                return;
            }
            if(button->getName().compare("confirm account") == 0)
            {
                if(mUsername == "")
                {
                    mMenuLabel->setCaption("Please Enter a Username");
                    return;
                }
                if(mPassword == "")
                {
                    mMenuLabel->setCaption("Please Enter a Password");
                    return;
                }
                if(mStats->createAccount(mUsername, mPassword))
                {
                    mStats->save();
                    removeCreateAccountMenu();
                    setupMainMenu();
                }   
                else
                {
                    mMenuLabel->setCaption("Username is Taken :(");
                }

                return;
            }
            if(button->getName().compare("back from create account") == 0)
            {
                if(!mStats->isLoggedIn())
                {
                    mUsername = "";
                    mPassword = "";
                }
                removeCreateAccountMenu();
                setupAccountMenu();
                return;
            }
        if(button->getName().compare("login") == 0)
        {
            removeAccountMenu();
            setupLoginMenu();
            return;
        }
            if(button->getName().compare("login uname") == 0)
            {
                mTypingUsername = true;
                mUsername = "";
                mUsernameButton->setCaption(mUsername);
                return;
            }
            if(button->getName().compare("login pass") == 0)
            {
                mTypingPassword = true;
                mPassword = "";
                mPasswordButton->setCaption(mPassword);
                return;
            }
            if(button->getName().compare("login to account") == 0)
            {
                if(mUsername == "")
                {
                    mMenuLabel->setCaption("Please Enter a Username");
                    return;
                }
                if(mPassword == "")
                {
                    mMenuLabel->setCaption("Please Enter a Password");
                    return;
                }
                if(mStats->login(mUsername, mPassword))
                {
                    removeLoginMenu();
                    setupMainMenu();
                }   
                else
                {
                    mMenuLabel->setCaption("Failed to Log in :(");
                }

                return;
            }
            if(button->getName().compare("back from login") == 0)
            {
                if(!mStats->isLoggedIn())
                {
                    mUsername = "";
                    mPassword = "";
                }
                removeLoginMenu();
                setupAccountMenu();
                return;
            }
        if(button->getName().compare("logout") == 0)
        {
            mStats->logout();
            mUsername = "";
            mPassword = "";
            removeAccountMenu();
            setupAccountMenu();
            return;
        }
        if(button->getName().compare("backfromsetup") == 0)
        {
            removeAccountMenu();
            setupMainMenu();
            return;
        }
    if(button->getName().compare("start") == 0)        
    {
        removeMainMenu();
        setupDifficultyMenu();      
        return;
    }       
    else if(button->getName().compare("sound") == 0 )
    {  
        removeMainMenu();
        setupSoundMenu();  
        return;
    }
    else if(button->getName().compare("help") == 0 )
    {  
        removeMainMenu();
        setupHelpMenu();  
        return;
    }
        else if(button->getName().compare("helpToMain") == 0 )
        {  
            removeHelpMenu();
            setupMainMenu();  
            return;
        }
        else if(button->getName().compare("control") == 0 )
        {  
            removeHelpMenu();
            setupControlMenu();  
            return;
        }
            else if(button->getName().compare("back from control") == 0 )
            {  
                removeControlMenu();
                setupHelpMenu();  
                return;
            }
        else if(button->getName().compare("info") == 0)
        {
            removeHelpMenu();
            setupInfoMenu();
            return;
        }
            else if(button->getName().compare("back from info") == 0 )
            {  
                removeInfoMenu();
                setupHelpMenu();  
                return;
            }
    else if(button->getName().compare("credit") == 0)
    {
        removeMainMenu(); 
        deleteMap(); // delete loading level
        mDifficulty = 5;
        mLevel = 1; 
        createObjects();              
        mGameStart= true;        
        mTrayMgr->hideCursor();      
        setupGUI(gameMap->getName()); 
        return;

    }
    else if(button->getName().compare("quit") == 0)
    {
        removeMainMenu();
        if(mStats->isLoggedIn())
        {
            mStats->save();
        }
        mShutDown = true;
    }
    else if(button->getName().compare("on") == 0 )
    {
        mMusic = true;
        bgm = true;
        soundeffect =true;        
        return;
    }
    else if(button->getName().compare("off") == 0 )
    {  
        mMusic = false;
        bgm = false;
        soundeffect =false;       
        return;
    }
    else if(button->getName().compare("bgm on") == 0 )
    {
        bgm = true;        
        return;
    }
    else if(button->getName().compare("bgm off") == 0 )
    {  
        bgm = false;       
        return;
    }
    else if(button->getName().compare("effect on") == 0 )
    {
        soundeffect = true;        
        return;
    }
    else if(button->getName().compare("effect off") == 0 )
    {  
        soundeffect = false;       
        return;
    }
    else if(button->getName().compare("sound to main") == 0 )
    {
        removeSoundMenu();         
        setupMainMenu();
        return;
    }
    for(int x = 1; x <= Level::numDifficulties(); x++)
    {
        // for clicking on the difficulty and loading the levels
        if(button->getName().compare(Level::difficultyName(x)) == 0 )       
        {       
            removeDifficultyMenu();
            setupLevelSelect(x);
            return;
        }
        // for clicking back to select difficulty
        if(button->getName().compare("back to select difficulty " + Level::difficultyName(x)) == 0)
        {
            removeLevelSelect(x);
            setupDifficultyMenu();   
            return;
        }
    }
    if(button->getName().compare("back to main menu") == 0 )
    {
        removeDifficultyMenu();
        setupMainMenu(); 
        return;
    }
    for(int x = 1; x <= Level::numDifficulties(); x++)
    {
        for(int y = 1; y <= Level::numLevels(x); y++)
        {
            std::string name = Level::difficultyName(x) + " " + patch::to_string(y);
            if(button->getName().compare(name) == 0)
            {
                removeLevelSelect(x);
                deleteMap();
                mDifficulty =x;
                mLevel = y; 
                createObjects();              
                mGameStart = true;        
                mTrayMgr->hideCursor();      
                setupGUI(gameMap->getName()); 
                return;   
            }
        }
    }


    if(button->getName().compare("quit level") == 0 )
    {
        removeLevelMenu();
        deleteMap();
        mGameStart = false;
        setupMainMenu();
        levelLoaded = false;
        music = Mix_LoadMUS("Music/0/bgm2.mp3");
        Mix_PlayMusic(music,-1);
        if(mStats->isLoggedIn())
        {
            mStats->update(mDifficulty, mLevel, mDeathCounter, mStopwatch->elapsedTime(), false);
        }
        mStopwatch->reset();
        mDeathCounter = 0;
        return;
    }
    else if(button->getName().compare("resume level") == 0 )
    {
        removeLevelMenu();
        setupGUI(gameMap->getName());
        mStopwatch->unpause();
        return;
    }
    else if(button->getName().compare("surrender") == 0 )
    {
        removeDeathMenu();
        deleteMap();
        mGameStart = false;
        setupMainMenu();
        levelLoaded = false;
        music = Mix_LoadMUS("Music/0/bgm2.mp3");
        Mix_PlayMusic(music,-1);
        if(mStats->isLoggedIn())
        {
            mStats->update(mDifficulty, mLevel, mDeathCounter+1, mStopwatch->elapsedTime(), false);
        }
        mStopwatch->reset();
        mDeathCounter = 0;
        //SAVE AND LOAD
        return;
    }
    else if(button->getName().compare("better") == 0 )
    {
        mCanRespawn = false;
        removeDeathMenu();
        setupGUI(gameMap->getName());
        gameMap->respawn();
        mDeathCounter += 1;
        if(mDeathCounter == 1)
        {
            mNumDeaths->setCaption(patch::to_string(mDeathCounter) + " death");
        }
        else
        {
            mNumDeaths->setCaption(patch::to_string(mDeathCounter) + " deaths");
        }
        mTrayMgr->hideCursor();
        return;
    }


   
}
示例#17
0
bool BaseApplication::frameRenderingQueued(const Ogre::FrameEvent& evt)
{
    if(mWindow->isClosed())
        return false;

    //run save code then shut down

    if(mShutDown)
    {
        if(mStats->isLoggedIn())
        {
            mStats->save();
        }
        return false;
    }
    // Need to capture/update each device
    mKeyboard->capture();
    mMouse->capture();
    if(!mMusic)
    {
        Mix_PauseMusic();
        Mix_Volume(-1, 0);
        if(bgm)
        {
             Mix_ResumeMusic();
        }
        if(soundeffect)
        {
             Mix_Volume(-1, 110);
        }
    }
    else if(mMusic)
    {
        Mix_ResumeMusic();
        Mix_Volume(-1, 110);
        if(!bgm)
        {
             Mix_PauseMusic();
        }
        if(!soundeffect)
        {
             Mix_Volume(-1, 0);
        }
    }
    if(mGameStart && !mInMenu)
    {
        if(player->levelFinished)
        {
            if(mStats->isLoggedIn())
            {
                mStats->update(mDifficulty, mLevel, mDeathCounter, mStopwatch->elapsedTime(), true);
            }
            calcNextLevel();
            deleteMap();
            createObjects();
            mLevelName->setCaption(gameMap->getName());
            mStopwatch->reset();
            mDeathCounter = 0;
            mNumDeaths->setCaption(patch::to_string(mDeathCounter) + " deaths");
            //SAVE AND LOAD
        }

        mPlayerHp->setProgress((player->health)/100.0);
        mPlayerHp->setCaption("current HP is " + patch::to_string(player->health) + "/100");
        mTime->setCaption(patch::to_string(int(mStopwatch->elapsedTime() / 100.0 ) / 10.0) + " seconds");
        Ogre::SceneNode* tem = mSceneMgr->getSceneNode("playerNode");    
        Ogre::Vector3 position = tem->getPosition();
        mCamera->setPosition(position.x , 300, position.z+200);
        if(gameMap->isPlayerAlive())
        {
            if(wisDown)
                gameMap->move(0);
            else if(disDown)
                gameMap->move(1);
            else if(sisDown)
                gameMap->move(2);
            else if(aisDown)
                gameMap->move(3);
            if(!mStopwatch->isRunning() && (sisDown || wisDown || disDown || aisDown))
            {
                mStopwatch->start();
            }
        }
        else
        {
            setupDeathMenu();  
            mTrayMgr->showCursor();
            mCanRespawn = true;
        }
        gameMap->simulate(evt.timeSinceLastFrame);  
        // mSimulator->stepSimulation(evt.timeSinceLastFrame, music2);
    }
    else if (!mGameStart) //should be the loadinglevel
    {
        if(!levelLoaded)
        {
            mDifficulty = 0;
            mLevel = 0;
            mOldDifficulty =0;
            createObjects();       
            levelLoaded = true;   
            Ogre::SceneNode* tem = mSceneMgr->getSceneNode("playerNode");    
            Ogre::Vector3 position = tem->getPosition();
            mCamera->setPosition(position.x , 300, position.z+300);        
        }
        else
        {
            gameMap->simulate(evt.timeSinceLastFrame);
        }
    }

    mTrayMgr->frameRenderingQueued(evt);

    if (!mTrayMgr->isDialogVisible())
    {
        mCameraMan->frameRenderingQueued(evt);   // If dialog isn't up, then update the camera
        if (mDetailsPanel->isVisible())          // If details panel is visible, then update its contents
        {
            mDetailsPanel->setParamValue(0, Ogre::StringConverter::toString(mCamera->getDerivedPosition().x));
            mDetailsPanel->setParamValue(1, Ogre::StringConverter::toString(mCamera->getDerivedPosition().y));
            mDetailsPanel->setParamValue(2, Ogre::StringConverter::toString(mCamera->getDerivedPosition().z));
            mDetailsPanel->setParamValue(4, Ogre::StringConverter::toString(mCamera->getDerivedOrientation().w));
            mDetailsPanel->setParamValue(5, Ogre::StringConverter::toString(mCamera->getDerivedOrientation().x));
            mDetailsPanel->setParamValue(6, Ogre::StringConverter::toString(mCamera->getDerivedOrientation().y));
            mDetailsPanel->setParamValue(7, Ogre::StringConverter::toString(mCamera->getDerivedOrientation().z));
        }
    }

    return true;
}
示例#18
0
int main (int argc, const char * argv[]) {
	const char* filename;
	struct hashMap *hashTable;
	int tableSize = 10;
	clock_t timer;

    /*
     this part is using command line arguments, you can use them if you wish
     but it is not required. DO NOT remove this code though, we will use it for
     testing your program.

     if you wish not to use command line arguments manually type in your
     filename and path in the else case.
     */
    if(argc == 2)
        filename = argv[1];
    else
        filename = "input1.txt"; /*specify your input text file here*/

    printf("opening file: %s\n", filename);

	timer = clock();

	hashTable = createMap(tableSize);

    /*... concordance code goes here ...*/
    FILE *file;
    file = fopen(filename, "r");
    /* if there is no file named that */
    if(!file){
        printf("Unable to open file. \n");
    }
    /* loops until the end of the file */
    while(!feof(file)){
        char *word = getWord(file);
        if(word){
            if(containsKey(hashTable, word)){
                int *value = atMap(hashTable, word);
                ++(*value);
            }
            else{
            insertMap(hashTable, word, 1);
            }
        }
    }


	/*... concordance code ends here ...*/

	printMap(hashTable);
	timer = clock() - timer;
	printf("\nconcordance ran in %f seconds\n", (float)timer / (float)CLOCKS_PER_SEC);
	printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
    printf("Table count = %d\n", size(hashTable));
	printf("Table capacity = %d\n", capacity(hashTable));
	printf("Table load = %f\n", tableLoad(hashTable));

	printf("Deleting keys\n");

	removeKey(hashTable, "and");
	removeKey(hashTable, "me");
	removeKey(hashTable, "the");
	printMap(hashTable);

	deleteMap(hashTable);
	printf("\nDeleted the table\n");
	return 0;
}
示例#19
0
int main (int argc, const char * argv[]) {
	const char* filename;
	struct hashMap *hashTable;	
	char *word;
	int tableSize = 10;
	clock_t timer;
	FILE *fileptr;
	int *numWordOccurances;	
    /*
     this part is using command line arguments, you can use them if you wish
     but it is not required. DO NOT remove this code though, we will use it for
     testing your program.
     
     if you wish not to use command line arguments manually type in your
     filename and path in the else case.
     */
    if(argc == 2)
        filename = argv[1];
    else
        filename = "input1.txt"; /*specify your input text file here*/
    
    	printf("opening file: %s\n", filename);

	timer = clock();
	
	hashTable = createMap(tableSize);	   
	
	// generate concordance
	fileptr = fopen(filename,"r");	
	while (!feof(fileptr)) {	

		word = getWord(fileptr);

		if(!word){
			break;
		}
		numWordOccurances = (int *)atMap(hashTable, word); /* cast return of atMap to int*/
		
		if(numWordOccurances!=0){			
			(*numWordOccurances)++;
		} else {
			/* need to malloc numWordOccurances before insertMap*/
			numWordOccurances = (int *) malloc(sizeof(int));
			*numWordOccurances = 1;
			insertMap(hashTable, word, numWordOccurances);		
		}
	}	

	// print concordance
	printMap(hashTable);
	
	// print hashmap statistices
	fclose(fileptr);
	timer = clock() - timer;
	printf("\nconcordance ran in %f seconds\n", (float)timer / (float)CLOCKS_PER_SEC);
	printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
    printf("Table count = %d\n", size(hashTable));
	printf("Table capacity = %d\n", capacity(hashTable));
	printf("Table load = %f\n", tableLoad(hashTable));
	
	printf("Deleting keys: \"and\", \"me\", and \"the\"\n");
	
	removeKey(hashTable, "and");
	removeKey(hashTable, "me");
	removeKey(hashTable, "the");
	printMap(hashTable);
		
	deleteMap(hashTable);
	printf("\nDeleted the table\n");   
	return 0;
}
示例#20
0
文件: main.c 项目: gpard77/cs261
int main (int argc, const char * argv[]) {
	const char* filename;
	struct hashMap *hashTable;	
	int tableSize = 10;
	clock_t timer;
	FILE *fileptr;	
    /*
     this part is using command line arguments, you can use them if you wish
     but it is not required. DO NOT remove this code though, we will use it for
     testing your program.
     
     if you wish not to use command line arguments manually type in your
     filename and path in the else case.
     */
    if(argc == 2)
        filename = argv[1];
    else
        filename = "input1.txt"; /*specify your input text file here*/
    
    printf("opening file: %s\n", filename);
    
	timer = clock();
	
	hashTable = createMap(tableSize);	   
	
    /*... concordance code goes here ...*/
	fileptr = fopen(filename, "r");

	if (!fileptr)
	{
	   printf("Error Opening File.\n");
	}

	char *word = getWord(fileptr);
	//ValueType val;
	
	while (word != 0)
	{
	   //char *word = getWord(fileptr);
	   // Check table for word, insert if not found
	   if (containsKey(hashTable, word)== 0)
	   {
	      insertMap(hashTable, word, 1);
	   }
	   else
	   {
	       (*atMap(hashTable, word))++;
	   }
	   word = 0;
	   free(word);
	   word = getWord(fileptr);
	}

	fclose(fileptr);
	
	printf("\n");
	hashLink * temp;

	for (int i = 0; i < hashTable->tableSize; i++)
	{
	   temp = hashTable->table[i];
	   while (temp != 0)
	   {
	      printf("%s: %d\n", temp->key, temp->value);
	      temp = temp->next;
	   }
	}
	free(temp);	
	/*... concordance code ends here ...*/

	printMap(hashTable);
	timer = clock() - timer;
	printf("\nconcordance ran in %f seconds\n", (float)timer / (float)CLOCKS_PER_SEC);
	printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
    printf("Table count = %d\n", size(hashTable));
	printf("Table capacity = %d\n", capacity(hashTable));
	printf("Table load = %f\n", tableLoad(hashTable));
	
	printf("Deleting keys\n");
	
	removeKey(hashTable, "and");
	removeKey(hashTable, "me");
	removeKey(hashTable, "the");
	printMap(hashTable);
		
	deleteMap(hashTable);
	printf("\nDeleted the table\n");   
	return 0;
}
   // -------------------------------------------------------------
   TRasterMapsDialog::TRasterMapsDialog(IMapAdapterInterfaces MapInterfaces_,
                                        QString Organization_, QString Application_, QWidget *Parent_)
      : QDialog(Parent_), PI(acos(-1.0)), m_Organization(Organization_), m_Application(Application_),
        m_Mode(Consts::ListMode), m_KeyControlPressed(false)
   {
   setWindowTitle(QNetMapTranslator::tr("Raster map list" /* Russian: Список растровых карт */));
   QPalette palette/*(palette())*/;
   palette.setColor(backgroundRole(), Qt::white);
   setPalette(palette);
   setAutoFillBackground(true);

   setMinimumSize(800, 600);
   // карта
   w_MapWidget = new TMapWidget(MapInterfaces_, "", 12, QPointF(0,0), Organization_, Application_);
   // Лайаут основной
   setLayout(&m_MainVerticalLayout);
   m_MainVerticalLayout.setSpacing(8);
   m_MainVerticalLayout.setMargin(8);

   // Лайаут для размещения элементов верхней строки с подсказкой
   QHBoxLayout *TopLayout = new QHBoxLayout;
   m_MainVerticalLayout.addLayout(TopLayout);
   TopLayout->addWidget(&m_TextHint);
   hint(QNetMapTranslator::tr("Select the map or action" /* Russian: Выберите карту или действие */));
   TopLayout->addStretch();
   // Лайаут для списка, кнопок и карты
   QHBoxLayout *MiddleLayout = new QHBoxLayout;
   m_MainVerticalLayout.addLayout(MiddleLayout);
   // Лайаут для списка и кнопок
   QVBoxLayout *ListLayout = new QVBoxLayout;
   // Лайаут для карты
   QVBoxLayout *MapLayout = new QVBoxLayout;

   // Путь к карте
   MapLayout->addWidget(&m_MapPath);
   // Рамка для виджета карты
   QFrame *MapWidgetFrame = new QFrame;
   MapWidgetFrame->setFrameStyle(QFrame::Box | QFrame::Plain);
   QHBoxLayout *MapWidgetFrameLayout = new QHBoxLayout(MapWidgetFrame);
   MapWidgetFrameLayout->setMargin(0);
   MapWidgetFrameLayout->addWidget(w_MapWidget);
   MapLayout->addWidget(MapWidgetFrame);
   // лайоут для списка точек привязки
   w_MapAnchors = new QVBoxLayout;
   w_MapAnchors->setMargin(0);
   MapLayout->addLayout(w_MapAnchors);

   // Список карт
   QStringList ListMaps;
   IMapAdapterInterfaces RasterMapInterfaces = w_MapWidget->rasterMapInterfaces();
   foreach(IMapAdapterInterface* Interface, RasterMapInterfaces) {
      ListMaps << Interface->pluginName();
      }
   m_Model.setStringList(ListMaps);
   m_MapsListView.setModel(&m_Model);
   ListLayout->addWidget(&m_MapsListView);
   QGroupBox *ListGroup = new QGroupBox(QNetMapTranslator::tr("Raster maps" /* Russian: Растровые карты */));
   ListGroup->setMaximumWidth(200);
   ListGroup->setLayout(ListLayout);
   
   // кнопки
   m_CenterMapButton.setText(QNetMapTranslator::tr("Map's center" /* Russian: Центр карты */));
   m_LinkingButton.setText(QNetMapTranslator::tr("Add reference points..." /* Russian: Привязать... */));
   m_DeleteLinkingButton.setText(QNetMapTranslator::tr("Delete reference points" /* Russian: Удалить привязку */));
   m_AddButton.setText(QNetMapTranslator::tr("Add to list..." /* Russian: Добавить в список... */));
   m_DeleteButton.setText(QNetMapTranslator::tr("Delete from list" /* Ru: Удалить из списка */));
   m_ExitDialogButton.setText(QNetMapTranslator::tr("OK"));
   ListLayout->addWidget(&m_CenterMapButton);
   ListLayout->addWidget(&m_LinkingButton);
   ListLayout->addWidget(&m_DeleteLinkingButton);
   ListLayout->addWidget(&m_AddButton);
   ListLayout->addWidget(&m_DeleteButton);
   ListLayout->addItem(new QSpacerItem(0, 7));
   ListLayout->addWidget(&m_ExitDialogButton);

   // Кнопки подтверждения / отмены
   m_ButtonBox.setMinimumSize(QSize(0, 30));
   m_ButtonBox.setOrientation(Qt::Horizontal);
   m_ButtonBox.setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
   // находим кнопку ОК и делаем ее недоступной
   QList<QAbstractButton*> ListButtons = m_ButtonBox.buttons();
   foreach(QAbstractButton* Button, ListButtons) {
      if(m_ButtonBox.buttonRole(Button) == QDialogButtonBox::AcceptRole) {
         w_ButtonOK = Button;
         w_ButtonOK->setEnabled(false);
         break;
         }
      }
   MapLayout->addWidget(&m_ButtonBox);
   m_ButtonBox.setVisible(false);   

   MiddleLayout->addWidget(ListGroup);
   MiddleLayout->addLayout(MapLayout);
   // устанавливаем текущей первую карту в списке
   if(m_Model.rowCount()) mapNameClicked(m_Model.index(0, 0));

   // сигналы
   QNM_DEBUG_CHECK(connect(&m_MapsListView,     SIGNAL(clicked(const QModelIndex&)),   
                  this,                SLOT(mapNameClicked(const QModelIndex&))));
   QNM_DEBUG_CHECK(connect(&m_MapsListView,     SIGNAL(activated(const QModelIndex&)), 
                  this,                SLOT(mapNameClicked(const QModelIndex&))));
   QNM_DEBUG_CHECK(connect(&m_ButtonBox,        SIGNAL(accepted()), this, SLOT(acceptLinking())));
   QNM_DEBUG_CHECK(connect(&m_ButtonBox,        SIGNAL(rejected()), this, SLOT(rejectLinking())));
   QNM_DEBUG_CHECK(connect(&m_AddButton,        SIGNAL(clicked()),  this, SLOT(addMap())));
   QNM_DEBUG_CHECK(connect(&m_DeleteButton,     SIGNAL(clicked()),  this, SLOT(deleteMap())));
   QNM_DEBUG_CHECK(connect(&m_LinkingButton,    SIGNAL(clicked()),  this, SLOT(viewMap())));
   QNM_DEBUG_CHECK(connect(&m_DeleteLinkingButton, SIGNAL(clicked()), this, SLOT(deleteLinking())));
   QNM_DEBUG_CHECK(connect(&m_CenterMapButton,  SIGNAL(clicked()),  this, SLOT(viewCenterMap())));
   QNM_DEBUG_CHECK(connect(&m_ExitDialogButton, SIGNAL(clicked()),  this, SLOT(accept())));
   //
   widgetsEnabling();
   }
示例#22
0
int main (int argc, const char * argv[]) {
	char *word;
	ValueType *value;
	const char* filename;
	struct hashMap *hashTable;
	int tableSize = 10;
	clock_t timer;
	FILE *fileptr;	
    /*
     this part is using command line arguments, you can use them if you wish
     but it is not required. DO NOT remove this code though, we will use it for
     testing your program.
     
     if you wish not to use command line arguments manually type in your
     filename and path in the else case.
     */
    if(argc == 2)
        filename = argv[1];
    else
        filename = "input1.txt"; /*specify your input text file here*/
    
    printf("opening file: %s\n", filename);
    
	timer = clock();
	
	hashTable = createMap(tableSize);	   
	
	/*... concordance code goes here ...*/
	fileptr = fopen(filename, "r");
	
	
	while(1){
		
		word = getWord(fileptr);
		if(word == NULL){
			break;
		}		
		value = atMap(hashTable, word);
		if(value == NULL)
		{
			value = malloc(sizeof(int*));
			*((int*)value) = 1;
		}
		else if(value != NULL)
		{
			*((int *)value) += 1;
		}
		insertMap(hashTable, word, ((void *)value));
	
	}
   
			
	/*... concordance code ends here ...*/
	

	printMap(hashTable);
	timer = clock() - timer;
	printf("\nconcordance ran in %f seconds\n", (float)timer / (float)CLOCKS_PER_SEC);
	printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
    printf("Table count = %d\n", size(hashTable));
	printf("Table capacity = %d\n", capacity(hashTable));
	printf("Table load = %f\n", tableLoad(hashTable));
	
	printf("Deleting keys\n");
	
	removeKey(hashTable, "and");
	removeKey(hashTable, "me");
	removeKey(hashTable, "the");
	printMap(hashTable);


		
	deleteMap(hashTable);
	printf("\nDeleted the table\n");   
	return 0;
}
示例#23
0
int main(int argc, char** argv) {
  double start, stop;
  double stop_read;
  double stop_reduce;
  int numprocs, rank;
  MPI_Init(&argc, &argv);
  start = MPI_Wtime();
  MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  //printf("got to start\n");
  DIR* dp;
  dp = opendir(READ_DIR_PATH);
  struct dirent* ep;
  char* filepath;
  /* Build stack for splitting up files across threads in OpenMP */
  FilenameStack* stack = newStack();
  int i = 0;
  if (dp != NULL) {
    while (ep = readdir(dp)) {
      // equally divide files among processes.
      if ((i % numprocs) - rank == 0) {
	filepath = (char*) malloc(1 + strlen(ep->d_name) + strlen(READ_DIR_PATH));
	strcpy(filepath, READ_DIR_PATH);
	strcat(filepath, ep->d_name);
	push(stack, filepath);
      }
      i++;
    }
  } else {
    printf("Couldn't open input directory\n");
    return 0;
  }
  closedir(dp);
  //printf("got past dividing work\n");
  HashMap* map = newMap(2000, &stringHasher, &stringComparator, &stringCopy);

  char* filename;
  filename = pop(stack);
  while(filename != NULL) {
    // most of the time spent should be here, so collisions should in theory
    // not cause a large performance impact.
    readFile(filename, 0, map);
    free(filename);
    filename = pop(stack);
  }
  //printf("got past reading\n");
  stop_read = MPI_Wtime();
  mpiMapReduce(map, rank, numprocs);
  stop_reduce = MPI_Wtime();

  // We could possibly parallelize this transformation and sort.
  if (rank == 0) {
    MapElement* elements = map2Array(map);
    sortArray(elements, map->nElements);
    //printf("Top 10 words:\n");
    //for(i = 0; i < 10; i++) {
    //printf("%d\t%s\t%d\n", i, (char*)elements[i].k, elements[i].v);
    //}
  
    deleteMapArray(elements, map->nElements);
    //printf("There are %d unique words.\n", maps[0]->nElements);
    deleteMap(map);
    stop = MPI_Wtime();
    printf("%.5e\n", stop_read - start);
    printf("%.5e\n", stop_reduce - stop_read);
    printf("%.5e\n", stop - start);
  } else {
    deleteMap(map);
  }
  
  MPI_Finalize();
  /** End mpi Parallel region **/
  return 0;
}
示例#24
0
int main (int argc, const char * argv[]) {
    const char* filename;
    struct hashMap *hashTable;
    int tableSize = 10;
    clock_t timer;
    FILE *fileptr;
    /*
     Optional command line argument usage for filename
    if(argc == 2)
    //    filename = argv[1];
    //else*/
    filename = "input2.txt"; /*specify your input text file here*/

    printf("opening file: %s\n", filename);

    timer = clock(); /*Used to calculate efficiency*/
    hashTable = createMap(tableSize);	   /*Create a new hashMap*/
    fileptr = fopen(filename, "r");/*Open the file*/
    assert(fileptr != NULL);/*Check that the file opened properly*/
    int * value;/*Used to receive the value at the key*/


    for (char* word = getWord(fileptr); word != NULL; word = getWord(fileptr)) /*While the file hasn't reached the end*/
    {
        if (containsKey(hashTable, word) == 1) {
            /*If the key is already in the hash table, get the current value at that key and increment it by 1.
            Then reinsert that key with the new value*/
            value = atMap(hashTable, word);
            *value+=1;
            insertMap(hashTable, word, *value);
        }

        else
            insertMap(hashTable, word, 1); /*else insert the key with a value of 1*/
    }


    fclose(fileptr);/*close the file*/

    printMap(hashTable);/*Print the keys and values in the hashMap*/


    timer = clock() - timer;
    /*Print statements for testing purposes*/
    printf("\nconcordance ran in %f seconds\n", (float)timer / (float)CLOCKS_PER_SEC);
    printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
    printf("Table count = %d\n", size(hashTable));
    printf("Table capacity = %d\n", capacity(hashTable));
    printf("Table load = %f\n", tableLoad(hashTable));


    /*Test the removeKey function*/
    printf("Deleting keys\n");
    removeKey(hashTable, "and");
    removeKey(hashTable, "me");
    removeKey(hashTable, "the");

    printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
    printf("Table count = %d\n", size(hashTable));
    printf("Table capacity = %d\n", capacity(hashTable));
    printf("Table load = %f\n", tableLoad(hashTable));
    printMap(hashTable);

    /*Delete the hashMap*/
    deleteMap(hashTable);
    printf("\nDeleted the table\n");
    return 0;
}
示例#25
0
int main (int argc, const char * argv[]) {
	const char* filename;
	struct hashMap *hashTable;	
	int tableSize = 1000;
	clock_t timer;
	FILE *fileptr;	
 	   /*
     this part is using command line arguments, you can use them if you wish
     but it is not required. DO NOT remove this code though, we will use it for
     testing your program.
     
     if you wish not to use command line arguments manually type in your
     filename and path in the else case.
     */
    if(argc == 2)
        filename = argv[1];
    else
        filename = "input1.txt"; /*specify your input text file here*/
    
    printf("opening file: %s\n", filename);
    
	timer = clock();
	
	/*... concordance code goes here ...*/

       	hashTable = createMap(tableSize); 
       
	fileptr = fopen(filename, "r");
//	char *character = "";

	 
//	ValueType* val; 
//	val = atMap(hashTable, character); 
/*
 * I couldnt figure out how to properly set up the concordance*/
		
		insertMap(hashTable, getWord(fileptr), 0); 
		insertMap(hashTable, getWord(fileptr), 0);
		insertMap(hashTable, getWord(fileptr), 0); 
		insertMap(hashTable, getWord(fileptr), 0); 

	
	fclose(fileptr);   		
	/*... concordance code ends here ...*/

	printMap(hashTable);
	timer = clock() - timer;
	printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
   	printf("Table count = %d\n", size(hashTable));


printf("Table load = %f\n", tableLoad(hashTable));
	
	printf("Deleting keys\n");
	
	removeKey(hashTable, "and");
	removeKey(hashTable, "me");
	removeKey(hashTable, "the");
	printMap(hashTable);
		
	deleteMap(hashTable);
	printf("\nDeleted the table\n");   
	return 0;
}
示例#26
0
int main (int argc, const char * argv[]) {
	char *fn; /* File name */
	struct hashMap *hashTable, *hashTable2;
	FILE *filePtr;

	fn = "text1.txt";/* the file name and path */
	printf("Opening file: %s \n", fn);
	filePtr = fopen(fn, "r");
	hashTable = createMap(40, 1);
  char *word;
  while((word = getWord(filePtr)) != '\0') {
      insertMap(hashTable, word, 1);
  }

  printf("--------------- Testing contains --------------- \n");

  assertTrue(containsKey(hashTable, "it") == 1, "Search for 'it'");
  assertTrue(containsKey(hashTable, "comparison") == 1, "Search for 'comparison'");
  assertTrue(containsKey(hashTable, "period") == 1, "Search for 'period'");
  assertTrue(containsKey(hashTable, "despair") == 1, "Search for 'despair'");
    assertTrue(containsKey(hashTable, "deriop") == 0, "Search for 'deriop'");
    assertTrue(containsKey(hashTable, "yuck") == 0, "Search for 'yuck'");

    printf("--------------- Testing table stats --------------- \n");

    assertTrue(hashTable->tableSize == 40, "Test table size");
    assertTrue(fullBuckets(hashTable) == 30, "Test full buckets");
    assertTrue(emptyBuckets(hashTable) == 10, "Test empty buckets");
    assertTrue(linkCount(hashTable) == 59, "Test link count");

    printf("--------------- Testing remove --------------- \n");

    removeKey(hashTable, "yuck"); /* Should print some type of 'not found' message */
    removeKey(hashTable, "despair");
    assertTrue(containsKey(hashTable, "despair") == 0, "Search for 'despair'");

    printf("--------------- Printing hash table --------------- \n");

    printMap(hashTable);

    deleteMap(hashTable);

    printf("--------------- New table - same text file - new hash --------------- \n");

    fn = "text1.txt";/* the file name and path */
		printf("Opening file: %s \n", fn);
		filePtr = fopen(fn, "r");
		hashTable2 = createMap(40, 2);

    while((word = getWord(filePtr)) != '\0') {
        insertMap(hashTable2, word, 1);
    }

    printf("--------------- Testing table stats 2 --------------- \n");

    assertTrue(hashTable2->tableSize == 80, "Test table size");
    assertTrue(fullBuckets(hashTable2) == 38, "Test full buckets");
    assertTrue(emptyBuckets(hashTable2) == 42, "Test empty buckets");
    assertTrue(linkCount(hashTable2) == 59, "Test link count");

    printf("Closing file: %s \n", fn);
		fclose(filePtr);

	/* Concordance testing	*/




	struct hashMap * concord;

  fn = "text2.txt";
	printf("Opening file: %s \n", fn);
	filePtr = fopen(fn, "r");
	concord = createMap(10, 2);


    while((word = getWord(filePtr)) != '\0') {
        concordance(concord, word);
    }

    printf("--------------- Concordance table stats --------------- \n");

    printf("table size: %d \n", concord->tableSize);
    printf("full buckets: %d \n", fullBuckets(concord));
    printf("empty buckets: %d \n", emptyBuckets(concord));
    printf("link count: %d \n", linkCount(concord));



    /*Test further on your own */

	return 0;
}
示例#27
0
int main (int argc, const char * argv[]) {
	const char* filename;
	struct hashMap *hashTable;	
	int tableSize = 97;
	clock_t timer;
	FILE *fileptr;	
    /*
     this part is using command line arguments, you can use them if you wish
     but it is not required. DO NOT remove this code though, we will use it for
     testing your program.
     
     if you wish not to use command line arguments manually type in your
     filename and path in the else case.
     */
    if(argc == 2)
        filename = argv[1];
    else
        filename = "input2.txt"; /*specify your input text file here*/
    
    printf("opening file: %s\n", filename);
    
	timer = clock();
	
	hashTable = createMap(tableSize);	   
	
    /*... concordance code goes here ...*/

	fileptr = fopen(filename, "r");
	char* word = getWord(fileptr);

	do
	{
		//if the word is in the hashTable, increment the val
		//otherwise, create the entry with value set to 1
		if (containsKey(hashTable, word))
		{
			//atMap is useless?
			int *val = atMap(hashTable, word);
			*val += 1;
			int i = 0;
		}
		else
		{
			int val = 1;
			insertMap(hashTable, word, val);
		}

		word = getWord(fileptr);
	} while (word != NULL);

	fclose(fileptr);

	/*... concordance code ends here ...*/

	printMap(hashTable);
	timer = clock() - timer;
	printf("\nconcordance ran in %f seconds\n", (float)timer / (float)CLOCKS_PER_SEC);
	printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
    printf("Table count = %d\n", size(hashTable));
	printf("Table capacity = %d\n", capacity(hashTable));
	printf("Table load = %f\n", tableLoad(hashTable));
	
	printf("Deleting keys\n");
	
	removeKey(hashTable, "and");
	removeKey(hashTable, "me");
	removeKey(hashTable, "the");
	printMap(hashTable);
		
	deleteMap(hashTable);
	printf("\nDeleted the table\n");   
	return 0;
}
示例#28
0
Map::~Map()
{
  deleteMap();
}
示例#29
0
int main(int argc, const char * argv[]) {
	const char* filename;
	struct hashMap *hashTable;
	int tableSize = 63;
	clock_t timer;
	FILE *fileptr;
	/*
	this part is using command line arguments, you can use them if you wish
	but it is not required. DO NOT remove this code though, we will use it for
	testing your program.

	if you wish not to use command line arguments manually type in your
	filename and path in the else case.
	*/
	if (argc == 2)
		filename = argv[1];
	else
		filename = "input1.txt"; /*specify your input text file here*/

	printf("opening file: %s\n", filename);

	timer = clock();

	hashTable = createMap(tableSize);

	/*... concordance code goes here ...*/
	fileptr = fopen(filename, "r"); //open the given file

	if (fileptr != NULL) //if the file was opened sucessfully...
	{
		/* while the end of the file has not yet been reached, get the next word in the file, 
		 * adding it to the hash table or updating the number of times it has appeared in the document.
		 * the alogrithm is case sensitive
		 */
		while (!feof(fileptr)) 
		{
			char* word = getWord(fileptr);

			if (word != NULL)
			{
				int* wordCount = atMap(hashTable, word);

				if (wordCount == NULL)
				{
					insertMap(hashTable, word, 1);
				}
				else
				{
					insertMap(hashTable, word, (*wordCount) + 1);
				}
			}
		}
	}
	else
	{
		fprintf(stderr, "Could not open file."); //print an error message if the file could not be opened
	}

	fclose(fileptr); //close the file

	//print each word in the document along with the number of times it has appeared. 
	for (int i = 0; i < hashTable->tableSize; i++)
	{
		hashLink* curLink = hashTable->table[i];

		while (curLink != NULL)
		{
			printf("%s: %d\n", curLink->key, curLink->value);

			curLink = curLink->next;
		}
	}
	/*... concordance code ends here ...*/

	printMap(hashTable);
	timer = clock() - timer;
	printf("\nconcordance ran in %f seconds\n", (float)timer / (float)CLOCKS_PER_SEC);
	printf("Table emptyBuckets = %d\n", emptyBuckets(hashTable));
	printf("Table count = %d\n", size(hashTable));
	printf("Table capacity = %d\n", capacity(hashTable));
	printf("Table load = %f\n", tableLoad(hashTable));

	printf("Deleting keys\n");

	removeKey(hashTable, "and");
	removeKey(hashTable, "me");
	removeKey(hashTable, "the");
	printMap(hashTable);

	deleteMap(hashTable);
	printf("\nDeleted the table\n");
	return 0;
}
示例#30
0
int main(int argc, char** argv) {
  HashMap* map = newMap(20, &stringHasher, &stringComparator, &stringCopy);
  char* str1 = "the";
  Key testKeyPtr = (Key)str1;
  incrementKeyValue(map, testKeyPtr);
  incrementKeyValue(map, testKeyPtr);
  incrementKeyValue(map, testKeyPtr);
  char* str2 = "blue";
  Key testKeyPtr2 = (Key)str2;
  incrementKeyValue(map, testKeyPtr2);
  incrementKeyValue(map, testKeyPtr2);
  incrementKeyValue(map, testKeyPtr2);
  printf("key = %d\n", get(map, testKeyPtr));
  printf("key2 = %d\n", get(map, testKeyPtr2));

  char* str3 = "a";
  Key testKeyPtr3 = (Key) str3;
  incrementKeyValue(map, testKeyPtr3);
  incrementKeyValue(map, testKeyPtr3);
  incrementKeyValue(map, testKeyPtr3);
  incrementKeyValue(map, testKeyPtr3);
  printf("key3 = \%d\n", get(map, testKeyPtr3));

  HashMap* map2 = newMap(20, &stringHasher, &stringComparator, &stringCopy);
  char* str4 = "blue";
  Key testKeyPtr4 = (Key) str4;
  incrementKeyValue(map2, testKeyPtr4);
  incrementKeyValue(map2, testKeyPtr4);

  char* str5 = "at";
  Key testKeyPtr5 = (Key) str5;
  incrementKeyValue(map2, testKeyPtr5);
  incrementKeyValue(map2, testKeyPtr5);
  printf("key4 = %d\n", get(map2, testKeyPtr4));
  printf("key5 = %d\n", get(map2, testKeyPtr5));

  char* str6 = "my";
  Key testKeyPtr6 = (Key) str6;
  incrementKeyValue(map2, testKeyPtr6);
  incrementKeyValue(map2, testKeyPtr6);
  incrementKeyValue(map2, testKeyPtr6);
  incrementKeyValue(map2, testKeyPtr6);
  printf("key6 = %d\n", get(map2, testKeyPtr6));

  printf("number of bytes in map1:%d\n", map->nBytes);
  char* data;
  uint32_t nBytes;
  data = serializeMap(map, &nBytes);
  printf("number of bytes in map2:%d\n", map2->nBytes);
  int i = 0;
  printf("printing raw bytes\n");
  for(i = 0;  i < nBytes + 4; i++) {
    printf("%c ", data[i]);
  }
  printf("\n");
  addSerializedToMap(map2, data);
  printf("number of bytes in reduced map2:%d\n", map2->nBytes);
  printf("key = %d\n", get(map2, testKeyPtr));
  printf("key2 = %d\n", get(map2, testKeyPtr2));
  printf("key3 = %d\n", get(map2, testKeyPtr3));
  printf("key4 = %d\n", get(map2, testKeyPtr4));
  printf("key5 = %d\n", get(map2, testKeyPtr5));
  printf("key6 = %d\n", get(map2, testKeyPtr6));
  deleteMap(map);
  deleteMap(map2);
}