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); }
void addAccessibilityNotificationHandler(AccessibilityNotificationHandler* notificationHandler) { if (!notificationHandler) return; #if PLATFORM(GTK) JSGlobalContextRef jsContext = webkit_web_frame_get_global_context(mainFrame); #else JSContextRef jsContext = 0; #endif if (!jsContext) return; JSValueProtect(jsContext, notificationHandler->notificationFunctionCallback()); // Check if this notification handler is related to a specific element. if (notificationHandler->platformElement()) { if (notificationHandlers.contains(notificationHandler->platformElement())) { JSValueUnprotect(jsContext, notificationHandlers.find(notificationHandler->platformElement())->value->notificationFunctionCallback()); notificationHandlers.remove(notificationHandler->platformElement()); } notificationHandlers.add(notificationHandler->platformElement(), notificationHandler); } else { if (notificationHandlers.contains(GlobalNotificationKey)) { JSValueUnprotect(jsContext, notificationHandlers.find(GlobalNotificationKey)->value->notificationFunctionCallback()); notificationHandlers.remove(GlobalNotificationKey); } notificationHandlers.add(GlobalNotificationKey, notificationHandler); } connectAccessibilityCallbacks(); }
int CountMaxContinusSequence(int a[], int n) { int maxLeng = 0; for (int i = 0; i < n; ++i) { // ignore duplicated elements if (hashMap.find(a[i]) != hashMap.end()) { continue; } hashMap.insert(std::make_pair(a[i], 1)); if (hashMap.find(a[i] - 1) != hashMap.end()) { maxLeng = Max(maxLeng, Merge(a[i] - 1, a[i])); } if (hashMap.find(a[i] + 1) != hashMap.end()) { maxLeng = Max(maxLeng, Merge(a[i], a[i] + 1)); } } return maxLeng; }
int main() { HashMap<unsigned long, string> hmap; hmap.insert(2, "Harsh"); string value; hmap.find(2, value); cout << value <<endl; cout <<"Hash table size is "<<hmap.size()<<endl; hmap.remove(2); hmap.find(2, value); cout <<"Hash table size is "<<hmap.size()<<endl; }
int Merge(int left, int right) { HashMap::iterator iterLeft = hashMap.find(left); HashMap::iterator iterRight = hashMap.find(right); int leftNum = left - iterLeft->second + 1; int rightNum = right - 1 + iterRight->second; const int length = rightNum - leftNum + 1; // update iterLeft->second = length; iterRight->second = length; return length; }
virtual void _Report_history(std::shared_ptr<library::XML> xml) { library::UniqueWriteLock uk(system_array_->getMutex()); //-------- // CONSTRUCT HISTORY //-------- std::shared_ptr<PRInvokeHistory> history(new PRInvokeHistory()); history->construct(xml); // IF THE HISTORY IS NOT EXIST IN PROGRESS, THEN TERMINATE REPORTING auto progress_it = progress_list_.find(history->getUID()); if (progress_it == progress_list_.end()) return; // ARCHIVE FIRST AND LAST INDEX history->first_ = std::dynamic_pointer_cast<PRInvokeHistory>(progress_it->second.second)->getFirst(); history->last_ = std::dynamic_pointer_cast<PRInvokeHistory>(progress_it->second.second)->getLast(); // ERASE FROM ORDINARY PROGRESS AND MIGRATE TO THE HISTORY progress_list_.erase(progress_it); history_list_.insert({ history->getUID(), history }); // NOTIFY TO THE MANAGER, SYSTEM_ARRAY ((base::ParallelSystemArrayBase*)system_array_)->_Complete_history(history); };
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); }
Ptr getMaxTree(const Arr<T>& data) { if (data.empty()) return nullptr; Arr<Ptr> node(data.size(), nullptr); for(int i = 0; i < data.size(); ++i) node[i] = std::make_shared<TreeNode>(data[i]); HashMap MaxMap; std::stack<Ptr> s; for (int i = 0; i < data.size(); ++i) { auto cur = node[i]; while (!s.empty() && s.top()->value < data[i]) { popStackSetMap(s, MaxMap, cur); } s.push(node[i]); } while (!s.empty()) { popStackSetMap(s, MaxMap, nullptr); } Ptr head = nullptr; for (int i = 0; i < node.size(); ++i) { auto cur = node[i]; auto res = MaxMap.find(cur); //结构如下 node left right //node是当前访问节点 left是左边离他最近比node大的点,right是右边。。 //nullptr代表没有或者到达边界 if (!res->second.first && !res->second.second) { head = res->first; } else if (!res->second.first) { if (!res->second.second->left) { res->second.second->left = res->first; } else { res->second.second->right = res->first; } } else if (!res->second.second) { if (!res->second.first->left) { res->second.first->left = res->first; } else { res->second.first->right = res->first; } } else { auto tmp = res->second.first->value < res->second.second->value ? res->second.first : res->second.second; if (!tmp->left) { tmp->left = res->first; } else { tmp->right = res->first; } } } return head; }
double FayyadMdlDiscretizer::_calculateEntropy(int start, int size) { assert(start + size <= (int)_classes->size()); assert(start >= 0); const std::vector<int>& classes = *_classes; HashMap<int, int> frequency; HashMap<int, int>::const_iterator it; for (int i = start; i < start + size; i++) { it = frequency.find(classes[i]); if (it == frequency.end()) { frequency[classes[i]] = 1; } else { int tmp = it->second; frequency[classes[i]] = tmp + 1; } } double entropy = 0.0; for (it = frequency.begin(); it != frequency.end(); it++) { double proportion = (double)it->second / (double)size; entropy += proportion * log(proportion) / log2; } return -entropy; }
static BOOL __stdcall CryptHashData_done(BOOL retval, HCRYPTHASH hHash, BYTE *pbData, DWORD dwDataLen, DWORD dwFlags) { DWORD err = GetLastError(); int ret_addr = *((DWORD *) ((DWORD) &retval - 4)); if (retval && !called_internally(ret_addr)) { HashMap::iterator iter; LOCK(); iter = hash_map.find(hHash); if (iter != hash_map.end()) { HashContext *ctx = iter->second; message_logger_log(_T("CryptHashData"), (char *) &retval - 4, ctx->get_id(), MESSAGE_TYPE_PACKET, MESSAGE_CTX_INFO, PACKET_DIRECTION_INVALID, NULL, NULL, (const char *) pbData, dwDataLen, _T("hHash=0x%p, Algid=%s"), hHash, ctx->get_alg_id_as_string()); } UNLOCK(); } SetLastError(err); return retval; }
static BOOL __stdcall CryptDestroyHash_done(BOOL retval, HCRYPTHASH hHash) { DWORD err = GetLastError(); int ret_addr = *((DWORD *) ((DWORD) &retval - 4)); if (retval) { LOCK(); HashMap::iterator iter = hash_map.find(hHash); if (iter != hash_map.end()) { HashContext *ctx = iter->second; if (!called_internally(ret_addr)) { message_logger_log(_T("CryptDestroyHash"), (char *) &retval - 4, ctx->get_id(), MESSAGE_TYPE_MESSAGE, MESSAGE_CTX_INFO, PACKET_DIRECTION_INVALID, NULL, NULL, NULL, 0, _T("hHash=0x%p"), hHash); } hash_map.erase(iter); delete ctx; } UNLOCK(); } SetLastError(err); return retval; }
int main(int argc, const char * argv[]) { // insert code here... vector<vector<int> > numbers = { {2, 4, 3, 6, 8, 10}, {10, 2, 1, 2, 0, 1}, {8, 4, 9, 6, 0, 1}, {8, 4, 3, 6, 8, 4}, {0, 9, 8, 7, 5, 2}, {9, 4, 3, 6, 8, 10}, {1, 4, 3, 6, 8, 10}, {2, 4, 3, 6, 8, 10}, {7, 4, 3, 6, 5, 2}}; int length = int(numbers.size()); for (int i = 0; i < length; ++i) { bool result = FindElement(numbers[i]); cout << "result: " << result << endl; } /********************test two*************************/ HashMap sample; vector<long> keys = {1, 2, 3, 4, 5, 6, 7, 8}; char a[16] = "test"; int length1 = int(keys.size()); for (int i = 0; i < length1; ++i) { sample.insert(keys[i], a); } Node *res = sample.find(1); cout << res->key << " " << res->value << endl; for (int i = 0; i < 32; i++) { int8_t a = static_cast<int8_t>( static_cast<int>((rand() / static_cast<float>(RAND_MAX)) * 255)); cout << a << endl; } return 0; }
void PannerNode::notifyAudioSourcesConnectedToNode(AudioNode* node, HashMap<AudioNode*, bool>& visitedNodes) { ASSERT(node); if (!node) return; // First check if this node is an AudioBufferSourceNode. If so, let it know about us so that doppler shift pitch can be taken into account. if (node->nodeType() == NodeTypeAudioBufferSource) { AudioBufferSourceNode* bufferSourceNode = static_cast<AudioBufferSourceNode*>(node); bufferSourceNode->setPannerNode(this); } else { // Go through all inputs to this node. for (unsigned i = 0; i < node->numberOfInputs(); ++i) { AudioNodeInput* input = node->input(i); // For each input, go through all of its connections, looking for AudioBufferSourceNodes. for (unsigned j = 0; j < input->numberOfRenderingConnections(); ++j) { AudioNodeOutput* connectedOutput = input->renderingOutput(j); AudioNode* connectedNode = connectedOutput->node(); HashMap<AudioNode*, bool>::iterator iterator = visitedNodes.find(connectedNode); // If we've seen this node already, we don't need to process it again. Otherwise, // mark it as visited and recurse through the node looking for sources. if (iterator == visitedNodes.end()) { visitedNodes.set(connectedNode, true); notifyAudioSourcesConnectedToNode(connectedNode, visitedNodes); // recurse } } } } }
static BOOL __stdcall CryptDuplicateHash_done(BOOL retval, HCRYPTHASH hHash, DWORD *pdwReserved, DWORD dwFlags, HCRYPTHASH *phHash) { DWORD err = GetLastError(); int ret_addr = *((DWORD *) ((DWORD) &retval - 4)); if (retval && !called_internally(ret_addr)) { HashMap::iterator iter; LOCK(); iter = hash_map.find(hHash); if (iter != hash_map.end()) { HashContext *ctx = iter->second; message_logger_log(_T("CryptDuplicateHash"), (char *) &retval - 4, ctx->get_id(), MESSAGE_TYPE_MESSAGE, MESSAGE_CTX_INFO, PACKET_DIRECTION_INVALID, NULL, NULL, NULL, 0, _T("hHash=0x%p, Algid=%s => *phHash=0x%p"), hHash, ctx->get_alg_id_as_string(), *phHash); } UNLOCK(); } SetLastError(err); return retval; }
static int certVerifyCallback(int ok, X509_STORE_CTX* ctx) { // whether the verification of the certificate in question was passed (preverify_ok=1) or not (preverify_ok=0) unsigned err = X509_STORE_CTX_get_error(ctx); if (!err) return 1; SSL* ssl = reinterpret_cast<SSL*>(X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx())); SSL_CTX* sslctx = SSL_get_SSL_CTX(ssl); ResourceHandle* job = reinterpret_cast<ResourceHandle*>(SSL_CTX_get_app_data(sslctx)); String host = job->firstRequest().url().host(); ResourceHandleInternal* d = job->getInternal(); d->m_sslErrors = sslCertificateFlag(err); #if PLATFORM(WIN) HashMap<String, ListHashSet<String>>::iterator it = allowedHosts.find(host); ok = (it != allowedHosts.end()); #else ListHashSet<String> certificates; if (!pemData(ctx, certificates)) return 0; ok = sslIgnoreHTTPSCertificate(host.lower(), certificates); #endif if (ok) { // if the host and the certificate are stored for the current handle that means is enabled, // so don't need to curl verifies the authenticity of the peer's certificate curl_easy_setopt(d->m_handle, CURLOPT_SSL_VERIFYPEER, false); } return ok; }
bool ProcessingInstruction::checkStyleSheet(String& href, String& charset) { if (m_target != "xml-stylesheet" || !document().frame() || parentNode() != document()) return false; // see http://www.w3.org/TR/xml-stylesheet/ // ### support stylesheet included in a fragment of this (or another) document // ### make sure this gets called when adding from javascript bool attrsOk; const HashMap<String, String> attrs = parseAttributes(m_data, attrsOk); if (!attrsOk) return false; HashMap<String, String>::const_iterator i = attrs.find("type"); String type; if (i != attrs.end()) type = i->value; m_isCSS = type.isEmpty() || type == "text/css"; m_isXSL = (type == "text/xml" || type == "text/xsl" || type == "application/xml" || type == "application/xhtml+xml" || type == "application/rss+xml" || type == "application/atom+xml"); if (!m_isCSS && !m_isXSL) return false; href = attrs.get("href"); charset = attrs.get("charset"); String alternate = attrs.get("alternate"); m_alternate = alternate == "yes"; m_title = attrs.get("title"); m_media = attrs.get("media"); return !m_alternate || !m_title.isEmpty(); }
CSSSelector::PseudoType CSSSelector::parsePseudoType(const AtomicString& name) { if (name.isNull()) return PseudoUnknown; HashMap<AtomicStringImpl*, CSSSelector::PseudoType>* nameToPseudoType = nameToPseudoTypeMap(); HashMap<AtomicStringImpl*, CSSSelector::PseudoType>::iterator slot = nameToPseudoType->find(name.impl()); return slot == nameToPseudoType->end() ? PseudoUnknown : slot->second; }
static BOOL __stdcall CryptGetHashParam_done (BOOL retval, HCRYPTHASH hHash, DWORD dwParam, BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags) { DWORD err = GetLastError(); int ret_addr = *((DWORD *) ((DWORD) &retval - 4)); if (retval && !called_internally(ret_addr)) { HashMap::iterator iter; LOCK(); iter = hash_map.find(hHash); if (iter != hash_map.end()) { HashContext *ctx = iter->second; const TCHAR *param_str; switch (dwParam) { case HP_ALGID: param_str = _T("ALGID"); break; case HP_HASHSIZE: param_str = _T("HASHSIZE"); break; case HP_HASHVAL: param_str = _T("HASHVAL"); break; default: param_str = _T("UNKNOWN"); break; } message_logger_log(_T("CryptGetHashParam"), (char *) &retval - 4, ctx->get_id(), MESSAGE_TYPE_PACKET, MESSAGE_CTX_INFO, PACKET_DIRECTION_INVALID, NULL, NULL, (const char *) pbData, *pdwDataLen, _T("hHash=0x%p, Algid=%s, dwParam=%s"), hHash, ctx->get_alg_id_as_string(), param_str); } UNLOCK(); } SetLastError(err); return retval; }
static bool isAxisName(const String& name, Step::Axis& type) { static HashMap<String, Step::Axis> axisNames; if (axisNames.isEmpty()) setUpAxisNamesMap(axisNames); HashMap<String, Step::Axis>::iterator it = axisNames.find(name); if (it == axisNames.end()) return false; type = it->second; return true; }
void setSSLClientCertificate(ResourceHandle* handle) { String host = handle->firstRequest().url().host(); HashMap<String, clientCertificate>::iterator it = allowedClientHosts.find(host.lower()); if (it == allowedClientHosts.end()) return; ResourceHandleInternal* d = handle->getInternal(); clientCertificate clientInfo = it->value; curl_easy_setopt(d->m_handle, CURLOPT_SSLCERT, std::get<0>(clientInfo).utf8().data()); curl_easy_setopt(d->m_handle, CURLOPT_SSLCERTTYPE, "P12"); curl_easy_setopt(d->m_handle, CURLOPT_SSLCERTPASSWD, std::get<1>(clientInfo).utf8().data()); }
static String cachedStorageDirectory(DWORD pathIdentifier) { static HashMap<DWORD, String> directories; HashMap<DWORD, String>::iterator it = directories.find(pathIdentifier); if (it != directories.end()) return it->second; String directory = storageDirectory(pathIdentifier); directories.add(pathIdentifier, directory); return directory; }
DataObjectGtk* DataObjectGtk::forClipboard(GtkClipboard* clipboard) { static HashMap<GtkClipboard*, RefPtr<DataObjectGtk> > objectMap; if (!objectMap.contains(clipboard)) { RefPtr<DataObjectGtk> dataObject = DataObjectGtk::create(); objectMap.set(clipboard, dataObject); return dataObject.get(); } HashMap<GtkClipboard*, RefPtr<DataObjectGtk> >::iterator it = objectMap.find(clipboard); return it->value.get(); }
bool canMatch(const char* head, const char * end, HashMap & flags, int l){ if (head == end+1) return true; string s=""; for (int i=0; i<l; i++) s+= *(head+i); HashMap::iterator hi = flags.find(s); if (hi==flags.end() || hi->second<=0) return false; flags[s]--; bool rlt = canMatch(head+l,end,flags,l); flags[s]++; return rlt; }
inline void CalculationValueMap::deref(unsigned handle) { ASSERT(m_map.contains(handle)); auto it = m_map.find(handle); if (it->value.referenceCountMinusOne) { --it->value.referenceCountMinusOne; return; } // The adoptRef here is balanced by the leakRef in the insert member function. Ref<CalculationValue> value { adoptRef(*it->value.value) }; m_map.remove(it); }
virtual void _Reply_data(std::shared_ptr<protocol::Invoke> invoke) override { if (invoke->getListener() == "_Report_history") _Report_history(invoke->front()->getValueAsXML()); else if (invoke->getListener() == "_Send_back_history") { size_t uid = invoke->front()->getValue<size_t>(); auto it = progress_list_.find(uid); if (it != progress_list_.end()) _Send_back_history(it->second.first, it->second.second); } else replyData(invoke); };
int main(int argc, const char * argv[]) { // insert code here... HashMap sample; vector<long> keys = {1, 2, 3, 4, 5, 6, 7, 8}; char a[16] = "test"; int length1 = int(keys.size()); for (int i = 0; i < length1; ++i) { sample.insert(keys[i], a); } Node *res = sample.find(1); cout << res->key << " " << res->value << endl; return 0; }
CSSSelector::PseudoType CSSSelector::parsePseudoType(const AtomicString& name) { if (name.isNull()) return PseudoUnknown; HashMap<AtomicStringImpl*, CSSSelector::PseudoType>* nameToPseudoType = nameToPseudoTypeMap(); HashMap<AtomicStringImpl*, CSSSelector::PseudoType>::iterator slot = nameToPseudoType->find(name.impl()); if (slot != nameToPseudoType->end()) return slot->value; if (name.startsWith("-webkit-")) return PseudoWebKitCustomElement; if (name.startsWith("x-") || name.startsWith("cue")) return PseudoUserAgentCustomElement; return PseudoUnknown; }
const Element* Element::get(const String& symbol) { static HashMap<String, const Element*> elements; if (elements.empty()) { for (Index i = 0; i < ARRAY_LENGTH(ELEMENT_DATA); ++i) { elements[ELEMENT_DATA[i].symbol] = ELEMENT_DATA+i; } elements[ELEMENT_D.symbol] = &ELEMENT_D; elements[ELEMENT_T.symbol] = &ELEMENT_T; } HashMap<String, const Element*>::const_iterator it = elements.find(symbol); if (it != elements.end()) { return it->second; } else { return NULL; } }
bool MeshSerializerTests::isHashMapClone(const HashMap<K, V>& a, const HashMap<K, V>& b) { // if you recreate a HashMap with same elements, then iteration order may differ! // So isContainerClone is not always working on HashMap. if (a.size() != b.size()) { return false; } typename HashMap<K, V>::const_iterator it, itFind, itEnd; it = a.begin(); itEnd = a.end(); for (; it != itEnd; it++) { itFind = b.find(it->first); if (itFind == b.end() || itFind->second != it->second) { return false; } } return true; }
void TypeSet::removeDuplicatesInStructureHistory() { Vector<RefPtr<StructureShape>>* newHistory = new Vector<RefPtr<StructureShape>>; HashMap<String, bool> container; for (size_t i = 0; i < m_structureHistory->size(); i++) { RefPtr<StructureShape> a = m_structureHistory->at(i); String hash = a->propertyHash(); auto iter = container.find(hash); if (iter == container.end()) { container.add(hash, true); newHistory->append(a); } } delete m_structureHistory; m_structureHistory = newHistory; m_mightHaveDuplicatesInStructureHistory = false; }