本文整理汇总了C++中HashMap::add方法的典型用法代码示例。如果您正苦于以下问题:C++ HashMap::add方法的具体用法?C++ HashMap::add怎么用?C++ HashMap::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashMap
的用法示例。
在下文中一共展示了HashMap::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setInstance
void WebPreferences::setInstance(WebPreferences* instance, BSTR identifier)
{
if (!identifier || !instance)
return;
WTF::String identifierString(identifier, SysStringLen(identifier));
webPreferencesInstances.add(identifierString, instance);
}
示例2: testMapMove
static void testMapMove()
{
// Add 1000..1999 to a HashMap.
HashMap<Uptr, Uptr> a;
for(Uptr i = 0;i < 1000;++i)
{
a.add(i + 1000, i);
}
// Move the map to a new HashMap.
HashMap<Uptr, Uptr> b {std::move(a)};
// Test that the new HashMap contains the expected numbers.
for(Uptr i = 0;i < 1000;++i)
{
errorUnless(!b.get(i));
errorUnless(*b.get(i + 1000) == i);
errorUnless(!b.get(i + 2000));
}
// Test moving the map to itself.
b = std::move(b);
// Test that the map wasn't changed by the move-to-self.
for(Uptr i = 0;i < 1000;++i)
{
errorUnless(!b.get(i));
errorUnless(*b.get(i + 1000) == i);
errorUnless(!b.get(i + 2000));
}
}
示例3:
static NEVER_INLINE void populateCSSPropertyWithSVGDOMNameToAnimatedPropertyTypeMap(HashMap<QualifiedName::QualifiedNameImpl*, AnimatedPropertyType>& map)
{
using namespace HTMLNames;
using namespace SVGNames;
struct TableEntry {
const QualifiedName& attributeName;
AnimatedPropertyType type;
};
static const TableEntry table[] = {
{ cxAttr, AnimatedLength },
{ cyAttr, AnimatedLength },
{ rAttr, AnimatedLength },
{ rxAttr, AnimatedLength },
{ ryAttr, AnimatedLength },
{ SVGNames::heightAttr, AnimatedLength },
{ SVGNames::widthAttr, AnimatedLength },
{ xAttr, AnimatedLength },
{ yAttr, AnimatedLength },
};
for (auto& entry : table)
map.add(entry.attributeName.impl(), entry.type);
}
示例4:
TEST(TestHashMapRemove, addedItemThenRemoveItemHashMapShouldHave0items)
{
HashMap Test;
Test.add("Ford", "Tang");
Test.remove("Ford");
ASSERT_EQ(0, Test.size());
}
示例5: makeIndexWriters
bool IDBObjectStoreBackendLevelDB::makeIndexWriters(PassRefPtr<IDBTransactionBackendLevelDB> transaction, IDBBackingStore* backingStore, int64_t databaseId, const IDBObjectStoreMetadata& objectStore, PassRefPtr<IDBKey> primaryKey, bool keyWasGenerated, const Vector<int64_t>& indexIds, const Vector<IDBDatabaseBackendInterface::IndexKeys>& indexKeys, Vector<OwnPtr<IndexWriter> >* indexWriters, String* errorMessage, bool& completed)
{
ASSERT(indexIds.size() == indexKeys.size());
completed = false;
HashMap<int64_t, IDBDatabaseBackendInterface::IndexKeys> indexKeyMap;
for (size_t i = 0; i < indexIds.size(); ++i)
indexKeyMap.add(indexIds[i], indexKeys[i]);
for (IDBObjectStoreMetadata::IndexMap::const_iterator it = objectStore.indexes.begin(); it != objectStore.indexes.end(); ++it) {
const IDBIndexMetadata& index = it->value;
IDBDatabaseBackendInterface::IndexKeys keys = indexKeyMap.get(it->key);
// If the objectStore is using autoIncrement, then any indexes with an identical keyPath need to also use the primary (generated) key as a key.
if (keyWasGenerated && (index.keyPath == objectStore.keyPath))
keys.append(primaryKey);
OwnPtr<IndexWriter> indexWriter(adoptPtr(new IndexWriter(index, keys)));
bool canAddKeys = false;
bool backingStoreSuccess = indexWriter->verifyIndexKeys(*backingStore, transaction->backingStoreTransaction(), databaseId, objectStore.id, index.id, canAddKeys, primaryKey.get(), errorMessage);
if (!backingStoreSuccess)
return false;
if (!canAddKeys)
return true;
indexWriters->append(indexWriter.release());
}
completed = true;
return true;
}
示例6: recalcTreeState
void HTMLImport::recalcTreeState(HTMLImport* root)
{
HashMap<RawPtr<HTMLImport>, HTMLImportState> snapshot;
Vector<RawPtr<HTMLImport> > updated;
for (HTMLImport* i = root; i; i = traverseNext(i)) {
snapshot.add(i, i->state());
i->m_state = HTMLImportState::invalidState();
}
// The post-visit DFS order matters here because
// HTMLImportStateResolver in recalcState() Depends on
// |m_state| of its children and precedents of ancestors.
// Accidental cycle dependency of state computation is prevented
// by invalidateCachedState() and isStateCacheValid() check.
for (HTMLImport* i = traverseFirstPostOrder(root); i; i = traverseNextPostOrder(i)) {
ASSERT(!i->m_state.isValid());
i->m_state = HTMLImportStateResolver(i).resolve();
HTMLImportState newState = i->state();
HTMLImportState oldState = snapshot.get(i);
// Once the state reaches Ready, it shouldn't go back.
ASSERT(!oldState.isReady() || oldState <= newState);
if (newState != oldState)
updated.append(i);
}
for (size_t i = 0; i < updated.size(); ++i)
updated[i]->stateDidChange();
}
示例7: providerDidCloseNotifications
void WebNotificationManagerProxy::providerDidCloseNotifications(API::Array* globalNotificationIDs)
{
HashMap<WebPageProxy*, Vector<uint64_t>> pageNotificationIDs;
size_t size = globalNotificationIDs->size();
for (size_t i = 0; i < size; ++i) {
auto it = m_globalNotificationMap.find(globalNotificationIDs->at<API::UInt64>(i)->value());
if (it == m_globalNotificationMap.end())
continue;
if (WebPageProxy* webPage = WebProcessProxy::webPage(it->value.first)) {
auto pageIt = pageNotificationIDs.find(webPage);
if (pageIt == pageNotificationIDs.end()) {
Vector<uint64_t> newVector;
newVector.reserveInitialCapacity(size);
pageIt = pageNotificationIDs.add(webPage, WTF::move(newVector)).iterator;
}
uint64_t pageNotificationID = it->value.second;
pageIt->value.append(pageNotificationID);
}
m_notifications.remove(it->value);
m_globalNotificationMap.remove(it);
}
for (auto it = pageNotificationIDs.begin(), end = pageNotificationIDs.end(); it != end; ++it)
it->key->process().send(Messages::WebNotificationManager::DidCloseNotifications(it->value), 0);
}
示例8: dispatchWillSubmitForm
void WebFrameLoaderClient::dispatchWillSubmitForm(PassRefPtr<FormState> formState, FramePolicyFunction function)
{
WebView* webView = m_webFrame->webView();
Frame* coreFrame = core(m_webFrame);
ASSERT(coreFrame);
COMPtr<IWebFormDelegate> formDelegate;
if (FAILED(webView->formDelegate(&formDelegate))) {
function(PolicyUse);
return;
}
COMPtr<IDOMElement> formElement(AdoptCOM, DOMElement::createInstance(formState->form()));
HashMap<String, String> formValuesMap;
const StringPairVector& textFieldValues = formState->textFieldValues();
size_t size = textFieldValues.size();
for (size_t i = 0; i < size; ++i)
formValuesMap.add(textFieldValues[i].first, textFieldValues[i].second);
COMPtr<IPropertyBag> formValuesPropertyBag(AdoptCOM, COMPropertyBag<String>::createInstance(formValuesMap));
COMPtr<WebFrame> sourceFrame(kit(formState->sourceDocument()->frame()));
if (SUCCEEDED(formDelegate->willSubmitForm(m_webFrame, sourceFrame.get(), formElement.get(), formValuesPropertyBag.get(), setUpPolicyListener(function).get())))
return;
// FIXME: Add a sane default implementation
function(PolicyUse);
}
示例9: calculateTreeScopePrePostOrderNumbers
void EventPath::calculateTreeScopePrePostOrderNumbers()
{
// Precondition:
// - TreeScopes in m_treeScopeEventContexts must be *connected* in the same tree of trees.
// - The root tree must be included.
HashMap<const TreeScope*, TreeScopeEventContext*> treeScopeEventContextMap;
for (size_t i = 0; i < m_treeScopeEventContexts.size(); ++i)
treeScopeEventContextMap.add(&m_treeScopeEventContexts[i]->treeScope(), m_treeScopeEventContexts[i].get());
TreeScopeEventContext* rootTree = 0;
for (size_t i = 0; i < m_treeScopeEventContexts.size(); ++i) {
TreeScopeEventContext* treeScopeEventContext = m_treeScopeEventContexts[i].get();
// Use olderShadowRootOrParentTreeScope here for parent-child relationships.
// See the definition of trees of trees in the Shado DOM spec: http://w3c.github.io/webcomponents/spec/shadow/
TreeScope* parent = treeScopeEventContext->treeScope().olderShadowRootOrParentTreeScope();
if (!parent) {
ASSERT(!rootTree);
rootTree = treeScopeEventContext;
continue;
}
ASSERT(treeScopeEventContextMap.find(parent) != treeScopeEventContextMap.end());
treeScopeEventContextMap.find(parent)->value->addChild(*treeScopeEventContext);
}
ASSERT(rootTree);
rootTree->calculatePrePostOrderNumber(0);
}
示例10: updateDatabase
void LocalStorageDatabase::updateDatabase()
{
if (m_isClosed)
return;
ASSERT(m_didScheduleDatabaseUpdate);
m_didScheduleDatabaseUpdate = false;
HashMap<String, String> changedItems;
if (m_changedItems.size() <= maximumItemsToUpdate) {
// There are few enough changed items that we can just always write all of them.
m_changedItems.swap(changedItems);
updateDatabaseWithChangedItems(changedItems);
m_disableSuddenTerminationWhileWritingToLocalStorage = nullptr;
} else {
for (int i = 0; i < maximumItemsToUpdate; ++i) {
auto it = m_changedItems.begin();
changedItems.add(it->key, it->value);
m_changedItems.remove(it);
}
ASSERT(changedItems.size() <= maximumItemsToUpdate);
// Reschedule the update for the remaining items.
scheduleDatabaseUpdate();
updateDatabaseWithChangedItems(changedItems);
}
}
示例11: prune
void AvailabilityMap::prune()
{
if (m_heap.isEmpty())
return;
HashSet<Node*> possibleNodes;
for (unsigned i = m_locals.size(); i--;) {
if (m_locals[i].hasNode())
possibleNodes.add(m_locals[i].node());
}
int oldPossibleNodesSize;
do {
oldPossibleNodesSize = possibleNodes.size();
for (auto pair : m_heap) {
if (pair.value.hasNode() && possibleNodes.contains(pair.key.base()))
possibleNodes.add(pair.value.node());
}
} while (oldPossibleNodesSize != possibleNodes.size());
HashMap<PromotedHeapLocation, Availability> newHeap;
for (auto pair : m_heap) {
if (possibleNodes.contains(pair.key.base()))
newHeap.add(pair.key, pair.value);
}
m_heap = newHeap;
}
示例12: findGoodTouchTargets
void findGoodTouchTargets(const IntRect& touchBox, LocalFrame* mainFrame, Vector<IntRect>& goodTargets, Vector<Node*>& highlightNodes)
{
goodTargets.clear();
int touchPointPadding = ceil(max(touchBox.width(), touchBox.height()) * 0.5);
IntPoint touchPoint = touchBox.center();
IntPoint contentsPoint = mainFrame->view()->windowToContents(touchPoint);
HitTestResult result = mainFrame->eventHandler().hitTestResultAtPoint(contentsPoint, HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::ConfusingAndOftenMisusedDisallowShadowContent, IntSize(touchPointPadding, touchPointPadding));
const ListHashSet<RefPtr<Node> >& hitResults = result.rectBasedTestResult();
// Blacklist nodes that are container of disambiguated nodes.
// It is not uncommon to have a clickable <div> that contains other clickable objects.
// This heuristic avoids excessive disambiguation in that case.
HashSet<Node*> blackList;
for (ListHashSet<RefPtr<Node> >::const_iterator it = hitResults.begin(); it != hitResults.end(); ++it) {
// Ignore any Nodes that can't be clicked on.
RenderObject* renderer = it->get()->renderer();
if (!renderer || !it->get()->willRespondToMouseClickEvents())
continue;
// Blacklist all of the Node's containers.
for (RenderBlock* container = renderer->containingBlock(); container; container = container->containingBlock()) {
Node* containerNode = container->node();
if (!containerNode)
continue;
if (!blackList.add(containerNode).isNewEntry)
break;
}
}
HashMap<Node*, TouchTargetData> touchTargets;
float bestScore = 0;
for (ListHashSet<RefPtr<Node> >::const_iterator it = hitResults.begin(); it != hitResults.end(); ++it) {
for (Node* node = it->get(); node; node = node->parentNode()) {
if (blackList.contains(node))
continue;
if (node->isDocumentNode() || isHTMLHtmlElement(*node) || isHTMLBodyElement(*node))
break;
if (node->willRespondToMouseClickEvents()) {
TouchTargetData& targetData = touchTargets.add(node, TouchTargetData()).storedValue->value;
targetData.windowBoundingBox = boundingBoxForEventNodes(node);
targetData.score = scoreTouchTarget(touchPoint, touchPointPadding, targetData.windowBoundingBox);
bestScore = max(bestScore, targetData.score);
break;
}
}
}
for (HashMap<Node*, TouchTargetData>::iterator it = touchTargets.begin(); it != touchTargets.end(); ++it) {
// Currently the scoring function uses the overlap area with the fat point as the score.
// We ignore the candidates that has less than 1/2 overlap (we consider not really ambiguous enough) than the best candidate to avoid excessive popups.
if (it->value.score < bestScore * 0.5)
continue;
goodTargets.append(it->value.windowBoundingBox);
highlightNodes.append(it->key);
}
}
示例13: writeString
void BinaryPropertyListPlan::writeString(const String& string)
{
++m_currentAggregateSize;
if (!m_strings.add(string, m_currentObjectReference).isNewEntry)
return;
++m_currentObjectReference;
writeStringObject(string);
}
示例14: scanDirectoryForDicionaries
static void scanDirectoryForDicionaries(const char* directoryPath, HashMap<AtomicString, Vector<String>>& availableLocales)
{
for (const auto& filePath : listDirectory(directoryPath, "hyph_*.dic")) {
String locale = extractLocaleFromDictionaryFilePath(filePath).convertToASCIILowercase();
availableLocales.add(locale, Vector<String>()).iterator->value.append(filePath);
String localeReplacingUnderscores = String(locale);
localeReplacingUnderscores.replace('_', '-');
if (locale != localeReplacingUnderscores)
availableLocales.add(localeReplacingUnderscores, Vector<String>()).iterator->value.append(filePath);
size_t dividerPosition = localeReplacingUnderscores.find('-');
if (dividerPosition != notFound) {
localeReplacingUnderscores.truncate(dividerPosition);
availableLocales.add(localeReplacingUnderscores, Vector<String>()).iterator->value.append(filePath);
}
}
}
示例15: 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());
}