本文整理汇总了C++中Hash::find方法的典型用法代码示例。如果您正苦于以下问题:C++ Hash::find方法的具体用法?C++ Hash::find怎么用?C++ Hash::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hash
的用法示例。
在下文中一共展示了Hash::find方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: buildWord
bool buildWord(string str, bool original, Hash strHash){
if(strHash.find((char*)&str[0])&&!original)
return true;
for(int i=1;i<str.length();i++){
string left=str.substr(0,i);
string right=str.substr(i,str.length()-i);
if(strHash.find((char*)&left[0])&&buildWord(right, false, strHash))
return true;
}
return false;
}
示例2: main
int main(){
Hash<int>* tab = new Hash<int>(100);
tab->insert("chickin" , 5);
tab->insert("car" , 1);
tab->insert("asdf", 3);
cout << tab->find("chickin") << endl;
cout << tab->find("asdf") << endl;
tab->remove("car");
cout << tab->find("car");
delete tab;
return 0;
}
示例3: main
int main()
{
Hash<int,string> h;
if(h.find(111)!=0)
cout<<*(h.find(111))<<endl;
else
cout<<111<<" Not exist"<<endl;
h.insert(111,"111");
h.insert(222,"222");
h.insert(333,"333");
if(h.find(111)!=0)
cout<<*(h.find(111))<<endl;
else
cout<<111<<"Not exist"<<endl;
if(h.find(222)!=0)
cout<<*(h.find(222))<<endl;
else
cout<<222<<"Not exist"<<endl;
h.remove(111);
cout<<"Remove 111 ..."<<endl;
if(h.find(111)!=0)
cout<<*(h.find(111))<<endl;
else
cout<<111<<" Not exist"<<endl;
}
示例4: printf
void t2(){
// string key checks
printf("test 1, strings----\n");
Hash h;
Value v,w;
char keys[HCOUNT][32];
char vals[HCOUNT][32];
for(int i=0;i<HCOUNT;i++){
sprintf(keys[i],"foo%x",i*31);
Types::tString->set(&v,keys[i]);
sprintf(vals[i],"bar%d",rand()%100000);
Types::tString->set(&w,vals[i]);
// printf("%s %s\n",keys[i],vals[i]);
h.set(&v,&w);
}
for(int i=0;i<HCOUNT;i++){
Types::tString->set(&v,keys[i]);
if(h.find(&v)){
w.copy(h.getval());
if(w.t != Types::tString)
die("value not an int");
const StringBuffer& buf = w.toString();
if(strcmp(buf.get(),vals[i])){
printf("%s != %s\n",buf.get(),vals[i]);
die("value mismatch");
}
} else
die("key not found");
}
}
示例5: if
void t1(){
printf("test 1, integers----\n");
int keys[HCOUNT];
int vals[HCOUNT];
Hash h;
Value v,w;
for(int i=0;i<HCOUNT;i++){
keys[i]=i*31;
Types::tInteger->set(&v,keys[i]);
vals[i]=rand()%100000;
Types::tInteger->set(&w,vals[i]);
h.set(&v,&w);
}
for(int i=0;i<HCOUNT;i++){
Types::tInteger->set(&v,keys[i]);
if(h.find(&v)){
w.copy(h.getval());
if(w.t != Types::tInteger)
die("value not an int");
else if(w.toInt() != vals[i]){
printf("%d != %d\n",w.toInt(),vals[i]);
die("value mismatch");
}
} else
die("key not found");
}
}
示例6: data
/* Brief: TODO description
* Parameter: index, TODO description
* Parameter: role, TODO description
*
* Note: This function is called
*/
QVariant CDailyWeatherModel::data( const QModelIndex & index, int role ) const
{
int column = index.column();
int row = index.row();
//qDebug("from inside Data(), row:%i, col:%i, role=%i, counter=%i", row, column, role, counter);
if (role == Qt::DisplayRole || role == Qt::EditRole)
{
if (mStation == NULL)
return QVariant("n/a");
if (column == CDailyWeatherModel::YEAR)
return QVariant(mYear);
else if (column == CDailyWeatherModel::DOY)
return QVariant(row+1);
else {
// Note: Be sure to use pointer here! Else, the map will be returned by value. This means
// that a copy of this huge map will be made whenever this function is called (whenever
// the model needs to be updated or the table needs to be redraen - potentially many times.
// This will lag the interface.
Hash* hash = mStation->getWeather();
QString yr = QString::number(mYear);
QString doy = QString::number(row+1);
Pair pair(yr, doy);
// Find item in weather map with key
Hash::const_iterator iter = hash->find(pair);
// (Year, Day of Year) not found in weather data map for the current station
if(iter == hash->end())
return QVariant("n/a");
return QVariant(iter.value()->at(column-2));
}
}
else if (role == Qt::TextAlignmentRole)
return QVariant(Qt::AlignCenter);
else
return QVariant();
}
示例7: mode
IntPair mode(const int *values, unsigned int size) {
Hash::iterator it;
Hash hash;
for (int i = 0; i < size; i++) {
it = hash.find(values[i]);
if(it == hash.end()) {
hash.insert( std::make_pair(values[i], 1));
} else {
it->second += 1;
}
}
unsigned int counts = 0;
Hash::iterator found;
for (it = hash.begin(); it != hash.end(); ++it) {
if(it->second > counts) {
counts = it->second;
found = it;
}
}
return *found;
}
示例8: findSmallestSubString
void findSmallestSubString (string word, unsigned int indexInString)
{
Hash::iterator nptr;
bool checkForNewSmallest = false;
/* its not their in words to check */
if( (nptr=words.find(word)) == words.end() ) return ;
if( nptr->second->index == -1 )
noOfWords--;
nptr->second->index = indexInString;
if( start == NULL ) start = nptr->second;
else if( start == nptr->second)
{
start = start->next;
checkForNewSmallest = true;
}
if( end == NULL ) end = nptr->second;
else if( end != nptr->second)
{
Node *n = nptr->second;
if( n->prev ) n->prev->next = n->next;
if( n->next ) n->next->prev = n->prev;
n->prev = end;
end->next = n;
end = n;
}
if( noOfWords == 0 && checkForNewSmallest )
{
if( smallestCount > end->index - start->index + 1 )
{
smallestIndex = start->index;
smallestCount = end->index - start->index + 1;
}
}
}
示例9: setData
/* Brief: TODO description
* Parameter: index, TODO description
* Parameter: value, TODO description
* Parameter: role, TODO description
*/
bool CDailyWeatherModel::setData( const QModelIndex & index, const QVariant & value, int role )
{
int column = index.column();
int row = index.row();
Hash* hash = mStation->getWeather();
QString yr = QString::number(mYear);
QString doy = QString::number(row+1);
Pair pair(yr, doy);
// Find item in weather map with key
Hash::iterator iter = hash->find(pair);
QVector<QString>* values = iter.value();
if (index.isValid() && role == Qt::EditRole)
{
(*values)[column-2] = value.toString();
emit dataChanged(index, index);
return true;
}
return false;
}
示例10: main
int main() {
Value a;
assert(!a.isInteger());
assert(!a.isString());
assert(!a.isList());
assert(!a.isHash());
assert(a.type() == Value::UNDEFINED);
assert(!a);
a = Value(11);
assert(a.isInteger());
assert(!a.isString());
assert(!a.isList());
assert(!a.isHash());
assert(a);
assert(a.asInteger() == 11);
a = Value("123");
assert(!a.isInteger());
assert(a.isString());
assert(!a.isList());
assert(!a.isHash());
assert(a);
assert(a.asString() == "123");
List b;
b.push_back(Value(11));
b.push_back(Value("111"));
a = Value(b);
b.push_back(Value(34));
assert(b.size() == 3);
assert(a.isList());
assert(a.asList().size() == 2);
Hash m;
m["aa"] = Value(12);
m["bb"] = Value(11);
a = Value(m);
m.erase("bb");
assert(m.size() == 1);
assert(m["aa"].asInteger() == 12);
assert(m.find("bb") == m.end());
assert(a.isHash());
assert(a.asHash().size() == 2);
a = Value(Vector(1,-1,2));
assert(a.type() == Value::VECTOR);
assert(a.isVector());
assert(a.asVector().y == -1);
assert(a);
a = Value(Position(1,-1,2));
assert(a.type() == Value::POSITION);
assert(a.isPosition());
assert(a.asPosition().x == 1);
assert(a);
std::cout << "Success!" << std::endl;
return 0;
}
示例11: QVERIFY
void tst_QHash::insert1()
{
const char *hello = "hello";
const char *world = "world";
const char *allo = "allo";
const char *monde = "monde";
{
typedef QHash<QString, QString> Hash;
Hash hash;
QString key;
for (int i = 0; i < 10; ++i) {
key[0] = i + '0';
for (int j = 0; j < 10; ++j) {
key[1] = j + '0';
hash.insert(key, "V" + key);
}
}
for (int i = 0; i < 10; ++i) {
key[0] = i + '0';
for (int j = 0; j < 10; ++j) {
key[1] = j + '0';
hash.remove(key);
}
}
}
{
typedef QHash<int, const char *> Hash;
Hash hash;
hash.insert(1, hello);
hash.insert(2, world);
QVERIFY(hash.size() == 2);
QVERIFY(!hash.isEmpty());
{
Hash hash2 = hash;
hash2 = hash;
hash = hash2;
hash2 = hash2;
hash = hash;
hash2.clear();
hash2 = hash2;
QVERIFY(hash2.size() == 0);
QVERIFY(hash2.isEmpty());
}
QVERIFY(hash.size() == 2);
{
Hash hash2 = hash;
hash2[1] = allo;
hash2[2] = monde;
QVERIFY(hash2[1] == allo);
QVERIFY(hash2[2] == monde);
QVERIFY(hash[1] == hello);
QVERIFY(hash[2] == world);
hash2[1] = hash[1];
hash2[2] = hash[2];
QVERIFY(hash2[1] == hello);
QVERIFY(hash2[2] == world);
hash[1] = hash[1];
QVERIFY(hash[1] == hello);
}
{
Hash hash2 = hash;
hash2.detach();
hash2.remove(1);
QVERIFY(hash2.size() == 1);
hash2.remove(1);
QVERIFY(hash2.size() == 1);
hash2.remove(0);
QVERIFY(hash2.size() == 1);
hash2.remove(2);
QVERIFY(hash2.size() == 0);
QVERIFY(hash.size() == 2);
}
hash.detach();
{
Hash::iterator it1 = hash.find(1);
QVERIFY(it1 != hash.end());
Hash::iterator it2 = hash.find(0);
QVERIFY(it2 != hash.begin());
QVERIFY(it2 == hash.end());
*it1 = monde;
QVERIFY(*it1 == monde);
QVERIFY(hash[1] == monde);
*it1 = hello;
QVERIFY(*it1 == hello);
QVERIFY(hash[1] == hello);
//.........这里部分代码省略.........
示例12: onUpdate
void TextNavigation::onUpdate( float t )
{
WindowText::onUpdate( t );
if ( visible() && activeTime() > UPDATE_NAV_TEXT )
{
setActiveTime( 0 );
GameDocument * pDoc = (GameDocument *)document();
ASSERT( pDoc );
CharString sText;
if ( pDoc->isTeamValid() )
{
GameContext * pContext = pDoc->context();
ASSERT( pContext );
Hash< dword, Array<NounPlanet *> > factionPlanets;
Hash< dword, Array<NounShip *> > factionShips;
int nStars = 0;
int nAsteroids = 0;
int nGates = 0;
// get the players teamId
int nFactionId = pDoc->factionId();
// push all detected objects
for(int z=0;z<pContext->zoneCount();z++)
{
NodeZone * pZone = pContext->zone( z );
for(int i=0;i<pZone->childCount();i++)
{
NounGame * pNoun = WidgetCast<NounGame>( pZone->child(i) );
if (! pNoun )
continue;
if ( pNoun->isDetected( nFactionId ) )
{
if ( WidgetCast<NounShip>( pNoun ) )
factionShips[ pNoun->factionId() ].push( (NounShip *)pNoun );
else if ( WidgetCast<NounPlanet>( pNoun ) )
factionPlanets[ pNoun->factionId() ].push( (NounPlanet *)pNoun );
else if ( WidgetCast<NounStar>( pNoun ) )
nStars++;
else if ( WidgetCast<NounAsteroid>( pNoun ) )
nAsteroids++;
else if ( WidgetCast<NounJumpGate>( pNoun ) )
nGates++;
}
}
}
// update navigation text information
const GameContext::Team & fleet = pContext->team( pDoc->teamId() );
sText += CharString().format( "<b;l>%s</b;/l>:\n", fleet.name );
Array< NounShip * > & ships = factionShips[ fleet.factionId ];
sText += CharString().format("<x;10>Ships:<x;150>%d\n", ships.size() );
for(int k=0;k<NounShip::TYPE_COUNT;k++)
{
// how many ships of this type
int count = 0;
for(int j=0;j<ships.size();j++)
if ( ships[j]->type() == (NounShip::Type)k )
count++;
if ( count > 0 )
sText += CharString().format( "<X;20>%s:<X;150>%d\n", NounShip::typeText( (NounShip::Type)k ), count );
}
if ( factionPlanets.find( fleet.factionId ).valid() )
{
Array< NounPlanet *> & planets = factionPlanets[ fleet.factionId ];
sText += CharString().format("<X;10>Planets:<X;150>%d\n", planets.size() );
int population = 0;
int ports = 0;
int depots = 0;
int yards = 0;
int units = 0;
for(int j=0;j<planets.size();j++)
{
NounPlanet * pPlanet = planets[ j ];
population += pPlanet->population();
units += pPlanet->friendlyUnitCount();
if ( pPlanet->flags() & NounPlanet::FLAG_HAS_DEPOT )
depots++;
if ( pPlanet->flags() & NounPlanet::FLAG_HAS_PORT )
ports++;
if ( pPlanet->flags() & NounPlanet::FLAG_HAS_SHIPYARD )
yards++;
}
if ( population > 0 )
sText += CharString().format( "<X;20>Population:<X;150>%d\n", population );
if ( units > 0 )
sText += CharString().format( "<X;20>Units:<X;150>%d\n", units );
//.........这里部分代码省略.........