本文整理汇总了C++中HashTable::get方法的典型用法代码示例。如果您正苦于以下问题:C++ HashTable::get方法的具体用法?C++ HashTable::get怎么用?C++ HashTable::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashTable
的用法示例。
在下文中一共展示了HashTable::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: make
/**
* Principal function. It creates Nodes and Edges to put in the Graph,
* from the given BBHG
* @param bhg source BBHG
*/
void BBHGDrawer::make() {
if(_made) {
return;
}
ASSERT(_bhg);
ASSERT(_graph);
// Construct the Graph
HashTable<void*, display::Node*> map;
for(BBHG::Iterator bb(_bhg); bb; bb++) {
display::Node *node = _graph->newNode();
map.put(*bb, node);
onNode(*bb, node);
}
for(BBHG::Iterator bb(_bhg); bb; bb++) {
display::Node *node = map.get(*bb);
for(BBHG::OutIterator succ(bb); succ; succ++) {
BBHGEdge* edge = succ;
display::Edge *display_edge;
display_edge = _graph->newEdge(node,map.get(edge->target()));
onEdge(edge, display_edge);
}
}
onEnd(_graph);
_made = true;
}
示例2: testInsert
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));
}
示例3: main
int main(int argc, const char * argv[]) {
HashTable * ht = new HashTable();
ht->put("one", "1");
ht->put("two", "2");
ht->put("three", "3");
ht->put("four", "4");
ht->put("five", "5");
ht->put("six", "6");
ht->put("seven", "7");
string value = ht->get("three");
if (!value.empty())
cout << value << endl;
value = ht->get("two");
if (!value.empty())
cout << value << endl;
value = ht->get("one");
if (!value.empty())
cout << value << endl;
value = ht->get("zero");
if (!value.empty())
cout << value << endl;
value = ht->get("seven");
if (!value.empty())
cout << value << endl;
delete ht;
return 0;
}
示例4: testUpdate
void HashTableTest::testUpdate()
{
// add code for second test here
std::string s1("str1");
std::string s2("str2");
HashTable<std::string, int> hashTable;
hashTable.insert(s1, 13);
hashTable.update(s1, 14);
assert (hashTable.exists(s1));
assert (hashTable.get(s1) == 14);
int retVal = 0;
assert (hashTable.get(s1, retVal));
assert (retVal == 14);
// updating a non existing item must work too
hashTable.update(s2, 15);
assert (hashTable.get(s2) == 15);
}
示例5: testHashTable
void testHashTable()
{
HashTable<int> table;
for (char i = 48; i < 58; i++) { //ascii 0
string key(string("test ") + string(&i));
table.set(key, i);
int val = table.get(key);
cout << key << ": " << val << endl;
}
}
示例6: main
int main() {
HashTable h;
h.put(10,10);
h.put(130,130);
h.put(8,8);
h.put(128,128);
h.put(40,40);
h.put(1,1);
h.put(0,0);
h.put(10,20);
cout << h.get(10) << endl;
return 0;
}
示例7: main
int main(){
HashTable<int, string> t;
for (int k=0; k < 100; k++){
int l = k*42;
for (int i=l; i < l+42; i++)
t.insertAt(i, "Foo");
for (int i=l; i < l+42; i +=2)
t.remove(i);
}
for (int i=0; i < 4200; i+=5)
cout << t.get(i, "None");
cout << "Done!" << endl;
}
示例8: Inquire
void Inquire(string Licensestr, HashTable<LicenseType, BikePtr>& ht){
LicenseType License(Licensestr);
BikePtr* bikeMetaPtr = ht.get(License);
if( bikeMetaPtr ) {
BikePtr bike = *bikeMetaPtr;
xStationType station = bike->Station;
ClassType Class = bike->Class;
int mileage = bike->Mileage;
cout << setw(15) << "License" << setw(15) << "Mileage"<<setw(15) << "Class" << setw(15) << "Station"<<endl;
cout<<"============================================================"<< endl;
cout << setw(11) << License << setw(15) << mileage<<setw(15) << classToStr(Class) << setw(15) << stationTypeToString(station) << endl << endl;
}
else {
cout << "Bike " << Licensestr << " does not belong to our company." << endl;
}
}
示例9: 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;
}
示例10: reduce
void LoopReductor::reduce(VirtualCFG *vcfg, CFG *cfg) {
HashTable<BasicBlock*,BasicBlock*> map;
map.put(cfg->entry(), vcfg->entry());
map.put(cfg->exit(),vcfg->exit());
idx = 1;
/* duplicate the basic blocks */
for (CFG::BBIterator bb(cfg); bb; bb++) {
if (!bb->isEnd()) {
BasicBlock *vbb = new VirtualBasicBlock(*bb);
INDEX(vbb) = idx;
idx++;
map.put(bb, vbb);
vcfg->addBB(vbb);
}
}
INDEX(vcfg->exit()) = idx;
idx++;
/* connect edges */
for (CFG::BBIterator bb(cfg); bb; bb++) {
for (BasicBlock::OutIterator edge(bb); edge; edge++) {
if (edge->kind() == Edge::CALL) {
BasicBlock *vsource = map.get(edge->source(), NULL);
CFG *vcalled = vcfgvec.get(INDEX(edge->calledCFG()));
ASSERT(vsource && vcalled);
Edge *vedge = new Edge(vsource, vcalled->entry(), Edge::CALL);
CALLED_CFG(vedge) = vcalled;
} else {
BasicBlock *vsource = map.get(edge->source(), NULL);
BasicBlock *vtarget = map.get(edge->target(), NULL);
ASSERT(vsource && vtarget);
new Edge(vsource, vtarget, edge->kind());
}
}
}
Vector<BasicBlock*> *ancestors = new Vector<BasicBlock*>();
for (CFG::BBIterator bb(vcfg); bb; bb++) {
IN_LOOPS(bb) = new dfa::BitSet(vcfg->countBB());
}
/* Do the Depth-First Search, compute the ancestors sets, and mark loop headers */
depthFirstSearch(vcfg->entry(), ancestors);
/* Collect all loop headers in a bitset */
/*
for (CFG::BBIterator bb(vcfg); bb; bb++)
if (LOOP_HEADER(bb)) {
realhdr.add(bb->number());
}
*/
/*
HashTable<int, BasicBlock*> hdrmap;
Vector<BasicBlock*> dups;
*/
bool done = false;
while (!done) {
done = true;
for (CFG::BBIterator bb(vcfg); bb; bb++) {
Vector<Edge*> toDel;
BasicBlock *duplicate = NULL;
for (BasicBlock::InIterator edge(bb); edge; edge++) {
/* compute loops entered by the edge */
dfa::BitSet enteredLoops(**IN_LOOPS(bb));
enteredLoops.remove(**IN_LOOPS(edge->source()));
/* The edge is a regular entry if it enters one loop, and edge->target() == loop header */
if (!((enteredLoops.count() == 0) || ((enteredLoops.count() == 1) && (enteredLoops.contains(bb->number()))))) {
if (!duplicate) {
duplicate = new VirtualBasicBlock(bb);
ASSERT(DUPLICATE_OF(bb) == NULL);
DUPLICATE_OF(bb) = duplicate;
INDEX(duplicate) = idx;
idx++;
vcfg->addBB(duplicate);
IN_LOOPS(duplicate) = new dfa::BitSet(**IN_LOOPS(edge->source()));
for (BasicBlock::OutIterator outedge(bb); outedge; outedge++) {
if (DUPLICATE_OF(outedge->target())) {
new Edge(duplicate, DUPLICATE_OF(outedge->target()), outedge->kind());
} else {
new Edge(duplicate, outedge->target(), outedge->kind());
}
}
}
done = false;
new Edge(edge->source(), duplicate, edge->kind());
toDel.add(edge);
}
}
//.........这里部分代码省略.........
示例11: main
int main(int argc, char *argv[])
{
//checks to see correct number of arguments are passed in
if(argc != 2)
cerr << "Not correct number of arguments passed in." << endl;
//creates a hash table
HashTable htable;
vector<string> nameVector;
int i, dayNum, monthNum, yearNum;
string day, month, year;
ifstream infile(argv[1]);
if(!infile.is_open())
cout << "Could not open the file." << endl;
else
{
string line;
string name;
int count = 0;
while(getline(infile, line))
{
stringstream instream(line);
getline(instream, name, ',');
getline(instream, month, '/');
getline(instream, day, '/');
getline(instream, year);
Date d(atoi(month.c_str()), atoi(day.c_str()), atoi(year.c_str()));
htable.insert(d, name);
}
}
string wholeDate;
//get the initial date from the user
cout << "Please enter a date (mm/dd/yyyy) or 0 when finished: " ;
cin >> wholeDate;
//parse the initial date
stringstream newinstream(wholeDate);
getline(newinstream, month, '/');
getline(newinstream, day, '/');
getline(newinstream, year);
dayNum = atoi(day.c_str());
monthNum = atoi(month.c_str());
yearNum = atoi(year.c_str());
while(dayNum != 0 && monthNum != 0 && yearNum != 0)
{
Date getDate(monthNum, dayNum, yearNum);
nameVector = htable.get(getDate);
if(nameVector.size() == 0)
cout << "No names found for that date" << endl;
else
{
cout << "Number of names for date: " << month << "/" << day << "/" << year << ": " << nameVector.size()<< endl;
for(i = 0; i < nameVector.size(); i++)
cout << nameVector[i] << endl;
}
//get the next date from the user
cout << "Enter another date or 0 when finished: " ;
cin >> wholeDate;
//parse the next date
stringstream newinstream(wholeDate);
getline(newinstream, day, '/');
getline(newinstream, month, '/');
getline(newinstream, year);
dayNum = atoi(day.c_str());
monthNum = atoi(month.c_str());
yearNum = atoi(year.c_str());
}
return 0;
}
示例12: main
int main(int argc, char** arvg){
srand(time(NULL));
vector <int> v;
BSTree* root = new BSTree();
HashTable *ht = new HashTable();
int key, counter = 0;
initValues(v, *root, *ht);
cout << "Vector: " << endl;
sort(v.begin(), v.end());
printVector(v);
cout << "Binary Search Tree: " << endl;
root->print();
cout << "Hash table: " << endl;
ht->printHashTable();
cout << "Insert a key to search for: ";
cin >> key;
cout << endl << endl << "-------------Sequential Search-------------"
<< endl << endl;
sequentialSearch(v, key, counter);
std::string seq = "Number of iteractions from the Sequential Search: ";
seq += std::to_string(counter);
cout << seq << endl;
cout << endl << endl << "-------------Binary Search-------------"
<< endl << endl;
counter = 0;
binarySearch(v, key, counter, 0, size-1);
std::string bin = "Number of iteractions from the Binary Search: ";
bin += std::to_string(counter);
cout << bin << endl;
cout << endl << endl << "-------------Binary Search Tree-------------"
<< endl << endl;
counter = 0;
root->search(key, counter);
cout << endl << endl << "-------------Hash Table-------------"
<< endl << endl;
counter = 0;
ht->get(key, counter);
std::string hash = "Number of iteractions from the Hash Table: ";
hash += std::to_string(counter);
cout << hash << endl;
cout << endl << endl << "-------------Destroying Structures-------------"
<< endl << endl;
delete root;
delete ht;
getchar();
return 0;
}
示例13:
/**
* Find a type by its name.
* @param name Type name.
* @return Found type or NULL.
*/
AbstractType *AbstractType::getType(CString name) {
return types.get(name, 0);
}
示例14: testHashTable
int testHashTable()
{
HashTable<uint64_t *,uint64_t> *hashTable;
std::vector<uint64_t> verify;
hashTable = new HashTable<uint64_t *,uint64_t>(glbTestSize);
uint64_t *value;
cout << "\nTesting HashTable.\n";
verify.resize(glbTestSize);
for (int ix = 0; ix < glbTestSize; ix++)
{
do
{
value = new uint64_t(random());
}
while (hashTable->get(*value) == NULL);
hashTable->insert(value, *value);
verify[ix] = *value;
}
for (int ix = 0; ix < glbTestSize; ix++)
{
if (*hashTable->get(verify[ix]) != verify[ix])
{
hashTable->get(verify[ix]);
cout << "Index ";
cout << ix;
cout << " does not match!\n";
//return -1;
}
//if ((ix % 4) == 3) {
// hashTable->remove(index);
//}
}
for (int ix = 0; ix < glbTestSize; ix++)
{
if (*hashTable->get(verify[ix]) != verify[ix])
{
cout << "Index ";
cout << ix;
cout << " does not match!\n";
return -1;
}
hashTable->remove(verify[ix]);
//if ((index % 4) != 3) {
// hashTable->remove(index);
//}
}
delete hashTable;
cout << "HashTable:Done\n";
return 0;
}
示例15: setInitialCraftingValues
void GeneticLabratory::setInitialCraftingValues(TangibleObject* prototype, ManufactureSchematic* manufactureSchematic, int assemblySuccess) {
if(manufactureSchematic == NULL || manufactureSchematic->getDraftSchematic() == NULL)
return;
ManagedReference<DraftSchematic* > draftSchematic = manufactureSchematic->getDraftSchematic();
CraftingValues* craftingValues = manufactureSchematic->getCraftingValues();
float value, maxPercentage, currentPercentage, weightedSum;
String itemName;
// These 2 values are pretty standard, adding these
itemName = "xp";
value = float(draftSchematic->getXpAmount());
craftingValues->addExperimentalProperty("", itemName, value, value, 0, true, CraftingManager::OVERRIDECOMBINE);
itemName = "complexity";
value = manufactureSchematic->getComplexity();
craftingValues->addExperimentalProperty("", itemName, value, value, 0, true, CraftingManager::OVERRIDECOMBINE);
float modifier = calculateAssemblyValueModifier(assemblySuccess);
// Cast component to genetic
if (!prototype->isComponent())
return;
GeneticComponent* genetic = cast<GeneticComponent*>(prototype);
HashTable<String, ManagedReference<DnaComponent*> > slots;
for (int i = 0; i < manufactureSchematic->getSlotCount(); ++i) {
// Dna Component Slots
Reference<IngredientSlot* > iSlot = manufactureSchematic->getSlot(i);
ComponentSlot* cSlot = cast<ComponentSlot*>(iSlot.get());
ManagedReference<TangibleObject*> tano = cSlot->getPrototype();
ManagedReference<DnaComponent*> component = cast<DnaComponent*>( tano.get());
slots.put(cSlot->getSlotName(),component);
}
// At this point we have all the DNA slots. Update the craftingvalue accordingly
DnaComponent* phy = slots.get("physique_profile").get();
DnaComponent* pro = slots.get("prowess_profile").get();
DnaComponent* men = slots.get("mental_profile").get();
DnaComponent* psy = slots.get("psychological_profile").get();
DnaComponent* agr = slots.get("aggression_profile").get();
uint32 harMax, fortMax, endMax,intMax, dexMax,cleMax,depMax,couMax,fieMax,powMax;
fortMax = applyFormula(phy->getForititude(),pro->getForititude(),men->getForititude(),psy->getForititude(),agr->getForititude(),PHYSIQUE);
harMax = applyFormula(phy->getHardiness(),pro->getHardiness(),men->getHardiness(),psy->getHardiness(),agr->getHardiness(),PHYSIQUE);
dexMax = applyFormula(phy->getDexterity(),pro->getDexterity(),men->getDexterity(),psy->getDexterity(),agr->getDexterity(),PROWESS);
endMax = applyFormula(phy->getEndurance(),pro->getEndurance(),men->getEndurance(),psy->getEndurance(),agr->getEndurance(),PROWESS);
intMax = applyFormula(phy->getIntellect(),pro->getIntellect(),men->getIntellect(),psy->getIntellect(),agr->getIntellect(),MENTAL);
cleMax = applyFormula(phy->getCleverness(),pro->getCleverness(),men->getCleverness(),psy->getCleverness(),agr->getCleverness(),MENTAL);
depMax = applyFormula(phy->getDependency(),pro->getDependency(),men->getDependency(),psy->getDependency(),agr->getDependency(),PHYSCHOLOGICAL);
couMax = applyFormula(phy->getCourage(),pro->getCourage(),men->getCourage(),psy->getCourage(),agr->getCourage(),PHYSCHOLOGICAL);
fieMax = applyFormula(phy->getFierceness(),pro->getFierceness(),men->getFierceness(),psy->getFierceness(),agr->getFierceness(),AGRESSION);
powMax = applyFormula(phy->getPower(),pro->getPower(),men->getPower(),psy->getPower(),agr->getPower(),AGRESSION);
uint32 fortMin,endMin,harMin,intMin,dexMin,cleMin,depMin,couMin,fieMin,powMin;
fortMin = calcMin(fortMax);
harMin = calcMin(harMax);
dexMin = calcMin(dexMax);
endMin = calcMin(endMax);
intMin = calcMin(intMax);
cleMin = calcMin(cleMax);
depMin = calcMin(depMax);
couMin = calcMin(couMax);
fieMin = calcMin(fieMax);
powMin = calcMin(powMax);
float blast, energy, kinetic,heat,cold,electric,acid,stun,saber;
blast = applyFormula(phy->getBlast(),pro->getBlast(),men->getBlast(),psy->getBlast(),agr->getBlast(),PHYSIQUE);
kinetic = applyFormula(phy->getKinetic(),pro->getKinetic(),men->getKinetic(),psy->getKinetic(),agr->getKinetic(),PHYSIQUE);
energy = applyFormula(phy->getEnergy(),pro->getEnergy(),men->getEnergy(),psy->getEnergy(),agr->getEnergy(),PHYSIQUE);
heat = applyFormula(phy->getHeat(),pro->getHeat(),men->getHeat(),psy->getHeat(),agr->getHeat(),PHYSIQUE);
cold = applyFormula(phy->getCold(),pro->getCold(),men->getCold(),psy->getCold(),agr->getCold(),PHYSIQUE);
electric = applyFormula(phy->getElectric(),pro->getElectric(),men->getElectric(),psy->getElectric(),agr->getElectric(),PHYSIQUE);
acid = applyFormula(phy->getAcid(),pro->getAcid(),men->getAcid(),psy->getAcid(),agr->getAcid(),PHYSIQUE);
stun = applyFormula(phy->getStun(),pro->getStun(),men->getStun(),psy->getStun(),agr->getStun(),PHYSIQUE);
saber = applyFormula(phy->getSaber(),pro->getSaber(),men->getSaber(),psy->getSaber(),agr->getSaber(),PHYSIQUE);
craftingValues->addExperimentalProperty("expPhysiqueProfile","fortitude",fortMin,fortMax,0,false,CraftingManager::LINEARCOMBINE);
craftingValues->addExperimentalProperty("expPhysiqueProfile","hardiness",harMin,harMax,0,false,CraftingManager::LINEARCOMBINE);
craftingValues->addExperimentalProperty("expProwessProfile","dexterity",dexMin,dexMax,0,false,CraftingManager::LINEARCOMBINE);
craftingValues->addExperimentalProperty("expProwessProfile","endurance",endMin,endMax,0,false,CraftingManager::LINEARCOMBINE);
craftingValues->addExperimentalProperty("expMentalProfile","intellect",intMin,intMax,0,false,CraftingManager::LINEARCOMBINE);
craftingValues->addExperimentalProperty("expMentalProfile","cleverness",cleMin,cleMax,0,false,CraftingManager::LINEARCOMBINE);
craftingValues->addExperimentalProperty("expPsychologicalProfile","dependability",depMin,depMax,0,false,CraftingManager::LINEARCOMBINE);
craftingValues->addExperimentalProperty("expPsychologicalProfile","courage",couMin,couMax,0,false,CraftingManager::LINEARCOMBINE);
craftingValues->addExperimentalProperty("expAggressionProfile","fierceness",fieMin,fieMax,0,false,CraftingManager::LINEARCOMBINE);
craftingValues->addExperimentalProperty("expAggressionProfile","power",powMin,powMax,0,false,CraftingManager::LINEARCOMBINE);
craftingValues->addExperimentalProperty("","dna_comp_armor_kinetic",calcResistMin(kinetic,modifier),kinetic,0,true,CraftingManager::OVERRIDECOMBINE);
craftingValues->addExperimentalProperty("","dna_comp_armor_blast",calcResistMin(blast,modifier),blast,0,true,CraftingManager::OVERRIDECOMBINE);
craftingValues->addExperimentalProperty("","dna_comp_armor_energy",calcResistMin(energy,modifier),energy,0,true,CraftingManager::OVERRIDECOMBINE);
craftingValues->addExperimentalProperty("","dna_comp_armor_heat",calcResistMin(heat,modifier),heat,0,true,CraftingManager::OVERRIDECOMBINE);
craftingValues->addExperimentalProperty("","dna_comp_armor_cold",calcResistMin(cold,modifier),cold,0,true,CraftingManager::OVERRIDECOMBINE);
craftingValues->addExperimentalProperty("","dna_comp_armor_electric",calcResistMin(electric,modifier),electric,0,true,CraftingManager::OVERRIDECOMBINE);
craftingValues->addExperimentalProperty("","dna_comp_armor_acid",calcResistMin(acid,modifier),acid,0,true,CraftingManager::OVERRIDECOMBINE);
craftingValues->addExperimentalProperty("","dna_comp_armor_stun",calcResistMin(stun,modifier),stun,0,true,CraftingManager::OVERRIDECOMBINE);
craftingValues->addExperimentalProperty("","dna_comp_armor_saber",calcResistMin(saber,modifier),saber,0,true,CraftingManager::OVERRIDECOMBINE);
craftingValues->setMaxPercentage("dna_comp_armor_kinetic",kinetic/100);
craftingValues->setMaxPercentage("dna_comp_armor_blast",blast/100);
craftingValues->setMaxPercentage("dna_comp_armor_energy",energy/100);
craftingValues->setMaxPercentage("dna_comp_armor_heat",heat/100);
craftingValues->setMaxPercentage("dna_comp_armor_cold",cold/100);
craftingValues->setMaxPercentage("dna_comp_armor_electric",electric/100);
//.........这里部分代码省略.........