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


C++ Hash::search方法代码示例

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


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

示例1: profilePush

void FW::profilePush(const char* id)
{
    if (!s_profileStarted)
        return;
    if (!Thread::isMain())
        fail("profilePush() can only be used in the main thread!");

    // Find or create token.

    S32 token;
    S32* found = s_profilePointerToToken.search(id);
    if (found)
        token = *found;
    else
    {
        found = s_profileStringToToken.search(id);
        if (found)
            token = *found;
        else
        {
            token = s_profileStringToToken.getSize();
            s_profileStringToToken.add(id, token);
        }
        s_profilePointerToToken.add(id, token);
    }

    // Find or create timer.

    Vec2i timerKey(-1, token);
    if (s_profileStack.getSize())
        timerKey.x = s_profileStack.getLast();

    S32 timerIdx;
    found = s_profileTimerHash.search(timerKey);
    if (found)
        timerIdx = *found;
    else
    {
        timerIdx = s_profileTimers.getSize();
        s_profileTimerHash.add(timerKey, timerIdx);
        ProfileTimer& timer = s_profileTimers.add();
        timer.id = id;
        timer.parent = timerKey.x;
        if (timerKey.x != -1)
            s_profileTimers[timerKey.x].children.add(timerIdx);
    }

    // Push timer.

    if (s_profileStack.getSize() == 1)
        s_profileTimers[s_profileStack[0]].timer.start();
    s_profileStack.add(timerIdx);
    if (s_profileStack.getSize() > 1)
        s_profileTimers[timerIdx].timer.start();
}
开发者ID:AllioNicholas,项目名称:CG_AS3,代码行数:55,代码来源:Defs.cpp

示例2: main

int main()
{
	cout << "Welcome to this awesome Phone Book\n" << endl;

	Hash hash;
	int choice;
	string name;
	string phone;
	Node* entry;
	do
	{
		menu();
		cin >> choice;
		switch (choice)
		{
		case 1:
			getchar();
			cout << "Name: ";
			getline(cin, name);
			cout << "Phone: ";
			getline(cin, phone);
			entry = new Node();
			entry->name = name;
			entry->phone = phone;
			hash.add(entry);
			break;
		case 2:
			getchar();
			cout << "Enter full name: ";
			getline(cin, name);
			hash.search(name);
			break;
		case 3:
			getchar();
			cout << "Name: ";
			getline(cin, name);
			hash.remove(name);
			break;
		case 4:
			hash.printAll();
			break;
		case 0:
			hash.clearAll();
			break;
		default:
			cout << "Invalid entry. Please try again" << endl;
			break;
		}
	} while (choice != 0);
	
	cout << "Have a good day!" << endl;

	return 0;
}
开发者ID:fhammoud,项目名称:Portfolio,代码行数:54,代码来源:Source.cpp

示例3: popMemOwner

void FW::popMemOwner(void)
{
#if FW_MEM_DEBUG
    U32 threadID = Thread::getID();
    Array<const char*>* stack = s_memOwnerStacks.search(threadID);
    if (stack)
    {
        stack->removeLast();
        if (!stack->getSize())
        {
            s_memOwnerStacks.remove(threadID);
            if (!s_memOwnerStacks.getSize())
                s_memOwnerStacks.reset();
        }
    }
#endif
}
开发者ID:AllioNicholas,项目名称:CG_AS3,代码行数:17,代码来源:Defs.cpp

示例4: pushMemOwner

void FW::pushMemOwner(const char* id)
{
#if !FW_MEM_DEBUG
    FW_UNREF(id);
#else
    s_lock.enter();
    s_memPushingOwner = true;

    U32 threadID = Thread::getID();
    Array<const char*>* stack = s_memOwnerStacks.search(threadID);
    if (!stack)
    {
        stack = &s_memOwnerStacks.add(threadID);
        stack->clear();
    }
    stack->add(id);

    s_memPushingOwner = false;
    s_lock.leave();
#endif
}
开发者ID:AllioNicholas,项目名称:CG_AS3,代码行数:21,代码来源:Defs.cpp

示例5: setprecision

int
main ( ) {

  Hash hashTable;
  cout << setprecision ( 10 );
  cout << "Test 1 - print empty table" << endl;
  hashTable.print ( );
  cout << "-------------------------------------------------------------"
       << endl;
  cout << "Test 2 - processing input file" << endl;
  hashTable.processFile ( "dict5.txt" );
  hashTable.print ( );
  cout << "-------------------------------------------------------------"
       << endl;
  cout << "Test 3 - searching" << endl;
  if ( hashTable.search ( "heath" ) ) 
    cout << "Passed - searching for valid item" << endl;
  else
    cout << "FAILED - searching for valid item" << endl;

  if ( hashTable.search ( "hello" ) ) 
    cout << "Passed - searching for valid item" << endl;
  else
    cout << "FAILED - searching for valid item" << endl;

  if ( hashTable.search ( "ttttt" ) ) 
    cout << "Passed - searching for valid item" << endl;
  else
    cout << "FAILED - searching for valid item" << endl;

  if ( hashTable.search ( "empty" ) ) 
    cout << "FAILED - searching for invalid item" << endl;
  else
    cout << "Passed - searching for invalid item" << endl;
  cout << "-------------------------------------------------------------"
       << endl;
  cout << "Test 4 - testing remove" << endl;
  hashTable.remove ( "happy" );
  hashTable.print ( );
  cout << endl;
  hashTable.remove ( "hello" );
  hashTable.remove ( "harps" );
  hashTable.print ( );
  cout << endl;
  hashTable.remove ( "heath" );
  hashTable.remove ( "heath" );
  hashTable.remove ( "heath" );
  hashTable.print ( );
  cout << endl;
  hashTable.remove ( "rrrrr" );
  hashTable.remove ( "ooooo" );
  hashTable.print ( );
  cout << "-------------------------------------------------------------"
       << endl;
  cout << "Test 5 - output to file" << endl;
  hashTable.output ( "hash.out" );
  cout << endl << endl;
  cout << "-------------------------------------------------------------"
       << endl;
  cout << "Test 6 - Stats" << endl;
  hashTable.printStats ( );
  cout << "-------------------------------------------------------------"
       << endl;
  return 1;
}
开发者ID:norcal82,项目名称:Hash-Table,代码行数:65,代码来源:main.cpp

示例6: importTiffImage

Image* FW::importTiffImage(InputStream& stream)
{
    // Detect endianess and check format.

    U8 endianTag = stream.readU8();
    Input in(stream, (endianTag == 'I'), 1);
    if ((endianTag != 'I' && endianTag != 'M') || in.readU8() != endianTag || in.readU16() != 42)
        setError("Not a TIFF file!");

    // Read directory header.

    U32 dirOfs = in.readU32();
    in.seek(dirOfs);
    int numEntries = in.readU16();
    if (!dirOfs || !numEntries)
        setError("Corrupt TIFF directory!");

    // Read directory entries.

    Hash<U32, Array<U32> > entries;
    for (int i = 0; i < numEntries && !hasError(); i++)
    {
        U16 tag   = in.readU16();
        U16 type  = in.readU16();
        U32 count = in.readU32();
        U32 ofs   = in.readU32();

        // Check type and count.

        int typeSize;
        switch (type)
        {
        case 1:     typeSize = 1; break;    // BYTE
        case 3:     typeSize = 2; break;    // SHORT
        case 4:     typeSize = 4; break;    // LONG
        default:    typeSize = 0; break;
        }

        if (!typeSize)
            continue;

        // Seek to the value.

        U32 oldOfs = in.tell();
        if (typeSize * count <= 4)
            in.seek(oldOfs - 4);
        else
            in.seek(ofs);

        // Read value.

        Array<U32>& data = entries.add(tag);
        data.resize(count);
        for (int j = 0; j < (int)count; j++)
        {
            switch (typeSize)
            {
            case 1:     data[j] = in.readU8(); break;
            case 2:     data[j] = in.readU16(); break;
            case 4:     data[j] = in.readU32(); break;
            default:    FW_ASSERT(false); break;
            }
        }
        in.seek(oldOfs);
    }

    // Find relevant entries and check their sizes.

    const Array<U32>* width         = entries.search(256);  // ImageWidth
    const Array<U32>* height        = entries.search(257);  // ImageLength
    const Array<U32>* numBits       = entries.search(258);  // BitsPerSample
    const Array<U32>* compression   = entries.search(259);  // Compression
    const Array<U32>* photometric   = entries.search(262);  // PhotometricInterpretation
    const Array<U32>* stripOfs      = entries.search(273);  // StripOffsets
    const Array<U32>* numChannels   = entries.search(277);  // SamplesPerPixel
    const Array<U32>* stripBytes    = entries.search(279);  // StripByteCounts
    const Array<U32>* predictor     = entries.search(317);  // Predictor
    const Array<U32>* extraSamples  = entries.search(338);  // ExtraSamples
    const Array<U32>* sampleFormat  = entries.search(339);  // SampleFormat

    if (!width          || width->getSize()         != 1 ||
        !height         || height->getSize()        != 1 ||
        !numBits        || numBits->getSize()       == 0 ||
        !compression    || compression->getSize()   != 1 ||
        !photometric    || photometric->getSize()   != 1 ||
        !stripOfs       || stripOfs->getSize()      == 0 ||
        !numChannels    || numChannels->getSize()   != 1 ||
        !stripBytes     || stripBytes->getSize()    != stripOfs->getSize() ||
        (predictor      && predictor->getSize()     != 1) ||
        (extraSamples   && extraSamples->getSize()  != 1) ||
        (sampleFormat   && sampleFormat->getSize()  != 1))
    {
        setError("Corrupt TIFF directory!");
    }

    if (hasError())
        return NULL;

    // Interpret size.

//.........这里部分代码省略.........
开发者ID:galekoul,项目名称:temporal-lightfield-reconstruction,代码行数:101,代码来源:ImageTiffIO.cpp

示例7: main


//.........这里部分代码省略.........
            log << "Files specified in \'" << SParser.cmd.value1 << "\' are successfully loaded into list \'" << SParser.cmd.listID << "\'.\n" << endl;
/*cout << "Before filter:" << endl;
F[i].print();
cout << endl;*/
            i++;
            break;
        case 11:
            n = tempWordList.read(SParser.cmd.value1);
            if (n != 0) {
                log << "Error: fail to open file \'" << SParser.cmd.value1 << "\'.\n" << endl;
                continue;
            }
            tempFreqList.frequency_unsorted(tempWordList);
            tempFreqList.sort();
            tempFreqNode = tempFreqList.head;
            while (tempFreqNode) {
                F[ID].erase(tempFreqNode->word);
                tempFreqNode = tempFreqNode->pnext;
            }
            tempWordList.clear();
            tempFreqList.clear();
            log << "Words from file \'" << SParser.cmd.value1 << "\' are successfully eliminated from list \'" << SParser.cmd.listID << "\'.\n" << endl;
/*cout << "After filter:" << endl;
F[ID].print();
cout << endl;*/
            break;
        case 12:
            tempFreqNode = F[ID].head;
            while (tempFreqNode) {
                if (tempFreqNode->word[0] == '*')
                    tempString = (tempFreqNode->word).substr(1,(tempFreqNode->word).length()-1);
                else
                    HT.insert(tempFreqNode->word,tempString);
                tempFreqNode = tempFreqNode->pnext;
            }
            log << "Hash table is sucessfully established (or updated).\n" << endl;

/*cout << "Words are stored in hash table as:" << endl;
for (int j = 0; j < HT.size; j++) {
    tempNode = (HT.Table[j]).head;
    if (tempNode == NULL) emp++;
    if (tempNode != NULL) occ++;
    while (tempNode) {
        if (tempNode->pnext != NULL) con++;
        cout << "position: " << j << ", word: " << tempNode->IndexWord << endl;
//        cout << "file(s): ";
//        (tempNode->FileName).print();
        tempNode = tempNode->pnext;
    }
}*/
            break;
        case 13:
            S[i] = SParser.cmd.listID;
            tempString = SParser.cmd.value1;
            transform(tempString.begin(),tempString.end(),tempString.begin(),::tolower); //transfer all the key words into lower case
            pos1 = 0;
            while (pos1 != string::npos) {
                pos2 = tempString.find(",");
                tempWordList.insert(tempString.substr(pos1,pos2));
                if (pos2 == string::npos) pos1 = pos2;
                else {
                    pos1 = 0;
                    tempString = tempString.substr(pos2+1,tempString.length()-pos2-1);
                }
            }
            tempWordNode = tempWordList.head;
            while (tempWordNode) {
                tempWordListpt = HT.search(tempWordNode->word);
                tempFreqList.frequency_unsorted(*tempWordListpt);
                tempFreqList.sort();
                if (tempWordNode->pprev == NULL) {
                    F[i].copy(tempFreqList);
                    tempFreqList.clear();
                }
                else {
                   tempFreqList2.copy(F[i]);
                   F[i].clear();
                   F[i].list_intersection_nonrec(tempFreqList,tempFreqList2);
                   tempFreqList.clear();
                   tempFreqList2.clear();
                }
                tempWordNode = tempWordNode->pnext;
            }
            tempWordList.clear();
            i++;
            log << "Names of those files which contain the words: '" << SParser.cmd.value1 << "' are successfully found and written into list " << SParser.cmd.listID << ".\n" << endl;
            break;
        case 0:
            log << "Error: above line is not a valid script form.\n" << endl;
            break;
        }
    }
  
  log << "End parsing script file \'" << script << "\'.\n" <<endl;
  log.close();
  delete[] L;
  delete[] F;
  delete[] S;
  return 0;
}
开发者ID:zhuoliu0920,项目名称:data-structures,代码行数:101,代码来源:keywordsearch.cpp


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