本文整理汇总了C++中HashMap::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ HashMap::clear方法的具体用法?C++ HashMap::clear怎么用?C++ HashMap::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashMap
的用法示例。
在下文中一共展示了HashMap::clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testClear
void HashMapTest::testClear() {
HashMap<int, std::string> hashMap;
hashMap.put(1, "one");
hashMap.put(3, "three");
hashMap.put(2, "two");
hashMap.clear();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Clear failed to reset size", 0, hashMap.size());
for (int i = 0; i < 125; i++) {
CPPUNIT_ASSERT_THROW_MESSAGE(
"Failed to clear all elements",
hashMap.get(i),
NoSuchElementException);
}
// Check clear on a large loaded map of Integer keys
HashMap<int, std::string> map;
for (int i = -32767; i < 32768; i++) {
map.put(i, "foobar");
}
map.clear();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Failed to reset size on large integer map", 0, map.size());
for (int i = -32767; i < 32768; i++) {
CPPUNIT_ASSERT_THROW_MESSAGE(
"Failed to clear all elements",
map.get(i),
NoSuchElementException);
}
}
示例2: setLiveValues
static void setLiveValues(HashMap<Node*, AbstractValue>& values, HashSet<Node*>& live)
{
values.clear();
HashSet<Node*>::iterator iter = live.begin();
HashSet<Node*>::iterator end = live.end();
for (; iter != end; ++iter)
values.add(*iter, AbstractValue());
}
示例3: populateCopyOfNotificationPermissions
void WebNotificationManagerProxy::populateCopyOfNotificationPermissions(HashMap<String, bool>& permissions)
{
RefPtr<ImmutableDictionary> knownPermissions = m_provider.notificationPermissions();
permissions.clear();
RefPtr<ImmutableArray> knownOrigins = knownPermissions->keys();
for (size_t i = 0; i < knownOrigins->size(); ++i) {
WebString* origin = knownOrigins->at<WebString>(i);
permissions.set(origin->string(), knownPermissions->get<WebBoolean>(origin->string())->value());
}
}
示例4: testClear
void testClear ()
{
map->put ((char*)"one", 1);
CPPUNIT_ASSERT_EQUAL (map->empty (), false);
map->clear ();
CPPUNIT_ASSERT_EQUAL (map->empty (), true);
}
示例5: testIsEmpty
void HashMapTest::testIsEmpty() {
HashMap<int, std::string> hashMap;
CPPUNIT_ASSERT_MESSAGE("Returned false for new map", hashMap.isEmpty());
hashMap.put(1, "1");
CPPUNIT_ASSERT_MESSAGE("Returned true for non-empty", !hashMap.isEmpty());
hashMap.clear();
CPPUNIT_ASSERT_MESSAGE("Returned false for cleared map", hashMap.isEmpty());
}
示例6: main
int main()
{
SString *inicial = new SString(NULL, '\0');
while(true)
{
cin.getline(lectura, 1010);
int tam = strlen(lectura);
int act = 0;
for(int i = 0; i < tam + 1; i++)
{
if(lectura[i] != ' ')
{
tams[act] = 0;
lecturaSE[act++] = lectura[i];
}
}
tam = strlen(lecturaSE);
if(tam == 0)
return 0;
tabla.clear();
for(int i = 0; i < tam; i++)
{
SString *anterior = inicial;
for(int j = i; j < tam; j++)
{
SString nuevo(anterior, lecturaSE[j]);
SString **enTabla = tabla.lookupKey(&nuevo);
if(enTabla == NULL)
{
SString *nuevaEntrada = new SString(nuevo.anterior, nuevo.ultima);
tabla[nuevaEntrada] = 1;
anterior = nuevaEntrada;
}
else
{
int nuevoV = ++tabla[*enTabla];
anterior = *enTabla;
if(nuevoV > tams[j - i + 1])
tams[j - i + 1] = nuevoV;
}
}
}
for(int i = 0; i < tam; i++)
{
if(tams[i] > 1)
cout << tams[i] << endl;
}
cout << endl;
}
}
示例7: willDestroyPage
void DOMWindowExtensionBasic::willDestroyPage(WKBundleRef, WKBundlePageRef)
{
HashMap<WKBundleDOMWindowExtensionRef, int>::iterator it = m_extensionToRecordMap.begin();
HashMap<WKBundleDOMWindowExtensionRef, int>::iterator end = m_extensionToRecordMap.end();
for (; it != end; ++it) {
updateExtensionStateRecord(it->key, Removed);
WKRelease(it->key);
}
m_extensionToRecordMap.clear();
sendExtensionStateMessage();
sendBundleMessage("TestComplete");
}
示例8: LOGINFO
vector<ServerDescriptor> ServerFactory::getServerFromRegistry( const string& application, const string& serverName, string& result)
{
LOG->debug()<<"get server from registry ["<< application <<"."<<serverName<<"]"<<endl;
vector<ServerDescriptor> vServerDescriptor;
try
{
RegistryPrx _pRegistryPrx = AdminProxy::getInstance()->getRegistryProxy();
if(!_pRegistryPrx)
{
result = "coun't get the proxy of registry.";
LOG->error()<<result<< endl;
return vServerDescriptor;
}
vServerDescriptor =_pRegistryPrx->getServers( application, serverName,_tPlatformInfo.getNodeName());
//清空cache
if( vServerDescriptor.size()> 0 && application == "" && serverName == "")
{
g_serverInfoHashmap.clear();
LOGINFO("hashmap clear ok "<<endl);
}
//重置cache
for(unsigned i = 0; i < vServerDescriptor.size(); i++)
{
ServerInfo tServerInfo;
tServerInfo.application = vServerDescriptor[i].application;
tServerInfo.serverName = vServerDescriptor[i].serverName;
g_serverInfoHashmap.set(tServerInfo,vServerDescriptor[i]);
LOGINFO("hashmap set ok "<<tServerInfo.application<<"."<<tServerInfo.serverName<<endl);
}
} catch (exception &e)
{
result = "ServerFactory::getServerFromRegistry exception:";
result = result + e.what();
LOG->error()<<result<< endl;
}
return vServerDescriptor;
}
示例9: main
int main () {
#ifndef ONLINE_JUDGE
freopen ("in.txt", "r", stdin);
freopen ("out.txt", "w", stdout);
#endif
for (;;) {
map.clear();
int len, n;
bool ans = false;
scanf("%d\n", &len);
if(len == -1) return 0;
scanf("%d\n", &n);
for (int i = 0; i < n; ++i) {
int left, right;
char s[20];
scanf("%d %d %s\n", &left, &right, s);
if(ans) continue;
if(left > right) swap(left, right);
if(! add(left, right, s[0]=='o')) {
ans = true;
printf("%d\n", i);
}
}
if(!ans) printf("%d\n", n);
}
return 0;
}
示例10: json
//.........这里部分代码省略.........
case EdgeType::Index:
json.appendNumber(edge.u.index);
break;
default:
// No data for this edge type.
json.append('0');
break;
}
};
json.append('{');
// version
json.appendLiteral("\"version\":1");
// nodes
json.append(',');
json.appendLiteral("\"nodes\":");
json.append('[');
json.appendLiteral("0,0,0,0"); // <root>
for (HeapSnapshot* snapshot = m_profiler.mostRecentSnapshot(); snapshot; snapshot = snapshot->previous()) {
for (auto& node : snapshot->m_nodes)
appendNodeJSON(node);
}
json.append(']');
// node class names
json.append(',');
json.appendLiteral("\"nodeClassNames\":");
json.append('[');
Vector<const char *> orderedClassNames(classNameIndexes.size());
for (auto& entry : classNameIndexes)
orderedClassNames[entry.value] = entry.key;
classNameIndexes.clear();
bool firstClassName = true;
for (auto& className : orderedClassNames) {
if (!firstClassName)
json.append(',');
firstClassName = false;
json.appendQuotedJSONString(className);
}
orderedClassNames.clear();
json.append(']');
// Process edges.
// Replace pointers with identifiers.
// Remove any edges that we won't need.
m_edges.removeAllMatching([&] (HeapSnapshotEdge& edge) {
// If the from cell is null, this means a <root> edge.
if (!edge.from.cell)
edge.from.identifier = 0;
else {
auto fromLookup = allowedNodeIdentifiers.find(edge.from.cell);
if (fromLookup == allowedNodeIdentifiers.end())
return true;
edge.from.identifier = fromLookup->value;
}
if (!edge.to.cell)
edge.to.identifier = 0;
else {
auto toLookup = allowedNodeIdentifiers.find(edge.to.cell);
if (toLookup == allowedNodeIdentifiers.end())
return true;
edge.to.identifier = toLookup->value;
}
示例11: hashMapInt
void hashMapInt() {
HashMap<int, int> m;
//insert
assert("HashMap::insert()", m.insert(2, 5).second);
assert("HashMap::insert()", m.insert(3, 6).second);
assert("HashMap::insert()", m.insert(4, 7).second);
assert("HashMap::size()", m.size() == 3);
//dupe insert
Pair<HashMap<int, int>::Iterator, bool> res = m.insert(4, 8);
assert("HashMap::insert()", !res.second);
assert("HashMap::insert()", res.first != m.end());
assert("HashMap::insert()", res.first->first == 4);
assert("HashMap::insert()", res.first->second == 7);
//find
HashMap<int, int>::Iterator itr = m.find(3);
assert("HashMap::find()", itr != m.end());
assert("HashMap::find()", itr->first == 3);
assert("HashMap::find()", itr->second == 6);
//iterate
itr = m.begin();
assert("HashMap::begin()", itr != m.end());
++itr;
itr++;
++itr;
assert("HashMap::Iterator", itr == m.end());
//const iterator
HashMap<int, int>::ConstIterator citr = m.find(2);
assert("cHashMap::find()", citr != m.end());
assert("cHashMap::find()", citr->first == 2);
assert("cHashMap::find()", citr->second == 5);
citr = m.begin();
assert("cHashMap::begin()", citr != m.end());
++citr;
citr++;
++citr;
assert("cHashMap::Iterator", citr == m.end());
//erase
assert("HashMap::erase()", m.erase(3));
assert("HashMap::erase()", m.size() == 2);
//copy constuctor
HashMap<int, int> copy(m);
assert("HashMap::HashMap(HashMap)", copy.size() == 2);
//erase by iterator
m.erase(m.find(2));
assert("HashMap::erase(Iterator)", m.size() == 1);
//clear
m.clear();
assert("HashMap::clear()", m.size() == 0);
itr = m.find(4);
assert("HashMap::clear()", itr == m.end());
assert("HashMap::clear()", m.begin() == m.end());
//assignment operator
m = copy;
assert("HashMap::operator=", m.size() == 2);
//square bracket operator
m[9] = 10;
assert("HashMap::operator[]", m[2] == 5);
}
示例12: hashMap
void hashMap() {
HashMap<String, String> m;
//insert
assert("HashMap::insert()", m.insert("foo", "F00").second);
assert("HashMap::insert()", m.insert("bar", "B4R").second);
assert("HashMap::insert()", m.insert("baz", "B4Z").second);
assert("HashMap::size()", m.size() == 3);
//dupe insert
Pair<HashMap<String, String>::Iterator, bool> res = m.insert("foo", "whatev");
assert("HashMap::insert()", !res.second);
assert("HashMap::insert()", res.first != m.end());
assert("HashMap::insert()", res.first->first == "foo");
assert("HashMap::insert()", res.first->second == "F00");
//find
HashMap<String, String>::Iterator itr = m.find("bar");
assert("HashMap::find()", itr != m.end());
assert("HashMap::find()", itr->first == "bar");
assert("HashMap::find()", itr->second == "B4R");
//iterate
itr = m.begin();
assert("HashMap::begin()", itr != m.end());
++itr;
itr++;
++itr;
assert("HashMap::Iterator", itr == m.end());
//const iterator
HashMap<String, String>::ConstIterator citr = m.find("baz");
assert("cHashMap::find()", citr != m.end());
assert("cHashMap::find()", citr->first == "baz");
assert("cHashMap::find()", citr->second == "B4Z");
citr = m.begin();
assert("cHashMap::begin()", citr != m.end());
++citr;
citr++;
++citr;
assert("cHashMap::Iterator", citr == m.end());
//erase
assert("HashMap::erase()", m.erase("bar"));
assert("HashMap::erase()", m.size() == 2);
//copy constuctor
HashMap<String, String> copy(m);
assert("HashMap::HashMap(HashMap)", copy.size() == 2);
//erase by iterator
m.erase(m.find("baz"));
assert("HashMap::erase(Iterator)", m.size() == 1);
//clear
m.clear();
assert("HashMap::clear()", m.size() == 0);
itr = m.find("baz");
assert("HashMap::clear()", itr == m.end());
assert("HashMap::clear()", m.begin() == m.end());
//assignment operator
m = copy;
assert("HashMap::operator=", m.size() == 2);
//square bracket operator
m["norg"] = "N07G";
assert("HashMap::operator[]", m["foo"] == "F00");
}
示例13: fixSSA
//.........这里部分代码省略.........
// Create Defs for all of the stores to the stack variable.
for (BasicBlock* block : proc) {
for (Value* value : *block) {
if (value->opcode() != Store)
continue;
StackSlotValue* stack = value->child(1)->as<StackSlotValue>();
if (!stack)
continue;
if (SSACalculator::Variable* variable = stackToVariable.get(stack))
ssa.newDef(variable, block, value->child(0));
}
}
// Decide where Phis are to be inserted. This creates them but does not insert them.
ssa.computePhis(
[&] (SSACalculator::Variable* variable, BasicBlock* block) -> Value* {
StackSlotValue* stack = variableToStack[variable->index()];
Value* phi = proc.add<Value>(Phi, stackVariable.get(stack), stack->origin());
if (verbose) {
dataLog(
"Adding Phi for ", pointerDump(stack), " at ", *block, ": ",
deepDump(proc, phi), "\n");
}
return phi;
});
// Now perform the conversion.
InsertionSet insertionSet(proc);
HashMap<StackSlotValue*, Value*> mapping;
for (BasicBlock* block : proc.blocksInPreOrder()) {
mapping.clear();
for (auto& entry : stackToVariable) {
StackSlotValue* stack = entry.key;
SSACalculator::Variable* variable = entry.value;
SSACalculator::Def* def = ssa.reachingDefAtHead(block, variable);
if (def)
mapping.set(stack, def->value());
}
for (SSACalculator::Def* phiDef : ssa.phisForBlock(block)) {
StackSlotValue* stack = variableToStack[phiDef->variable()->index()];
insertionSet.insertValue(0, phiDef->value());
mapping.set(stack, phiDef->value());
}
for (unsigned valueIndex = 0; valueIndex < block->size(); ++valueIndex) {
Value* value = block->at(valueIndex);
value->performSubstitution();
switch (value->opcode()) {
case Load: {
if (StackSlotValue* stack = value->child(0)->as<StackSlotValue>()) {
if (Value* replacement = mapping.get(stack))
value->replaceWithIdentity(replacement);
}
break;
}
case Store: {
if (StackSlotValue* stack = value->child(1)->as<StackSlotValue>()) {
示例14: GetDOIFromContentID
/*! \brief Get simple DOI identifier from full DOI content ID string.
\param contentID input, full DOI contentID string.
\param doi output, simple DOI identifier.
\returns Boolean indicating success or failure.
*/
bool OsmsOpenIPMPMessenger::GetDOIFromContentID(const std::string& contentID,
std::string& doiID) {
XMLDocument pIPMP_ContentId;
if (pIPMP_ContentId.decode(contentID.data(), "IPMP_ContentIdentity") == false) {
return false;
}
HashMap* identifier = pIPMP_ContentId.getDocList("Identifier");
if (identifier == 0) {
return false;
}
if (identifier->size() == 0) {
identifier->clear();
delete identifier;
return false;
}
XMLDocument* node = (XMLDocument*)identifier->first();
if (node == 0) {
for (int j = 1; j < identifier->size(); j++) {
node = (XMLDocument*)identifier->next();
if (node != 0) delete node;
}
identifier->clear();
delete identifier;
return false;
}
char* identifierType = node->getString("IdentifierType");
char* identifierValue = node->getString("IdentifierValue");
if ((identifierType == 0) || (identifierValue == 0)) {
delete node;
for (int j = 1; j < identifier->size(); j++) {
node = (XMLDocument*)identifier->next();
if (node != 0) delete node;
}
identifier->clear();
delete identifier;
return false;
}
if (strcmp(identifierType, "DOI") == 0) {
doiID = identifierValue;
delete[] identifierType;
delete[] identifierValue;
delete node;
for (int j = 1; j < identifier->size(); j++) {
node = (XMLDocument*)identifier->next();
if (node != 0) delete node;
}
identifier->clear();
delete identifier;
return true;
}
delete[] identifierType;
delete[] identifierValue;
delete node;
for (int i = 1; i < identifier->size(); i++) {
node = (XMLDocument*)identifier->next();
if (node == 0) {
for (int j = (i + 1); j < identifier->size(); j++) {
node = (XMLDocument*)identifier->next();
if (node != 0) delete node;
}
identifier->clear();
delete identifier;
return false;
}
char* identifierType = node->getString("IdentifierType");
char* identifierValue = node->getString("IdentifierValue");
if ((identifierType == 0) || (identifierValue == 0)) {
delete node;
for (int j = (i + 1); j < identifier->size(); j++) {
node = (XMLDocument*)identifier->next();
if (node != 0) delete node;
}
identifier->clear();
delete identifier;
return false;
}
if (strcmp(identifierType, "DOI") == 0) {
doiID = identifierValue;
delete[] identifierType;
delete[] identifierValue;
delete node;
for (int j = (i + 1); j < identifier->size(); j++) {
node = (XMLDocument*)identifier->next();
if (node != 0) delete node;
}
identifier->clear();
delete identifier;
return true;
}
delete[] identifierType;
delete[] identifierValue;
delete node;
//.........这里部分代码省略.........
示例15: _findBestSplitPoint
int FayyadMdlDiscretizer::_findBestSplitPoint(int start, int size, double& informationGain)
{
assert(start + size <= (int)_classes->size());
assert(start >= 0);
const std::vector<double>& values = *_values;
const std::vector<int>& classes = *_classes;
HashMap<int, int> frequency;
HashMap<int, int>::const_iterator it;
double log2 = log(2.0);
int cnt = 0;
for (int i = start; i < start + size; i++)
{
int seqClasses = 1;
it = frequency.find(classes[i]);
if (it == frequency.end())
{
frequency[classes[i]] = seqClasses;
}
else
{
int tmp = it->second;
frequency[classes[i]] = tmp + seqClasses;
}
cnt++;
double entropy = 0.0;
for (it = frequency.begin(); it != frequency.end(); it++)
{
double proportion = (double)it->second / (double)cnt;
entropy += proportion * log(proportion) / log2;
}
_entropyCacheUp[i] = -entropy;
}
cnt = 0;
frequency.clear();
for (int i = start + size - 1; i >= start; i--)
{
int seqClasses = 1;
it = frequency.find(classes[i]);
if (it == frequency.end())
{
frequency[classes[i]] = seqClasses;
}
else
{
int tmp = it->second;
frequency[classes[i]] = tmp + seqClasses;
}
cnt++;
double entropy = 0.0;
for (it = frequency.begin(); it != frequency.end(); it++)
{
double proportion = (double)it->second / (double)cnt;
entropy += proportion * log(proportion) / log2;
}
_entropyCacheDown[i] = -entropy;
}
double totalEntropy = _entropyCacheUp[start + size - 1];
int bestSplitPoint = -1;
double bestGain = -1.0;
int bestSmallSide = -1;
for (int i = start; i < start + size; i++)
{
// move on up to the next possible split point.
while (i < start + size - 1 && values[i] == values[i + 1])
{
i++;
}
double leftEnt = _entropyCacheUp[i];
double rightEnt = 0.0;
if (i < start + size - 1)
{
rightEnt = _entropyCacheDown[i + 1];
}
double leftSize = i - start + 1;
double rightSize = size - leftSize;
double gain = totalEntropy -
(rightEnt * rightSize / (double)size +
leftEnt * leftSize / (double)size);
int smallSide = (int)((leftSize < rightSize ? leftSize : rightSize) + .5);
// find the split with the most information gain and the most even split
if (gain > bestGain || (gain == bestGain && smallSide > bestSmallSide))
{
bestGain = gain;
bestSplitPoint = i;
bestSmallSide = smallSide;
}
}
informationGain = bestGain;
return bestSplitPoint;
//.........这里部分代码省略.........