TxId DatabaseHelper::txGetId(const Hash256& txHash, bool allowInvalid) { TxId txHashIndex; boost::lock_guard<boost::recursive_mutex> guard(cacheMutex); if (txCache.exists(txHash)) { txHashIndex = txCache.get(txHash); } else { auto buffer = bufferTLS.get(); if (buffer == NULL) { bufferTLS.reset(buffer = new std::string()); } DbTxHashToIdKey searchKey(txHash); if (!db->Get(leveldb::ReadOptions(), leveldb::Slice((const char*)&searchKey, sizeof(searchKey)), buffer).ok()) { if (!allowInvalid) assert("Unknown transaction hash => ID mapping"); return 0xFFFFFFFF; } txHashIndex = *(TxId*) buffer->c_str(); txCache.put(txHash, txHashIndex); txCache2.put(txHashIndex, txHash); } return txHashIndex; }
/* * Method: * bool BTree::exists(unsigned long key) const * * Purpose: * Checks if the given key exists in the BTree. * * Input: * key, key to be searched * * Output: * true, if the key exists * false, otherwise */ bool BTree::exists(unsigned long key) const { Btree_Node* pNode=NULL; int idx; searchKey(key,&pNode,&idx); return NULL!=pNode; }
comp_dict_item_t *insertKey(comp_dict_t *dict, char *key, int valueType, int line) { comp_dict_item_t *item; item = searchKey(*dict, key); if (item != NULL){ return item;//key already exists } comp_dict_node_t *newNode; unsigned int hashValue = hashFunction(dict->numberOfLists, key); newNode = malloc(sizeof(comp_dict_node_t)); if (newNode == NULL) return NULL;//couldnt alloc newNode->item = malloc(sizeof(comp_dict_item_t)); if (newNode->item == NULL) return NULL;//couldnt alloc newNode->item->key = strdup(key);//store key newNode->item->valueType = valueType;//store value type //initialize value (only literals have a valid value) and number of bytes if(valueType == IKS_STRING){ //cut string's double quotes newNode->item->stringValue = strdup(key); newNode->item->stringValue[0] = ' '; newNode->item->stringValue[strlen(key) - 1] = ' '; newNode->item->numBytes = 4; } if(valueType == IKS_CHAR){ newNode->item->charValue = key[1];//cut char's single quotes newNode->item->numBytes = 1; } if(valueType == IKS_INT){ newNode->item->intValue = atoi(key); newNode->item->numBytes = 4; } if(valueType == IKS_FLOAT){ newNode->item->floatValue = atof(key); newNode->item->numBytes = 8; } if(valueType == IKS_BOOL){ newNode->item->boolValue = (strcmp(key, "true") == 0 ? 1: 0); newNode->item->numBytes = 1; } if(valueType == IKS_UNDEFINED){ newNode->item->floatValue = 0; newNode->item->numBytes = 0; } newNode->item->nodeType = IKS_UNDEFINED_ITEM;//initialize node type newNode->item->line = line;//store line newNode->item->functionSymbolTable = NULL;//initialize function symbol table newNode->item->parametersList = NULL;//initialize parameters list createList(&(newNode->item->dimensionList));//initialize dimensions list createList(&(newNode->item->localVars));//initialize local vars list newNode->next = dict->table[hashValue]; dict->table[hashValue] = newNode; dict->numberOfElements++; return newNode->item; }
/* * Method: * unsigned long BTree::findVal(unsigned long key) const * * Purpose: * Searches for a value associated with the given key. * Throws an exception if the key does not exist. * * Input: * key, key to be searched * * Output: * val associated with the key */ unsigned long BTree::findVal(unsigned long key) const { Btree_Node* pNode=NULL; int Index; searchKey(key,&pNode,&Index); if( NULL==pNode ) throw "BTree::findVal, key does not exist"; return (pNode->pair)[Index].val; }
SkPathHeap::LookupEntry* SkPathHeap::addIfNotPresent(const SkPath& path) { LookupEntry searchKey(path); int index = SkTSearch<const LookupEntry, LookupEntry::Less>( fLookupTable.begin(), fLookupTable.count(), searchKey, sizeof(LookupEntry)); if (index < 0) { index = ~index; *fLookupTable.insert(index) = LookupEntry(path); } return &fLookupTable[index];; }
STDMETHODIMP CVolatilityManagement::OnVMESurface(/*[in]*/IDispatch* Symbol, /*[in]*/IDispatch* Data) { ObjectLock lock(this); IVMESurfacePtr spData = Data; if (spData) { CSurfaceKey searchKey(spData->SurfaceID, static_cast<EOptType>(spData->OptType)); CSurfaceMap::iterator itrSurface = m_surfaces.find(searchKey); if ( itrSurface != m_surfaces.end() ) { itrSurface->second->OnVMESurface(Symbol, Data ); } } return S_OK; }
void ShortcutManager::onButtonDown(const ButtonEvent& event) { UINT32 modifiers = 0; if (Input::instance().isButtonHeld(BC_LSHIFT) || Input::instance().isButtonHeld(BC_RSHIFT)) modifiers |= (UINT32)ButtonModifier::Shift; if (Input::instance().isButtonHeld(BC_LCONTROL) || Input::instance().isButtonHeld(BC_RCONTROL)) modifiers |= (UINT32)ButtonModifier::Ctrl; if (Input::instance().isButtonHeld(BC_LMENU) || Input::instance().isButtonHeld(BC_RMENU)) modifiers |= (UINT32)ButtonModifier::Alt; ShortcutKey searchKey((ButtonModifier)modifiers, event.buttonCode); auto iterFind = mShortcuts.find(searchKey); if (iterFind != mShortcuts.end()) { if (iterFind->second != nullptr) iterFind->second(); } }
/* * Method: * bool BTree::remove(unsigned long key) * * Purpose: * Deletes from the tree a node with the given key, if any * * Input: * key, the key to be removed * * Output: * true, removal succeeded (key existed) * fales, key did not exist */ bool BTree::remove(unsigned long key) { Btree_Node* pLeaf; int idx; // find the node to be deleted Btree_Node* pNode=NULL; searchKey(key,&pNode,&idx); if( NULL == pNode ) // the tree does not carry a key iKey return false; //we do a trick so as to ensure that we delete from a leaf: //if we are not deleting from a leaf, then we find the successor //of iKey, this successor is guaranteed to be located at a leaf, //then we copy the successor the place where iKey is, //this copying preserves the properties of B-tree, //and it deletes iKey (by overwriting iKey), //but creates a duplicate of the successor, //so we will need to delete the original successor (located at a leaf, as desired) if( NULL != (pNode->child)[0] ) { // pNode is not a leaf // go to the child on the right of the key // and then descend along first child pLeaf = (pNode->child)[idx+1]; while( NULL != (pLeaf->child)[0] ) pLeaf = (pLeaf->child)[0]; (pNode->pair)[idx] = (pLeaf->pair)[0]; // change which key is to be deleted pNode = pLeaf; idx = 0; }; // now we know that pNode is a leaf, and we must delete a key with index i removeAtLeaf(pNode,idx); return true; }
/************************************************************************************** * Function Name: findKey * * Description: * Get the RID the search key in given B+ Tree * If not exist, return RC_IM_KEY_NOT_FOUND * * Parameters: * BTreeHandle *tree: Entry to the B+ Tree * Value *key: search key * RID *result: the RID for the key we found * * Return: * RC: return code * * Author: * Xiaolang Wang <*****@*****.**> * * History: * Date Name Content * ---------- ---------------------------------------- ------------------------ * 2015-04-27 Xiaolang Wang <*****@*****.**> Initialization. **************************************************************************************/ RC findKey(BTreeHandle *tree, Value *key, RID *result) { RC rc; // get root page PageNumber rootPage; rc = -99; rc = getRootPage(tree, &rootPage); if (rc != RC_OK) { return rc; } BT_KeyPosition *kp; rc = -99; rc = searchKey(tree, key, result, kp); if (rc != RC_OK) { return rc; } return RC_OK; }
void ACDCallManager::updateTransferCallState(SIPX_CALLSTATE_INFO* pCallInfo) { SIPX_CALL hCallHandle = SIPX_CALL_NULL; SIPX_CALL hAssociatedCallHandle; int callEvent; int callCause; const char* remUri; char userUri[512]; ACDCall* pCallRef; mLock.acquire(); // Extract the call handle and state info hAssociatedCallHandle = pCallInfo->hAssociatedCall; callEvent = pCallInfo->event; callCause = pCallInfo->cause; remUri = pCallInfo->remoteAddress; /** * For the NEWCALL_TRANSFER event - find the ACDCall object instance * on the basis of the Associated call handle (from the older leg). */ if (pCallInfo->cause == CALLSTATE_NEW_CALL_TRANSFER) { if (TRUE == validateTransferToLine(pCallInfo)) { // Don't allow agents to transfer calls INTO the acd. It screws // things up. The correct behavior would be to move the call // the agent is currently handling into a new queue, but due to // the inability to remove calls from a conference, this just doesn't // work. Hangup on the transfer attempt. Ths should leave // caller and agent connected. OsSysLog::add(FAC_ACD, PRI_WARNING, "ACDCallManager::updateTransferCallState - " "CALLSTATE_OFFERING::%d to the ACD Line REJECTED", pCallInfo->cause); sipxCallReject(pCallInfo->hCall, SIP_BAD_REQUEST_CODE, "Agent Transfer Loop Rejected"); return ; } // not an agent transferring into the acd hCallHandle = hAssociatedCallHandle; UtlInt callKey(hCallHandle); pCallRef = dynamic_cast<ACDCall*>(mAgentCallHandleMap.findValue(&callKey)); } else // not new call transfer { UtlInt searchKey(pCallInfo->hCall); pCallRef = dynamic_cast<ACDCall*>(mTransferCallHandleMap.findValue(&searchKey)); } if (pCallRef != NULL) { if (callCause == CALLSTATE_NEW_CALL_TRANSFER) { addMapTransferAgentCallHandleToCall(pCallInfo->hCall, pCallRef); pCallRef->mFlagTransfer = TRUE; // only set TRUE here. } if ( (callCause == CALLSTATE_REMOTE_OFFERING_NORMAL) && (pCallRef->mFlagTransfer == TRUE)) { UtlString userId, hostAddress; Url remoteUrl(remUri); remoteUrl.getUserId(userId); remoteUrl.getHostAddress(hostAddress); if (remUri) { // Now find the agent for this remUri sprintf(userUri,"sip:%s@%s",userId.data(),hostAddress.data()); UtlString agentUri(userUri); ACDAgent* pAgentRef = mpAcdServer->getAcdAgentManager()->getAcdAgentReference(agentUri); if (!pAgentRef) { OsSysLog::add(FAC_ACD, gACD_DEBUG, "ACDCallManager::updateTransferCallState - " "Failed to find Agent. This is probably an agent that is not signed in: " "call(%d), TransferAgentCall(%d), agentUri(%s)", pCallRef->getCallHandle(), pCallInfo->hCall, agentUri.data()); // A non registered agent is not yet supported - so do not try ! pAgentRef = mpAcdServer->getAcdAgentManager()->createACDAgent(userUri, "dummy", "", FALSE, FALSE, NULL, TRUE); if (!pAgentRef) { assert(0); } } //set the mhCallHandle of the Agent object pAgentRef->setCallHandle(pCallInfo->hCall); // set the transfer agent object in the call object pCallRef->mpTransferAgent = pAgentRef; OsSysLog::add(FAC_ACD, gACD_DEBUG, "ACDCallManager::updateTransferCallState - " "success in finding Agent: call(%d), TransferAgentCall(%d) AgentUri(%s)", pCallRef->getCallHandle(), pCallInfo->hCall, pAgentRef->getUriString()->data()); } } if ( (callCause == CALLSTATE_REMOTE_OFFERING_NORMAL) && (pCallRef->mFlagTransfer == FALSE)) { ; // do nothing } else { pCallRef->updateState(hCallHandle, callEvent, callCause); } } mLock.release(); return; }
void Dbtux::execTUX_MAINT_REQ(Signal* signal) { jamEntry(); TuxMaintReq* const sig = (TuxMaintReq*)signal->getDataPtrSend(); // ignore requests from redo log IndexPtr indexPtr; c_indexPool.getPtr(indexPtr, sig->indexId); if (unlikely(! (indexPtr.p->m_state == Index::Online || indexPtr.p->m_state == Index::Building))) { jam(); #ifdef VM_TRACE if (debugFlags & DebugMaint) { TupLoc tupLoc(sig->pageId, sig->pageIndex); debugOut << "opInfo=" << hex << sig->opInfo; debugOut << " tableId=" << dec << sig->tableId; debugOut << " indexId=" << dec << sig->indexId; debugOut << " fragId=" << dec << sig->fragId; debugOut << " tupLoc=" << tupLoc; debugOut << " tupVersion=" << dec << sig->tupVersion; debugOut << " -- ignored at ISP=" << dec << c_internalStartPhase; debugOut << " TOS=" << dec << c_typeOfStart; debugOut << endl; } #endif sig->errorCode = 0; return; } TuxMaintReq reqCopy = *sig; TuxMaintReq* const req = &reqCopy; const Uint32 opCode = req->opInfo & 0xFF; // get the index ndbrequire(indexPtr.p->m_tableId == req->tableId); // get base fragment id and extra bits const Uint32 fragId = req->fragId; // get the fragment FragPtr fragPtr; findFrag(jamBuffer(), *indexPtr.p, fragId, fragPtr); ndbrequire(fragPtr.i != RNIL); Frag& frag = *fragPtr.p; // set up search entry TreeEnt ent; ent.m_tupLoc = TupLoc(req->pageId, req->pageIndex); ent.m_tupVersion = req->tupVersion; // set up and read search key KeyData searchKey(indexPtr.p->m_keySpec, false, 0); searchKey.set_buf(c_ctx.c_searchKey, MaxAttrDataSize << 2); readKeyAttrs(c_ctx, frag, ent, searchKey, indexPtr.p->m_numAttrs); if (unlikely(! indexPtr.p->m_storeNullKey) && searchKey.get_null_cnt() == indexPtr.p->m_numAttrs) { jam(); return; } #ifdef VM_TRACE if (debugFlags & DebugMaint) { const Uint32 opFlag = req->opInfo >> 8; debugOut << "opCode=" << dec << opCode; debugOut << " opFlag=" << dec << opFlag; debugOut << " tableId=" << dec << req->tableId; debugOut << " indexId=" << dec << req->indexId; debugOut << " fragId=" << dec << req->fragId; debugOut << " entry=" << ent; debugOut << endl; } #endif // do the operation req->errorCode = 0; TreePos treePos; bool ok; switch (opCode) { case TuxMaintReq::OpAdd: jam(); ok = searchToAdd(c_ctx, frag, searchKey, ent, treePos); #ifdef VM_TRACE if (debugFlags & DebugMaint) { debugOut << treePos << (! ok ? " - error" : "") << endl; } #endif if (! ok) { jam(); // there is no "Building" state so this will have to do if (indexPtr.p->m_state == Index::Online) { jam(); req->errorCode = TuxMaintReq::SearchError; } break; } /* * At most one new node is inserted in the operation. Pre-allocate * it so that the operation cannot fail. */ if (frag.m_freeLoc == NullTupLoc) { jam(); NodeHandle node(frag); req->errorCode = allocNode(c_ctx, node); if (req->errorCode != 0) { jam(); break; } frag.m_freeLoc = node.m_loc; ndbrequire(frag.m_freeLoc != NullTupLoc); } treeAdd(c_ctx, frag, treePos, ent); frag.m_entryCount++; frag.m_entryBytes += searchKey.get_data_len(); frag.m_entryOps++; break; case TuxMaintReq::OpRemove: jam(); ok = searchToRemove(c_ctx, frag, searchKey, ent, treePos); #ifdef VM_TRACE if (debugFlags & DebugMaint) { debugOut << treePos << (! ok ? " - error" : "") << endl; } #endif if (! ok) { jam(); // there is no "Building" state so this will have to do if (indexPtr.p->m_state == Index::Online) { jam(); req->errorCode = TuxMaintReq::SearchError; } break; } treeRemove(frag, treePos); ndbrequire(frag.m_entryCount != 0); frag.m_entryCount--; frag.m_entryBytes -= searchKey.get_data_len(); frag.m_entryOps++; break; default: ndbrequire(false); break; } #ifdef VM_TRACE if (debugFlags & DebugTree) { printTree(signal, frag, debugOut); } #endif // copy back *sig = *req; //ndbrequire(c_keyAttrs[0] == c_keyAttrs[1]); //ndbrequire(c_sqlCmp[0] == c_sqlCmp[1]); //ndbrequire(c_searchKey[0] == c_searchKey[1]); //ndbrequire(c_entryKey[0] == c_entryKey[1]); //ndbrequire(c_dataBuffer[0] == c_dataBuffer[1]); }
int MpTopologyGraph::linkTopologyResources(MpResourceTopology& resourceTopology, UtlHashBag& newResources, UtlBoolean replaceNumInName, int resourceNum) { // Link the resources int connectionIndex = 0; UtlString outputResourceName; UtlString inputResourceName; int outputResourcePortIndex; int inputResourcePortIndex; MpResource* outputResource = NULL; MpResource* inputResource = NULL; OsStatus result; UtlHashMap newConnectionIds; #ifdef TEST_PRINT osPrintf("%d new resources in the list\n", newResources.entries()); UtlHashBagIterator iterator(newResources); MpResource* containerResource = NULL; while(containerResource = (MpResource*) iterator()) { osPrintf("found list resource: \"%s\" value: \"%s\"\n", containerResource->getName().data(), containerResource->data()); } #endif while(resourceTopology.getConnection(connectionIndex, outputResourceName, outputResourcePortIndex, inputResourceName, inputResourcePortIndex) == OS_SUCCESS) { if(replaceNumInName) { resourceTopology.replaceNumInName(outputResourceName, resourceNum); resourceTopology.replaceNumInName(inputResourceName, resourceNum); } // Look in the container of new resources first as this is more // efficient and new resources are not added immediately to a running // flowgraph outputResource = (MpResource*) newResources.find(&outputResourceName); if(outputResource == NULL) { result = lookupResource(outputResourceName, outputResource); if(result != OS_SUCCESS) { int virtPortIdx = outputResourcePortIndex>=0?outputResourcePortIndex:-1; int realPortIdx; result = lookupVirtualOutput(outputResourceName, virtPortIdx, outputResource, realPortIdx); if (result == OS_SUCCESS && outputResourcePortIndex>=0) { outputResourcePortIndex = realPortIdx; } } assert(result == OS_SUCCESS); } inputResource = (MpResource*) newResources.find(&inputResourceName); if(inputResource == NULL) { result = lookupResource(inputResourceName, inputResource); if(result != OS_SUCCESS) { int virtPortIdx = inputResourcePortIndex>=0?inputResourcePortIndex:-1; int realPortIdx; result = lookupVirtualInput(inputResourceName, virtPortIdx, inputResource, realPortIdx); if (result == OS_SUCCESS && inputResourcePortIndex>=0) { inputResourcePortIndex = realPortIdx; } } assert(result == OS_SUCCESS); } assert(outputResource); assert(inputResource); if(outputResource && inputResource) { if(outputResourcePortIndex == MpResourceTopology::MP_TOPOLOGY_NEXT_AVAILABLE_PORT) { outputResourcePortIndex = outputResource->reserveFirstUnconnectedOutput(); assert(outputResourcePortIndex >= 0); } else if(outputResourcePortIndex < MpResourceTopology::MP_TOPOLOGY_NEXT_AVAILABLE_PORT) { // First see if a real port is already in the dictionary UtlInt searchKey(outputResourcePortIndex); UtlInt* foundValue = NULL; if((foundValue = (UtlInt*) newConnectionIds.findValue(&searchKey))) { // Use the mapped index outputResourcePortIndex = foundValue->getValue(); } else { // Find an available port and add it to the map int realPortNum = outputResource->reserveFirstUnconnectedOutput(); assert(realPortNum >= 0); UtlInt* portKey = new UtlInt(outputResourcePortIndex); UtlInt* portValue = new UtlInt(realPortNum); newConnectionIds.insertKeyAndValue(portKey, portValue); outputResourcePortIndex = realPortNum; } } if(inputResourcePortIndex == MpResourceTopology::MP_TOPOLOGY_NEXT_AVAILABLE_PORT) { inputResourcePortIndex = inputResource->reserveFirstUnconnectedInput(); assert(inputResourcePortIndex >= 0); } else if(inputResourcePortIndex < MpResourceTopology::MP_TOPOLOGY_NEXT_AVAILABLE_PORT) { // First see if a real port is already in the dictionary UtlInt searchKey(inputResourcePortIndex); UtlInt* foundValue = NULL; if((foundValue = (UtlInt*) newConnectionIds.findValue(&searchKey))) { // Use the mapped index inputResourcePortIndex = foundValue->getValue(); } else { // Find an available port and add it to the map int realPortNum = inputResource->reserveFirstUnconnectedInput(); assert(realPortNum >= 0); UtlInt* portKey = new UtlInt(inputResourcePortIndex); UtlInt* portValue = new UtlInt(realPortNum); newConnectionIds.insertKeyAndValue(portKey, portValue); inputResourcePortIndex = realPortNum; } } result = addLink(*outputResource, outputResourcePortIndex, *inputResource, inputResourcePortIndex); assert(result == OS_SUCCESS); } connectionIndex++; } newConnectionIds.destroyAll(); return(connectionIndex); }