static DArray<T> alloc(Memory& mem, size_t length) { auto ptr = cast(T*)mem.allocRaw(ARRAY_BYTE_SIZE(length) MEMBERTYPEID); DArray<T> ret = {ptr, length}; ret.zeroFill(); return ret; }
DArray<uint16> * LocalNodeInfo::getSubscribingClients (Message *pMsg) { DArray<uint16> *pSubscribingClients = NULL; uint16 j = 0; _m.lock (314); for (UInt32Hashtable<SubscriptionList>::Iterator i = _localSubscriptions.getAllElements(); !i.end(); i.nextElement()) { PtrLList<Subscription> *pSubscriptions = i.getValue()->getSubscriptionWild (pMsg->getMessageHeader()->getGroupName()); // Get every subscribed group that matches with the message's group if (pSubscriptions != NULL) { for (Subscription *pSub = pSubscriptions->getFirst(); pSub != NULL; pSub = pSubscriptions->getNext()) { if ((pSub->getSubscriptionType() == Subscription::GROUP_PREDICATE_SUBSCRIPTION) || pSub->matches(pMsg)) { if (pSubscribingClients == NULL) { pSubscribingClients = new DArray<uint16>(); } bool bFound = false; for (unsigned int k = 0; k < pSubscribingClients->size(); k++) { if ((*pSubscribingClients)[k] == i.getKey()) { bFound = true; break; } } if (!bFound) { (*pSubscribingClients)[j] = i.getKey(); j++; } } } delete pSubscriptions; pSubscriptions = NULL; } } _m.unlock (314); return pSubscribingClients; }
DArray<JournalRecord*> * Journal::getJournalRecords(uint64_t start_tid, uint64_t end_tid){ DArray<JournalRecord*> *recs = new DArray<JournalRecord*>(); int idx = -1; #if TID_HASHTABLE == 1 while((idx = tidSearchRecord(start_tid)) == -1) // psakse se pio index tou Journal tha ksekinisw na psaxnw start_tid += 1; // an den yparxei to tid pou mou dwse san start psakse to epomeno #else while((idx = searchRecord(start_tid)) == -1) // psakse se pio index tou Journal tha ksekinisw na psaxnw start_tid += 1; // an den yparxei to tid pou mou dwse san start psakse to epomeno #endif int rsize = Records->size(); for (int i = idx; i < rsize; i++){ // psakse siriaka apo ekei pou sou gurise i binary search // mexri to end_tid uint64_t tid = (Records->get(i))->getTransactionId(); // tid of the specific JournalRecord if (tid <= end_tid) { // oso den exw kseperasei to end_tid recs->push_back(Records->get(i)); } else break; } return recs; }
DArray<T> dup(Memory& mem) { auto retPtr = cast(T*)mem.allocRaw(ARRAY_BYTE_SIZE(length) MEMBERTYPEID); DArray<T> ret = {retPtr, this->length}; ret.slicea(*this); return ret; }
void PrintBTree ( BTree <char *> *btree ) { UplinkAssert ( btree ); DArray <char *> *uo = btree->ConvertToDArray (); DArray <char *> *uo_id = btree->ConvertIndexToDArray (); for ( int i = 0; i < uo->Size (); ++i ) { if ( uo->ValidIndex (i) ) { UplinkAssert ( uo_id->ValidIndex (i) ); printf ( "Index = %s\n", uo_id->GetData (i) ); if ( uo->GetData (i) ) printf ( "%s\n", uo->GetData (i) ); else printf ( "NULL\n" ); } } delete uo; delete uo_id; }
/* * Evaluate pressure, and add to accumulator. */ void McStressAutoCorrelation::sample(long iStep) { double pressure; double temperature; McSystem& sys=system(); sys.computeStress(pressure); DArray<double> elements; elements.allocate(9); Tensor total; if (isAtInterval(iStep)){ sys.computeVirialStress(total); temperature = sys.energyEnsemble().temperature(); elements[0] = (total(0,0) - pressure / 3.0) / (10.0 * temperature); elements[1] = (total(0,1) + total(1,0)) / 2.0 / (10.0 * temperature); elements[2] = (total(0,2) + total(2,0)) / 2.0 / (10.0 * temperature); elements[3] = elements[1]; elements[4] = (total(1,1) - pressure / 3.0) / (10.0 * temperature); elements[5] = (total(1,2) + total(2,1)) / 2.0 / (10.0 * temperature); elements[6] = elements[2]; elements[7] = elements[5]; elements[8] = (total(2,2) - pressure / 3.0) / (10.0 * temperature); accumulator_.sample(elements); } }
//======================================================================================================= DArray<uint64_t>* Key_HashTable::getHashRecords(unsigned key) { unsigned hashed_key; hashed_key = hashFunction(key); int index = getBucketIndex(hashed_key, globalDepth); // koitaw ta globaldepth deksia bits gia na dw se poio index tha paw Bucket* tempBucket = bucketArray.get(index); DArray<uint64_t>* array = new DArray<uint64_t>(); if((tempBucket->empty == false) && (tempBucket->key == key)){ BucketData* tempData = tempBucket->first; do { array->push_back(tempData->offsets[0]); if(tempData-> second_of == true) array->push_back(tempData->offsets[1]); tempData = tempData->next; }while(tempData != NULL); if(array->size() == 0) { delete array; return NULL; } return array; } else // cout << "getHashRecords: Key not found" << endl; if(array->size() == 0) { delete array; return NULL; } return array; }
DArray <char *> *BTree<T>::ConvertIndexToDArray() { DArray <char *> *darray = new DArray <char *>; darray->SetSize( Size() ); RecursiveConvertIndexToDArray( darray, this ); return darray; }
void EigenVectors::InitArray(DArray &darr, int size) const { if(!darr.empty()) { darr.clear(); } darr.reserve(size); for(int i = 0; i < size; ++i) { darr.push_back(0.); } }
void EclSuperUnHighlightAll () { DArray <char *> *highlights = superhighlightedbuttons.ConvertIndexToDArray (); for ( int i = 0; i < highlights->Size (); ++i ) if ( highlights->ValidIndex (i) ) EclSuperUnHighlight ( highlights->GetData (i) ); }
int main() { DArray<char> myArray; char theChar = 'a'; for(int i = 0; i < 26; i++){ myArray.add(theChar); theChar++; cout << myArray.getArray()[i] << endl; } }
int TopologyWorldState::printWorldStateInfo (void) { // Prints information about local node, like subscriptions, alive neighbors, dead peers, etc _m.lock (141); checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "=========================================================================\n"); checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, " PRINT WORLD STATE INFO\n"); checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, " Node id: %s\n", _pDisService->getNodeId()); if ((_pLocalNodeInfo->getConsolidatedSubscriptions())->getCount() == 0) { checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, " No subscribed groups\n"); } else { _pLocalNodeInfo->printAllSubscribedGroups(); // Print subscribing clients checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, " SUBSCRIBING CLIENTS:\n"); DArray<uint16> *pSubClients = _pLocalNodeInfo->getAllSubscribingClients(); for (int j = 0; j <= pSubClients->getHighestIndex(); j++) { checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, " SUB CLIENT N.%d:\n", (*pSubClients)[j]); SubscriptionList *pSubsForClient = _pLocalNodeInfo->getSubscriptionListForClient ((*pSubClients)[j]); _pLocalNodeInfo->releaseLocalNodeInfo(); if (pSubsForClient && pSubsForClient->getCount() != 0) { for (StringHashtable<Subscription>::Iterator i = pSubsForClient->getIterator(); !i.end(); i.nextElement()) { checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, " SUBSCRIPTION:\n"); checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, " groupname %s\n", i.getKey()); Subscription *pS = i.getValue(); pS->printInfo(); } } } // Print local consolidated subscriptions checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, " LOCAL CONSOLIDATED SUBSCRIPTIONS:\n"); SubscriptionList *pSubscriptions = _pLocalNodeInfo->getConsolidatedSubscriptions(); for (StringHashtable<Subscription>::Iterator i = pSubscriptions->getIterator(); !i.end(); i.nextElement()) { checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, " SUBSCRIPTION:\n"); checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, " groupname %s\n", i.getKey()); Subscription *pS = i.getValue(); pS->printInfo(); } } checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "-------------------------------------------------------------------------\n"); checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, " %d ACTIVE NEIGHBORS\n", _pLocalNodeInfo->getCount()); for (StringHashtable<Thing>::Iterator iNeighbors = _pLocalNodeInfo->getAllElements(); !iNeighbors.end(); iNeighbors.nextElement()) { checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "-------------------------------------------------------------------------\n"); RemoteNodeInfo *pRNI = (RemoteNodeInfo *) iNeighbors.getValue(); pRNI->printRemoteNodeInfo(); } checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "-------------------------------------------------------------------------\n"); checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, " %d DEAD PEERS\n", _deadPeers.getCount()); for (StringHashtable<RemoteNodeInfo>::Iterator iDead = _deadPeers.getAllElements(); !iDead.end(); iDead.nextElement()) { checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "-------------------------------------------------------------------------\n"); RemoteNodeInfo *pRNI = (RemoteNodeInfo *) iDead.getValue(); pRNI->printRemoteNodeInfo(); } checkAndLogMsg ("TopologyWorldState::printWorldStateInfo", Logger::L_Info, "=========================================================================\n"); _m.unlock (141); return 0; }
void LocalNodeInfo::addAddFiltersToConsolidateList (const char *pszGroupName) { _m.lock (328); // Get all the client subscribing the group DArray<uint16> *pSubClients = NULL;//getSubscribingClients (pszGroupName); Subscription *pSCons = _consolidatedSubscriptions.getSubscription (pszGroupName); if ((pSubClients == NULL) || (!((pSCons != NULL) && (pSCons->getSubscriptionType() == Subscription::GROUP_SUBSCRIPTION)))) { _m.unlock (328); return; } GroupSubscription *pGSCons = (GroupSubscription *) pSCons; // Look for the first subscribing client which subscribes by a GROUP_SUBSCRIPTION uint16 ui16ClientId; Subscription *pS = NULL; for (int i = 0; i <= pSubClients->getHighestIndex(); i++) { ui16ClientId = (*pSubClients)[i]; SubscriptionList *pSL = NULL; if (((pSL = _localSubscriptions.get(ui16ClientId)) != NULL) && ((pS = pSL->getSubscription(pszGroupName)) != NULL)) { if (pS->getSubscriptionType() == Subscription::GROUP_SUBSCRIPTION) { break; } if (pS->getSubscriptionType() == Subscription::GROUP_PREDICATE_SUBSCRIPTION) { // I want every tag - remove them and return pGSCons->removeAllFilters(); _m.unlock (328); return; } } } // match every filter against every other subscribing client's tag list. // Add it iff: // 1) Every other GROUP_SUBSCRIPTION has the same filter // 2) No one of the other GROUP_TAG_SUBSCRIPTION subscribe the tag // 3) There is not any GROUP_PREDICATE_SUBSCRIPTION for the group GroupSubscription *pGS = (GroupSubscription*) pS; DArray<uint16> *pTags = pGS->getAllFilters(); for (int i = 0; i <= pTags->getHighestIndex(); i++) { bool bAddFilter = true; int16 ui16Tag = (*pTags)[i]; for (int j = 0; j <= pSubClients->getHighestIndex(); j++) { Subscription *pS = NULL; if (pS->matches(ui16Tag)) { bAddFilter = false; break; } } if (bAddFilter) { pGSCons->addFilter((*pTags)[i]); } } _m.unlock (328); }
void InterfaceScreen::Remove () { DArray<char *> *btns = this->interface_buttons; for ( int i = 0; i < btns->Size(); ++i ) { if ( btns->ValidIndex( i ) ) { char *btn_name = btns->GetData( i ); if ( (NULL != btn_name) && ('\0' != btn_name[0]) ) EclRemoveButton( btn_name ); } } }
int DSProImpl::requestMoreChunks (const char *pszChunkedMsgId, const char *pszCallbackParameter) { const char *pszMethodName = "DSProImpl::requestMoreChunks"; if (pszChunkedMsgId == NULL) { return -1; } _m.lock (2010); if (_userReqs.put (pszChunkedMsgId, pszCallbackParameter) == 0) { checkAndLogMsg (pszMethodName, Logger::L_MildError, "new chunk requested " "and added it to _userReqs\n", pszChunkedMsgId); } Targets **ppTargets = _pTopology->getNeighborsAsTargets(); if (ppTargets == NULL) { _m.unlock (2010); return 0; } if (ppTargets[0] == NULL) { delete ppTargets; _m.unlock (2010); return 0; } uint8 ui8TotalNumberOfChunks = 0; DArray<uint8> *pCachedChunkIds = _pDataStore->getCachedChunkIDs (pszChunkedMsgId, ui8TotalNumberOfChunks); int rc = _adaptMgr.sendChunkRequestMessage (pszChunkedMsgId, pCachedChunkIds, getNodeId(), ppTargets); Targets::deallocateTargets (ppTargets); String chunkIds (""); if (pCachedChunkIds != NULL) { for (unsigned int i = 0; i < pCachedChunkIds->size(); i++) { chunkIds += ((uint32) (*pCachedChunkIds)[i]); chunkIds += " "; } delete pCachedChunkIds; pCachedChunkIds = NULL; } if (rc < 0) { checkAndLogMsg (pszMethodName, Logger::L_Warning, "could not request more chunks " "for %s. Return code %d. The already received chunks are: <%s>\n", pszChunkedMsgId, rc, chunkIds.c_str()); } else { checkAndLogMsg (pszMethodName, Logger::L_Info, "requested more chunks for message %s. " "The already received chunks are: <%s>\n", pszChunkedMsgId, chunkIds.c_str()); } _m.unlock (2010); return (rc < 0 ? -2 : 0); }
void DeleteBTreeData ( BTree <UplinkObject *> *btree ) { UplinkAssert ( btree ); DArray <UplinkObject *> *uo = btree->ConvertToDArray (); for ( int i = 0; i < uo->Size (); ++i ) if ( uo->ValidIndex (i) ) if ( uo->GetData (i) ) delete uo->GetData (i); delete uo; }
bool GroupSubscription::merge (Subscription *pSubscription) { bool bRet = false; switch (pSubscription->getSubscriptionType()) { case GROUP_SUBSCRIPTION: { GroupSubscription *pGS = (GroupSubscription *) pSubscription; DArray<uint16> *pFiltersInSubscription = pGS->getAllFilters(); if (pFiltersInSubscription != NULL) { for (unsigned int i = 0; i < pFiltersInSubscription->size(); i++) { uint16 ui16 = (*pFiltersInSubscription)[i]; if (_ui32HashFilteredTags.contains (ui16)) { pGS->removeFilter (ui16); bRet = true; } } } if (getPriority() > pGS->getPriority()) { pGS->setPriority (getPriority()); bRet = true; } if (isGroupReliable() > pGS->isGroupReliable()) { pGS->setGroupReliable (isGroupReliable()); bRet = true; } if (isMsgReliable() > pGS->isMsgReliable()) { pGS->setMsgReliable (isMsgReliable()); bRet = true; } if (isSequenced() > pGS->isSequenced()) { pGS->setSequenced (isSequenced()); bRet = true; } break; } case GROUP_PREDICATE_SUBSCRIPTION: { //TODO break; } case GROUP_TAG_SUBSCRIPTION: { //TODO break; } } return bRet; }
int main(){ int option, columns, total_records; uint64_t* values; JournalRecord* record; DArray<JournalRecord*> *Records; srand(time(0)); while(1){ cout << endl; cout << "==========================================================" << endl; cout << "Options: " << endl << endl; cout << "Option[1]: Create JournalRecords - USE THIS ONCE" << endl; cout << "Option[2]: Print JournalRecords" << endl; cout << "Option[3]: Delete all JournalRecords and EXIT" << endl; cout << "==========================================================" << endl; cin >> option; if (option == OPTION1){ cout << "Give # of columns for the records: "; cin >> columns; cout << "Give # of records to create: "; cin >> total_records; values = (uint64_t*)malloc((columns * total_records) * sizeof(uint64_t)); Records = new DArray<JournalRecord*>(); // array with random record values for total_records records for (int i = 0; i < columns * total_records; i++){ uint64_t val_to_add = rand() % 10001; values[i] = val_to_add; } for (int i = 0; i < columns * total_records; i++){ if(i % columns == 0) { // start of group uint64_t random_tid = rand() % 100; record = new JournalRecord(random_tid, INSERT); } record->addValue(values[i]); // add value to record if((i + 1) % columns == 0) // end of group Records->push_back(record); } } else if (option == OPTION2){
/*********************************************** * abs ***********************************************/ DArray abs(DArray& a) { a.setdefaultsize(a.n); DArray c; for(int i=0;i<a.n;i++) c[i] = (double)fabs(a[i]); return(c); }
/*********************************************** * log10 ***********************************************/ DArray log10(DArray& a) { a.setdefaultsize(a.n); DArray c; for(int i=0;i<a.n;i++) c[i] = log10(a[i]); return(c); }
void LanguageTable::ClearTranslation() { DArray<char *> *translation = m_translation.ConvertToDArray(); for( int i = 0; i < translation->Size(); ++i ) { if( translation->ValidIndex(i) ) { char *data = translation->GetData(i); delete data; } } delete translation; m_translation.Empty(); }
/*********************************************** * square ***********************************************/ DArray square(DArray& a) { a.setdefaultsize(a.n); DArray c; for(int i=0;i<a.n;i++) c[i] = square(a[i]); return(c); }
void LanguageTable::ClearBaseLanguage() { DArray<char *> *base = m_baseLanguage.ConvertToDArray(); for( int i = 0; i < base->Size(); ++i ) { if( base->ValidIndex(i) ) { char *data = base->GetData(i); delete data; } } delete base; m_baseLanguage.Empty(); }
/*********************************************** * rand ***********************************************/ DArray rand(DArray& a) { a.setdefaultsize(a.n); DArray c; for(int i=0;i<a.n;i++) c[i] = rand(a[i]); return(c); }
int main () { printf ("Results of tr1_array5_test:\n"); // define special type name typedef array<float,6> Array; // create and initialize an array const Array a = { { 42.42f } }; // use some common STL container operations printf ("static_size: %lu\n", a.size ()); printf ("size: %lu\n", a.size ()); // Can't use std::boolalpha because it isn't portable printf ("empty: %s\n", (a.empty()? "true" : "false")); printf ("max_size: %lu\n", a.max_size ()); printf ("front: %f\n", a.front ()); printf ("back: %f\n", a.back ()); printf ("[0]: %f\n", a[0]); printf ("elems: "); // iterate through all elements for (Array::const_iterator pos=a.begin(); pos<a.end(); ++pos) printf ("%f ", *pos); printf ("\n"); test_static_size(a); // check copy constructor and assignment operator Array b(a); Array c; c = a; if (a==b && a==c) printf ("copy construction and copy assignment are OK\n"); else printf ("copy construction and copy assignment are BROKEN\n"); typedef array<double,6> DArray; typedef array<int,6> IArray; IArray ia = { { 1, 2, 3, 4, 5, 6 } } ; // extra braces silence GCC warning DArray da; da = ia; da.assign (42); return 0; }
int TestSort_DArray(Sorter<int> *_sorter) { DArray<int> *darray = new DArray<int>(); for (int i = 0; i < SORT_ITEMS; i++) { darray->insert(CrissCross::System::RandomNumber()); } darray->sort(_sorter); for (int i = 0; i < SORT_ITEMS - 1; i++) { TEST_ASSERT(darray->get(i) <= darray->get(i+1)); } delete darray; return 0; }
void DeleteBTreeData ( BTree <char *> *btree ) { UplinkAssert ( btree ); DArray <char *> *uo = btree->ConvertToDArray (); for ( int i = 0; i < uo->Size (); ++i ) if ( uo->ValidIndex (i) ) if ( uo->GetData (i) ) // Even zero length string need to be deleted //if ( strcmp ( uo->GetData (i), "" ) != 0 ) delete [] uo->GetData (i); delete uo; }
//================================================================================================ DArray<JournalRecord*> * Journal::getRecordsbyKey(unsigned key, uint64_t start_tid, uint64_t end_tid) { DArray<unsigned>* offsets = key_htable.getHashRecords(key, start_tid, end_tid); if(offsets == NULL) return NULL; DArray<JournalRecord*> * records = new DArray<JournalRecord*>(100); unsigned size = offsets->size(); for (unsigned i = 0; i < size; i++) { records->push_back(getRecordatOffset(offsets->get(i))); } delete offsets; return records; }
void Legendre::ExtractPolynomial(DArray &dArray) { double val; int i, k; bool needAlloc = (dArray.size() != nn); if(needAlloc) { dArray.clear(); dArray.reserve(nn); } for(i = 0; i < nn; ++i) { k = i / 2; val = (i % 2) ? nFunction[0][k].c : nFunction[0][k].x; if(needAlloc) { dArray.push_back(val); } else { dArray[i] = val; } } }
int EigenVectors::TrimSystem(DMatrix &dmat, DArray &darr) const { dmat.pop_back(); darr.pop_back(); int i, size = dmat.size(); for(i = 0; i < size; ++i) { dmat[i].pop_back(); } return size; }