当前位置: 首页>>代码示例>>C++>>正文


C++ HashTable类代码示例

本文整理汇总了C++中HashTable的典型用法代码示例。如果您正苦于以下问题:C++ HashTable类的具体用法?C++ HashTable怎么用?C++ HashTable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了HashTable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: testGrow

void testGrow(){
  HashTable<std::string,int> testHash;
  testHash.add("0",0);
  unsigned long startingSize = testHash.backingArraySize;
  unsigned long i=0;
  while(testHash.backingArraySize == startingSize){
    i++;
    std::ostringstream ss;
    ss << i;
    testHash.add(ss.str(),i);
  }
  unsigned long endingSize = testHash.backingArraySize;
  if(i*2 > startingSize){
    std::cout << "ERROR: You didn't grown soon enough. Starting size was " << startingSize << ", didn't grow until " << i+1 << "adds done." << std::endl;
    return;
  } else {
    std::cout << "SUCCESS: Grow called at the right time. Starting size was " << startingSize << " and grow called on the " << i+1 << "th add call" << std::endl;
  }

  if(testHash.size() == i+1){
    std::cout << "SUCCESS: Size of hash table unchanged by the grow" << std::endl;
  } else {
    std::cout << "ERROR: Size of hash table should be " << i+1 << ", but got " << testHash.size() << std::endl;
    return;
  }

  if(testHash.numRemoved == 0){
    std::cout << "SUCCESS: After grow called, all removed items have been cleared out." << std::endl;
  } else {
    std::cout << "ERROR: When grow is called, you should clear out all the removed items." << std::endl;
    return;
  }

  for(int j=0; j<=i;j++){
    std::ostringstream ss;
    ss << j;
    if(!testHash.keyExists(ss.str())){
      std::cout << "ERROR: During grow the item with key '" << j << "' was lost" << std::endl;
      return;
    }
  }
  std::cout << "SUCCESS: After grow all items from the original table made it to the new one." << std::endl;
}
开发者ID:ChaceTurner,项目名称:05_Hashing_Lab,代码行数:43,代码来源:main.cpp

示例2: main

int main()
{
	ifstream fin;
	string word;
	HashTable Table;
	fin.open("jumbledwords.txt");
	fin >> word;
	while(!fin.fail()){
		Table.insert(word);
		fin >> word;
	}
	fin.close();
	for (int i = 0; i < Table.getSize(); i++) {
		if (Table.clusterLength(i) > 1) {
			cout << "index " << i << "  " << Table.clusterLength(i) << endl;
		}
	}
	cout << Table.getSize();
	return 0;
}
开发者ID:ScottEdg,项目名称:COS-221,代码行数:20,代码来源:main.cpp

示例3: main

int main() {
	//create_stu();
	welcome();
	command_tips();
	cout << endl;
	srand(time(0));
	
	HashTable<Student> h;
	HashTable2<Student> table;
	
	//read_stu(h, table);
	
	string command;
	while(cin >> command) {
		if (command[0] == '$') {
			if (command[1] == 'Q') break;
			switch(command[1]) {
			case 'I':
				{
					cout << "Please input a student's information (ID, name, age, gender):" << endl;
					string id, name;
					int age;
					bool sex;
					cin >> id >> name >> age >> sex;
					Student student(id, name, age, sex);
					if (h.insert(student)) {
						cout << "\nInserted successfully: " << endl;  //print the information that is removed
						cout << "Name: " << student.getName() << endl;
						cout << "ID: " << student.getID() << endl;
						cout << "Age: " << student.getAge() << endl;
						cout << "Gender: " << (student.getSex() == 0? "Male":"Female") << endl <<  endl;
					} else {
						cout << "\nInserted failed: The system already contains the student" << endl;
					}

				}
				break;
			case 'R': 
				{
					cout << "Please input the student's ID:" << endl;
					string s2;
					cin >> s2;
					h.remove(s2);
					cout << endl;
				}
				break;
			case 'F':
				{
					cout << "Please input the student's ID:" << endl;
					string s2;
					cin >> s2;
					h.findKey(s2);
					cout << endl;
				}
				break;
			case 'T':
				{
					cout << "Please wait for inputing the information from the file." << endl;
					read_stu(h, table);
					cout << "Input finished" << endl;
					cout << "Tatal numbers of student: " << totalNumber << endl;
					vector<list<Student> > ve = h.getList();
					double ave_CHI = 0, ave_OPEN = 0;
					int num = 30;
					for (int i = 0; i < num; i++) {
						list<Student>::iterator p = ve[rand() % ve.size()].end();
						string s1 = (*(--p)).getID();
						double CHAIN, OPEN;
						ave_CHI += (double)h.cal_time(s1) ;
						ave_OPEN += (double)table.cal_time(s1);
						cout << "chaning: " << setw(8) << (double)h.cal_time(s1) << " s" << "   open addressing: " << setw(8) << (double)table.cal_time(s1) << " s" << endl;
						Sleep(100);
					}
					cout << "Average time with chaining: " << (double)(ave_CHI / num) << " s"<< endl;
					cout << "Average time with open addressing: " << (double)(ave_OPEN / num) << " s" << endl;
					
					
					cout << endl;
				} break;
			default:
				{
					cout << "Command error! Please enter a right command!" << endl;
					command_tips();
				} break;
			}
		} else {
			cout << "Command error! Please enter a right command!" << endl;
			command_tips();
		}
	}
开发者ID:stella1006,项目名称:DataStructorHW-Lab,代码行数:90,代码来源:源.cpp

示例4: s1

void HashTableTest::testInsert()
{
	std::string s1("str1");
	std::string s2("str2");
	HashTable<std::string, int> hashTable;
	assert (!hashTable.exists(s1));
	hashTable.insert(s1, 13);
	assert (hashTable.exists(s1));
	assert (hashTable.get(s1) == 13);
	int retVal = 0;

	assert (hashTable.get(s1, retVal));
	assert (retVal == 13);
	try
	{
		hashTable.insert(s1, 22);
		failmsg ("duplicate insert must fail");
	}
	catch (Exception&){}
	try
	{
		hashTable.get(s2);
		failmsg ("getting a non inserted item must fail");
	}
	catch (Exception&){}

	assert (!hashTable.exists(s2));
	hashTable.insert(s2, 13);
	assert (hashTable.exists(s2));
}
开发者ID:1514louluo,项目名称:poco,代码行数:30,代码来源:HashTableTest.cpp

示例5: Returns

int Returns(xStationType statName,  LicenseType license, int mile, HashTable<LicenseType, BikePtr>&ht, Graph &stationMap) {
    
    BikePtr* bikeMetaPtr = ht.get(license);
    if( bikeMetaPtr ) {
        BikePtr bike = *bikeMetaPtr;
        //bike->Status=Free;

         vector<int> prev = stationMap.dijkstra(bike->Station);
         forward_list<int> shortest_path = stationMap.getPath(prev, statName);
         int dist=0;
         if( ! shortest_path.empty() ) {

             for(forward_list<int>::iterator it = shortest_path.begin(); it != shortest_path.end();) {
                 int from_tmp = *it;

                 forward_list<int>::iterator it_next = it;
                 it_next++;
                 if( it_next != shortest_path.end() ) {
                    int to_tmp = *(it_next);
                    dist += stationMap.distance(from_tmp, to_tmp);
                 }
                 it = it_next;
            }
         }

        int charge=0;
        int tmp=mile-bike->Mileage;

        if(tmp>dist){
            switch(bike->Class){
                case 0:
                    charge=tmp*40;
                    break;
                case 1:
                    charge=tmp*30;
                    break;
                case 2:
                    charge=tmp*20;
                    break;
                case 3:
                    charge=tmp*25;
                    break;
            }
        }
        else{
            switch(bike->Class){
                case 0:
                    charge=tmp*30;
                    break;
                case 1:
                    charge=tmp*25;
                    break;
                case 2:
                    charge=tmp*15;
                    break;
                case 3:
                    charge=tmp*20;
                    break;
            }
        }


        bike->Mileage=mile;
        int index = Station[bike->Station].HRent.find(bike, &licenseComp);
        Station[bike->Station].HRent.remove(index);
        Station[bike->Station].Nets[bike->Class] += charge;
        
        bike->Status = Free;
        Station[bike->Station].add(bike);
        
        cout<<"Rental charge for this bike is "<<charge<<"."<<endl;
    }
    return 0;
}
开发者ID:kaloni,项目名称:DataStructFinal,代码行数:74,代码来源:main.cpp

示例6: insertOnePoint

void insertOnePoint(HashTable<Point, std::string>& htbl, const Point& p)
{
   std::stringstream stream;
   stream << "Point " << ": " << "(" << p.getX() << ";" << p.getY() << ")";
   htbl.insert(p, stream.str());
}
开发者ID:dendibakh,项目名称:Algorithm-Tasks,代码行数:6,代码来源:main.cpp

示例7: oldToNew

// Read boundary file without reading mesh
void rewriteBoundary
(
    const bool isTestRun,
    const IOobject& io,
    const fileName& regionPrefix,
    HashTable<word>& thisNames,
    HashTable<word>& nbrNames
)
{
    Info<< "Reading boundary from " << typeFilePath<IOPtrList<entry>>(io)
        << endl;

    // Read PtrList of dictionary.
    const word oldTypeName = IOPtrList<entry>::typeName;
    const_cast<word&>(IOPtrList<entry>::typeName) = word::null;
    IOPtrList<entry> patches(io);
    const_cast<word&>(IOPtrList<entry>::typeName) = oldTypeName;
    // Fake type back to what was in field
    const_cast<word&>(patches.type()) = patches.headerClassName();


    // Replace any 'cyclic'
    label nOldCyclics = 0;
    forAll(patches, patchi)
    {
        const dictionary& patchDict = patches[patchi].dict();

        if (word(patchDict["type"]) == cyclicPolyPatch::typeName)
        {
            if (!patchDict.found("neighbourPatch"))
            {
                Info<< "Patch " << patches[patchi].keyword()
                    << " does not have 'neighbourPatch' entry; assuming it"
                    << " is of the old type." << endl;
                nOldCyclics++;
            }
        }
    }

    Info<< "Detected " << nOldCyclics << " old cyclics." << nl << endl;


    // Save old patches.
    PtrList<entry> oldPatches(patches);

    // Extend
    label nOldPatches = patches.size();
    patches.setSize(nOldPatches+nOldCyclics);

    // Create reordering map
    labelList oldToNew(patches.size());


    // Add new entries
    label addedPatchi = nOldPatches;
    label newPatchi = 0;
    forAll(oldPatches, patchi)
    {
        const dictionary& patchDict = oldPatches[patchi].dict();

        if
        (
            word(patchDict["type"]) == cyclicPolyPatch::typeName
        )
        {
            const word& name = oldPatches[patchi].keyword();

            if (patchDict.found("neighbourPatch"))
            {
                patches.set(patchi, oldPatches.set(patchi, nullptr));
                oldToNew[patchi] = newPatchi++;

                // Check if patches come from automatic conversion
                word oldName;

                string::size_type i = name.rfind("_half0");
                if (i != string::npos)
                {
                    oldName = name.substr(0, i);
                    thisNames.insert(oldName, name);
                    Info<< "Detected converted cyclic patch " << name
                        << " ; assuming it originates from " << oldName
                        << endl;
                }
                else
                {
                    i = name.rfind("_half1");
                    if (i != string::npos)
                    {
                        oldName = name.substr(0, i);
                        nbrNames.insert(oldName, name);
                        Info<< "Detected converted cyclic patch " << name
                            << " ; assuming it originates from " << oldName
                            << endl;
                    }
                }
            }
            else
            {
//.........这里部分代码省略.........
开发者ID:OpenFOAM,项目名称:OpenFOAM-dev,代码行数:101,代码来源:foamUpgradeCyclics.C

示例8: env

Boolean MediaSubsession::initiate(int useSpecialRTPoffset) {
  if (fReadSource != NULL) return True; // has already been initiated

  do {
    if (fCodecName == NULL) {
      env().setResultMsg("Codec is unspecified");
      break;
    }

    // Create RTP and RTCP 'Groupsocks' on which to receive incoming data.
    // (Groupsocks will work even for unicast addresses)
    struct in_addr tempAddr;
    tempAddr.s_addr = connectionEndpointAddress();
        // This could get changed later, as a result of a RTSP "SETUP"

    if (fClientPortNum != 0) {
      // The sockets' port numbers were specified for us.  Use these:
      Boolean const protocolIsRTP = strcmp(fProtocolName, "RTP") == 0;
      if (protocolIsRTP) {
	fClientPortNum = fClientPortNum&~1; // use an even-numbered port for RTP, and the next (odd-numbered) port for RTCP
      }
      if (isSSM()) {
	fRTPSocket = new Groupsock(env(), tempAddr, fSourceFilterAddr, fClientPortNum);
      } else {
	fRTPSocket = new Groupsock(env(), tempAddr, fClientPortNum, 255);
      }
      if (fRTPSocket == NULL) {
	env().setResultMsg("Failed to create RTP socket");
	break;
      }
      
      if (protocolIsRTP) {
	// Set our RTCP port to be the RTP port +1
	portNumBits const rtcpPortNum = fClientPortNum|1;
	if (isSSM()) {
	  fRTCPSocket = new Groupsock(env(), tempAddr, fSourceFilterAddr, rtcpPortNum);
	} else {
	  fRTCPSocket = new Groupsock(env(), tempAddr, rtcpPortNum, 255);
	}
      }
    } else {
      // Port numbers were not specified in advance, so we use ephemeral port numbers.
      // Create sockets until we get a port-number pair (even: RTP; even+1: RTCP).
      // We need to make sure that we don't keep trying to use the same bad port numbers over and over again.
      // so we store bad sockets in a table, and delete them all when we're done.
      HashTable* socketHashTable = HashTable::create(ONE_WORD_HASH_KEYS);
      if (socketHashTable == NULL) break;
      Boolean success = False;
      NoReuse dummy(env()); // ensures that our new ephemeral port number won't be one that's already in use

      while (1) {
	// Create a new socket:
	if (isSSM()) {
	  fRTPSocket = new Groupsock(env(), tempAddr, fSourceFilterAddr, 0);
	} else {
	  fRTPSocket = new Groupsock(env(), tempAddr, 0, 255);
	}
	if (fRTPSocket == NULL) {
	  env().setResultMsg("MediaSession::initiate(): unable to create RTP and RTCP sockets");
	  break;
	}

	// Get the client port number, and check whether it's even (for RTP):
	Port clientPort(0);
	if (!getSourcePort(env(), fRTPSocket->socketNum(), clientPort)) {
	  break;
	}
	fClientPortNum = ntohs(clientPort.num()); 
	if ((fClientPortNum&1) != 0) { // it's odd
	  // Record this socket in our table, and keep trying:
	  unsigned key = (unsigned)fClientPortNum;
	  Groupsock* existing = (Groupsock*)socketHashTable->Add((char const*)key, fRTPSocket);
	  delete existing; // in case it wasn't NULL
	  continue;
	}

	// Make sure we can use the next (i.e., odd) port number, for RTCP:
	portNumBits rtcpPortNum = fClientPortNum|1;
	if (isSSM()) {
	  fRTCPSocket = new Groupsock(env(), tempAddr, fSourceFilterAddr, rtcpPortNum);
	} else {
	  fRTCPSocket = new Groupsock(env(), tempAddr, rtcpPortNum, 255);
	}
	if (fRTCPSocket != NULL && fRTCPSocket->socketNum() >= 0) {
	  // Success! Use these two sockets.
	  success = True;
	  break;
	} else {
	  // We couldn't create the RTCP socket (perhaps that port number's already in use elsewhere?).
	  delete fRTCPSocket;

	  // Record the first socket in our table, and keep trying:
	  unsigned key = (unsigned)fClientPortNum;
	  Groupsock* existing = (Groupsock*)socketHashTable->Add((char const*)key, fRTPSocket);
	  delete existing; // in case it wasn't NULL
	  continue;
	}
      }

      // Clean up the socket hash table (and contents):
//.........这里部分代码省略.........
开发者ID:hatboyzero,项目名称:live456,代码行数:101,代码来源:MediaSession.cpp

示例9: set

void EQName::set(const QName& q, const HashTable& dict)
{
    prefix = dict.getKey(q.getPrefix());
    uri = dict.getKey(q.getUri());
    local = dict.getKey(q.getLocal());
}
开发者ID:alepharchives,项目名称:Sablotron,代码行数:6,代码来源:datastr.cpp

示例10: getSimilarity

// . returns 0.0 to 1.0
// . what percent of the alnum words in "w1" are in "w2" from words in [t0,t1)
// . gets 50% points if has all single words, and the other 50% if all phrases
// . Scores class applies to w1 only, use NULL if none
// . use word popularity information for scoring rarer term matches more
// . ONLY CHECKS FIRST 1000 WORDS of w2 for speed
float Title::getSimilarity ( Words  *w1 , int32_t i0 , int32_t i1 ,
			     Words  *w2 , int32_t t0 , int32_t t1 ) {
	// if either empty, that's 0% contained
	if ( w1->getNumWords() <= 0 ) return 0;
	if ( w2->getNumWords() <= 0 ) return 0;
	if ( i0 >= i1 ) return 0;
	if ( t0 >= t1 ) return 0;

	// invalids vals
	if ( i0 < 0   ) return 0;
	if ( t0 < 0   ) return 0;

	// . for this to be useful we must use idf
	// . get the popularity of each word in w1
	// . w1 should only be a few words since it is a title candidate
	// . does not add pop for word #i if scores[i] <= 0
	// . take this out for now since i removed the unified dict,
	//   we could use this if we added popularity to g_wiktionary
	//   but it would have to be language dependent
	Pops pops1;
	Pops pops2;
	if ( ! pops1.set ( w1 , i0 , i1 ) ) return -1.0;
	if ( ! pops2.set ( w2 , t0 , t1 ) ) return -1.0;

	// now hash the words in w1, the needle in the haystack
	int32_t nw1 = w1->getNumWords();
	if ( i1 > nw1 ) i1 = nw1;
	HashTable table;

	// this augments the hash table
	int64_t lastWid   = -1;
	float     lastScore = 0.0;

	// but we cannot have more than 1024 slots then
	if ( ! table.set ( 1024 ) ) return -1.0;

	// and table auto grows when 90% full, so limit us here
	int32_t count    = 0;
	int32_t maxCount = 20;

	// sum up everything we add
	float sum = 0.0;

	// loop over all words in "w1" and hash them
	for ( int32_t i = i0 ; i < i1 ; i++ ) {
		// the word id
		int64_t wid = w1->getWordId(i);

		// skip if not indexable
		if ( wid == 0 ) {
			continue;
		}

		// no room left in table!
		if ( count++ > maxCount ) {
			//logf(LOG_DEBUG, "query: Hash table for title "
			//    "generation too small. Truncating words from w1.");
			break;
		}

		// . make this a float. it ranges from 0.0 to 1.0
		// . 1.0 means the word occurs in 100% of documents sampled
		// . 0.0 means it occurs in none of them
		// . but "val" is the complement of those two statements!
		float score = 1.0 - pops1.getNormalizedPop(i);

		// accumulate
		sum += score;

		// add to table
		if ( ! table.addKey ( (int32_t)wid , (int32_t)score , NULL ) ) {
			return -1.0;
		}

		// if no last wid, continue
		if ( lastWid == -1LL ) {
			lastWid = wid;
			lastScore = score;
			continue;
		}

		// . what was his val?
		// . the "val" of the phrase: 
		float phrScore = score + lastScore;

		// do not count as much as single words
		phrScore *= 0.5;

		// accumulate
		sum += phrScore;

		// get the phrase id
		int64_t pid = hash64 ( wid , lastWid );

//.........这里部分代码省略.........
开发者ID:lemire,项目名称:open-source-search-engine,代码行数:101,代码来源:Title.cpp

示例11: env

Boolean MediaSubsession::initiate(int useSpecialRTPoffset) {
  if (fReadSource != NULL) return True; // has already been initiated

  do {
    if (fCodecName == NULL) {
      env().setResultMsg("Codec is unspecified");
      break;
    }

    // Create RTP and RTCP 'Groupsocks' on which to receive incoming data.
    // (Groupsocks will work even for unicast addresses)
    struct in_addr tempAddr;
    tempAddr.s_addr = connectionEndpointAddress();
        // This could get changed later, as a result of a RTSP "SETUP"

    if (fClientPortNum != 0) {
      // The sockets' port numbers were specified for us.  Use these:
      fClientPortNum = fClientPortNum&~1; // even
      if (isSSM()) {
	fRTPSocket = new Groupsock(env(), tempAddr, fSourceFilterAddr, fClientPortNum);
      } else {
	fRTPSocket = new Groupsock(env(), tempAddr, fClientPortNum, 255);
      }
      if (fRTPSocket == NULL) {
	env().setResultMsg("Failed to create RTP socket");
	break;
      }
      
      // Set our RTCP port to be the RTP port +1
      portNumBits const rtcpPortNum = fClientPortNum|1;
      if (isSSM()) {
	fRTCPSocket = new Groupsock(env(), tempAddr, fSourceFilterAddr, rtcpPortNum);
      } else {
	fRTCPSocket = new Groupsock(env(), tempAddr, rtcpPortNum, 255);
      }
      if (fRTCPSocket == NULL) {
	char tmpBuf[100];
	sprintf(tmpBuf, "Failed to create RTCP socket (port %d)", rtcpPortNum);
	env().setResultMsg(tmpBuf);
	break;
      }
    } else {
      // Port numbers were not specified in advance, so we use ephemeral port numbers.
      // Create sockets until we get a port-number pair (even: RTP; even+1: RTCP).
      // We need to make sure that we don't keep trying to use the same bad port numbers over and over again.
      // so we store bad sockets in a table, and delete them all when we're done.
      HashTable* socketHashTable = HashTable::create(ONE_WORD_HASH_KEYS);
      if (socketHashTable == NULL) break;
      Boolean success = False;

      while (1) {
	// Create a new socket:
	if (isSSM()) {
	  fRTPSocket = new Groupsock(env(), tempAddr, fSourceFilterAddr, 0);
	} else {
	  fRTPSocket = new Groupsock(env(), tempAddr, 0, 255);
	}
	if (fRTPSocket == NULL) {
	  env().setResultMsg("MediaSession::initiate(): unable to create RTP and RTCP sockets");
	  break;
	}

	// Get the client port number, and check whether it's even (for RTP):
	Port clientPort(0);
	if (!getSourcePort(env(), fRTPSocket->socketNum(), clientPort)) {
	  break;
	}
	fClientPortNum = ntohs(clientPort.num()); 
	if ((fClientPortNum&1) != 0) { // it's odd
	  // Record this socket in our table, and keep trying:
	  unsigned key = (unsigned)fClientPortNum;
	  socketHashTable->Add((char const*)key, fRTPSocket);
	  continue;
	}

	// Make sure we can use the next (i.e., odd) port number, for RTCP:
	portNumBits rtcpPortNum = fClientPortNum|1;
	if (isSSM()) {
	  fRTCPSocket = new Groupsock(env(), tempAddr, fSourceFilterAddr, rtcpPortNum);
	} else {
	  fRTCPSocket = new Groupsock(env(), tempAddr, rtcpPortNum, 255);
	}
	if (fRTCPSocket != NULL) {
	  // Success! Use these two sockets (and delete any others that we've created):
	  Groupsock* oldGS;
	  while ((oldGS = (Groupsock*)socketHashTable->RemoveNext()) != NULL) {
	    delete oldGS;
	  }
	  delete socketHashTable;
	  success = True;
	  break;
	} else {
	  // We couldn't create the RTCP socket (perhaps that port number's already in use elsewhere?).
	  // Record the first socket in our table, and keep trying:
	  unsigned key = (unsigned)fClientPortNum;
	  socketHashTable->Add((char const*)key, fRTPSocket);
	  continue;
	}
      }
      if (!success) break; // a fatal error occurred trying to create the RTP and RTCP sockets; we can't continue
//.........这里部分代码省略.........
开发者ID:dalinhuang,项目名称:ffmpeg-port,代码行数:101,代码来源:MediaSession.cpp

示例12: mainFuntions

int mainFuntions(int hashFunc)
{
    HashTable h;
    h.hashInit();
    //h.insertOrderName("", -1);
    //h.insertOrderYear("", -1);



    string inName, inYear, dName, fName;
    int yearInt;
    int select = menuSelect();
    hashElem *foundNode = NULL;
    while (select != 8)
    {
        switch(select)
        {
        case 1:
            // choose hash function
            cout << "Enter title:" << endl;
            getline(cin, inName);
            cout << "Enter year:" << endl;
            getline(cin, inYear);
            yearInt = atoi(inYear.c_str());

            h.insertMovie(inName, yearInt, hashFunc);
            h.insertOrderYear(inName, yearInt);
            h.insertOrderName(inName, yearInt);
            break;

        case 2:
            cout << "Enter title:" << endl;
            getline(cin, dName);
            h.deleteMovie(dName, hashFunc);
            break;
        case 3:
            cout << "Enter title:" << endl;
            getline(cin, fName);
            foundNode = h.findMovie(fName, hashFunc);
            if (foundNode != NULL)
            {
                cout << foundNode -> title <<  ":" << foundNode -> year << endl;
            }else{
                cout << "not found" << endl;
            }
            break;
        case 4:
            h.printTableContents();
            break;
        case 5:
            h.printList();
            break;
        case 6:
            h.printListYear();
            break;
        case 7:
            h.colCount(hashFunc);
            break;
        }
        select = menuSelect();
    }
    cout << "Goodbye!" << endl;
    return 1;
}
开发者ID:trst4996,项目名称:Ott_CSCI2270_FinalProject,代码行数:64,代码来源:main.cpp

示例13: main

int main( int argc, const char *argv[] )
{
    
    HashTable annaTable;
    // insert code here...
    
    int choice1;
    int choice2;
    string name;
    int id;
    
    while( 1 ) {
        cout << "\n----------------------" << endl;
        cout << "       The Hashers!" << endl;
        cout << "\n----------------------" << endl;
        cout << "1.Build the database!" << endl;
        cout << "2.Insert a new student" << endl;
        cout << "3.Display students" << endl;
        cout << "4.Search for a student" << endl;
        cout << "5.Exit" << endl;
        cout << "Enter your choice: " << endl;
        cin >> choice1;
        switch( choice1 )
        {
            case 1:
                cout << "\n----------------------" << endl;
                cout << "  The Hashers are building tables!" << endl;
                cout << "\n----------------------" << endl;
                cout << "1.Build using Direct Address" << endl;
                cout << "2.Build using Division" << endl;
                cout << "3.Build using Fibonacci" << endl;
                cout << "4.Build using Perfect" << endl;
                cout << "5.Build using Double Hashing" << endl;
                cout << "6.Build using Universal" << endl;
                cout << "7.Return " << endl;
                cout << "Enter your choice: " << endl;
                cin >> choice2;
                switch( choice2 )
            {
                case 1:
                    break;
                case 2:
                    
                    if (annaTable.isEmpty())
                    {
                        readData(annaTable,"data_set_1");
                    }
                    else
                    {
                        cout << "Table is already built!" << endl;
                    }
                    
                    break;
                case 3:
                    break;
                case 4:
                    break;
                case 5:
                    break;
                case 6:
                    break;
                case 7:
                    break;
                default:
                    break;
                    
            }
                break;
            case 2:
                cout << "\n----------------------" << endl;
                cout << "  INSERT: " << endl;
                cout << "\n----------------------" << endl;
                cout << "1.Insert using Direct Address" << endl;
                cout << "2.Insert using Division" << endl;
                cout << "3.Insert using Fibonacci" << endl;
                cout << "4.Insert using Perfect" << endl;
                cout << "5.Insert using Double Hashing" << endl;
                cout << "6.Insert using Universal" << endl;
                cout << "7.Return " << endl;
                cout << "Enter your choice: " << endl;
                cin >> choice2;
                switch( choice2 )
            {
                case 1:
                    break;
                case 2:
                    
                    cout << "what is the name of the student you want to insert ?" << endl;
                    cin >> name;
                    cout << "what is the id number of the student you want to insert ?" << endl;
                    cin >> id;
                    
                    annaTable.insert(name,id);
                    
                    break;
                case 3:
                    break;
                case 4:
                    break;
                case 5:
//.........这里部分代码省略.........
开发者ID:Stivens73,项目名称:2016_hash_project,代码行数:101,代码来源:final.cpp

示例14: if

ML_START_NAMESPACE

void AnimationExecuter::commandClip(vector<string>* tempEntryParams, kScriptFrameEntry* currentEntry, int /*frameNr*/, size_t /*FrameEntryListIter*/)
{
	//Params:					
	//on/off left/right/... percent toClip (notToClip) (aab/oab)
	if (tempEntryParams->size()>=4)
	{	
		//Parameter 1: on/off
		bool onOff = false;
		onOff=((*tempEntryParams)[0]=="ON");

		//Parameter 2: left/right/...
		//noch nicht
		string clipPlane;
		if ((*tempEntryParams)[1]=="LEFT")
			clipPlane = LAY_CLIPPINGLEFT;
		else if ((*tempEntryParams)[1]=="RIGHT")
			clipPlane = LAY_CLIPPINGRIGHT;
		else if ((*tempEntryParams)[1]=="TOP")
			clipPlane = LAY_CLIPPINGTOP;
		else if ((*tempEntryParams)[1]=="BOTTOM")
			clipPlane = LAY_CLIPPINGBOTTOM;
		else if ((*tempEntryParams)[1]=="REAR")
			clipPlane = LAY_CLIPPINGREAR;
		else clipPlane = LAY_CLIPPINGFRONT; //Front is default																			

		myObjMgr->setObjAttribute(O_CLIPPING,clipPlane,INF_CLIPPING_ON,new string((*tempEntryParams)[0]),omINFOTYPE_STRING,true,true);

		//Parameter 5: listNotToClip						
		vector<string>* listNotToClip = new vector<string>;
		if (tempEntryParams->size()>=5)
			myAnimationParser->getObjectStringList(kBasics::trimQuotatedStr((string)(*tempEntryParams)[4], kBasics::QUOTATION_SINGLE).c_str(),listNotToClip);

		//Parameter 4: listToClip, listForBB						
		HashTable<string>* listToClip = new HashTable<string>;						
		myAnimationParser->getObjectStringList(kBasics::trimQuotatedStr((string)(*tempEntryParams)[3], kBasics::QUOTATION_SINGLE).c_str(),listToClip);

		for ( size_t i = 0; i<listNotToClip->size(); i++)
			listToClip->remove((*listNotToClip)[i]);

		//Parameter 6: aab/oab

		//Transform ClippingBox
		//Get BoundingBox for objects to clip

		AnimationCache::Measures MasterBB = myCache->getMeasuresFromHT((string)(*tempEntryParams)[3]);
		SbVec3f BBCenter = myCache->getBoundingCenter(MasterBB);

		//Translation
		myObjMgr->setObjAttribute(O_CLIPPING,L_GLOBAL,INF_CLIPPING_TRANSLATION,new vec3(BBCenter[0],BBCenter[1],BBCenter[2]),omINFOTYPE_VEC3,true,true);

		//Scale
		//Scale nimmt sowieso nachher bei der ClipBox den größten der 3 werte
		SbVec3f tempScale;
		tempScale[0] = std::abs(MasterBB.BB_max[0]-MasterBB.BB_min[0])/2;
		tempScale[1] = std::abs(MasterBB.BB_max[1]-MasterBB.BB_min[1])/2;
		tempScale[2] = std::abs(MasterBB.BB_max[2]-MasterBB.BB_min[2])/2;
		myObjMgr->setObjAttribute(O_CLIPPING,L_GLOBAL,INF_CLIPPING_SCALE,new vec3(tempScale[0],tempScale[1],tempScale[2]),omINFOTYPE_VEC3,true,true);

		//Parameter 3: percent
		//left 
		//x +1 clip nothing
		//x -1 clip all
		string vecString;
		if (clipPlane == LAY_CLIPPINGLEFT)
			vecString = kBasics::FloatToString(1-2*kBasics::StringToFloat((string)(*tempEntryParams)[2]))+kScriptFrameEntry::DELIMITER_COLOR_SCRIPT+string("0")+kScriptFrameEntry::DELIMITER_COLOR_SCRIPT+string("0");
		else if (clipPlane == LAY_CLIPPINGRIGHT)
			vecString = kBasics::FloatToString(-1+2*kBasics::StringToFloat((string)(*tempEntryParams)[2]))+kScriptFrameEntry::DELIMITER_COLOR_SCRIPT+string("0")+kScriptFrameEntry::DELIMITER_COLOR_SCRIPT+string("0");
		else if (clipPlane == LAY_CLIPPINGTOP)
			vecString = string("0")+kScriptFrameEntry::DELIMITER_COLOR_SCRIPT+string("0")+kScriptFrameEntry::DELIMITER_COLOR_SCRIPT+kBasics::FloatToString(1-2*kBasics::StringToFloat((string)(*tempEntryParams)[2]));
		else if (clipPlane == LAY_CLIPPINGBOTTOM)
			vecString = string("0")+kScriptFrameEntry::DELIMITER_COLOR_SCRIPT+string("0")+kScriptFrameEntry::DELIMITER_COLOR_SCRIPT+kBasics::FloatToString(-1+2*kBasics::StringToFloat((string)(*tempEntryParams)[2]));
		else if (clipPlane == LAY_CLIPPINGREAR)							
			vecString = string("0")+kScriptFrameEntry::DELIMITER_COLOR_SCRIPT+kBasics::FloatToString(1-2*kBasics::StringToFloat((string)(*tempEntryParams)[2]))+kScriptFrameEntry::DELIMITER_COLOR_SCRIPT+string("0");
		else
			vecString = string("0")+kScriptFrameEntry::DELIMITER_COLOR_SCRIPT+kBasics::FloatToString(-1+2*kBasics::StringToFloat((string)(*tempEntryParams)[2]))+kScriptFrameEntry::DELIMITER_COLOR_SCRIPT+string("0");

		setV3ValueInterpol(O_CLIPPING, clipPlane,INF_CLIPPING_TRANSLATION, vecString, currentEntry->getCurrentFrame(), currentEntry->getFrameCount());

		//Nur beim ersten Frame einer setClipPlane-Anweisung soll er alle Clipping-Eigenschaften zurücksetzen.
		//Testen mit Anweisungen a la [1,10]
		if (currentEntry->getCurrentFrame()==0)
		{
			kDebug::Debug("Reset all Clipping to false",kDebug::DL_HIGH);
			//Get read-only access to object container
			const omObjectContainer *oc= getConstObjContainer();

			oc = getObjContainer();
			if(oc != NULL)
			{		
				omObjectContainer ::const_iterator iterObj;
				//definition in mlObjMgrObjectContainer.h: typedef std::map<omIDType, omObject> objVec;

				for ( iterObj = oc->begin(); iterObj!=oc->end(); iterObj++)
				{
					omObject tempObj = iterObj->second;
					//Als Typ für das Feld BOOL zu nehmen scheiterte daran, das nicht existente Felder bei z.B. viewer-Objekten auch TRUE zurückgeben wenn man nach dem Attribut fragt

					omAttribute attr2 = tempObj.getAttribute(LAY_DESCRIPTION,INF_NAME);
//.........这里部分代码省略.........
开发者ID:cguagliano,项目名称:communitymodules,代码行数:101,代码来源:cmdClip.cpp

示例15: main

int main() {

    HashTable<int>* h = new HashTable<int>(47);

    h->insert("sylvan",10);
    h->insert("lora",5);
    h->insert("jake",15);
    h->insert("kiran",20);
    h->insert("theo",16);
    h->insert("sylvan",41);
    h->insert("lora",39);
    h->insert("jake",6);
    h->insert("kiran",3);
    h->insert("theo",1);

    h->insert("will",10);
    h->insert("kelly",5);
    h->insert("nadine",15);
    h->insert("nick",20);
    h->insert("zoe",16);
    h->print();

    if (h->find("sylvan")!=0)
        cout << *(h->find("sylvan")) << endl;

    h->remove("sylvan");
    h->remove("lora");
    h->remove("will");
    h->print();

    h->insert("sylvan",30);
    h->insert("lora",28);
    h->insert("aili",0);
    h->insert("richard",70);
    h->insert("robert",70);
    h->insert("sandie",73);
    h->print();

    delete h;

}
开发者ID:skavanaugh,项目名称:HashTable,代码行数:41,代码来源:hash_test.cpp


注:本文中的HashTable类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。