//============================================================================= // METHOD: SPELLipcDataChunk:: //============================================================================= int SPELLipcDataChunk::startChunks( const std::string& id, const DataList& data ) { SPELLmonitor m(m_lock); if (data.size()<=m_chunkSize) return 0; ListOfDataList* chunks = new ListOfDataList(); DataList::const_iterator it; DataList::const_iterator end = data.end(); unsigned int lineCount = 0; DataList* chunk = new DataList(); for( it = data.begin(); it != end; it++) { chunk->push_back( (*it) ); lineCount++; if (lineCount==m_chunkSize) { chunks->push_back( chunk ); chunk = new DataList(); lineCount = 0; } } // Add the last partial chunk if any if (chunk->size()>0) { chunks->push_back( chunk ); } m_chunks[id] = chunks; int totalChunks = chunks->size(); return totalChunks; }
static DataList convolve(const DataList &f1, const DataList &f2, const float dt = 1.0f) { const unsigned int f1size = f1.size(); const unsigned int f2size = f2.size(); DataList toReturn = DataList(f1size + f2size - 1, 0); for (unsigned int i = 0; i < f1size; ++i) { for (unsigned int j = 0; j < f2size; ++j) { toReturn[i+j] += f1[i] * f2[j] * dt; } } return toReturn; }
void ParallelInfo::sendSumwz(const DataList &toSend) { int P_Tag = 0; // P_Info points to the info struct for the neigbor under consideration ParallelInfo *P_Info; #if defined(TIMING_MODE) long long start, elapsed; start = rdtsc(); #endif P_Info = &P_Nodes[0]; // send sumwz to the root node for (unsigned int i = 0; i < toSend.size(); i++) P_Info->P_sumwz[i] = toSend.at(i); #if defined(RNG_BUCKET) P_RandComm->Send(&P_Info->P_sumwz[0], totalNumNrns, MPI_DOUBLE, P_ROOT_NODE_NUM, P_Tag, MPI_COMM_WORLD); #else MPI_Send(&P_Info->P_sumwz[0], totalNumNrns, MPI_DOUBLE, P_ROOT_NODE_NUM, P_Tag, MPI_COMM_WORLD); #endif #if defined(TIMING_MODE) elapsed = rdtsc() - start; Output::Out() << MSG << "Elapsed nonroot_snd time = " << elapsed * 1.0 / TICKS_PER_SEC << " seconds" << endl; #endif }
void fillDataLists(const vector<FrameEnhanced> &frames, DataList& redChannels, DataList& greenChannels, DataList& blueChannels) { assert(frames.size() == redChannels.size()); assert(frames.size() == greenChannels.size()); assert(frames.size() == blueChannels.size()); // build temporary data structure for ( size_t exp = 0; exp < frames.size(); ++exp ) { Channel* red; Channel* green; Channel* blue; frames[exp].frame()->getXYZChannels(red, green, blue); redChannels[exp] = red->data(); greenChannels[exp] = green->data(); blueChannels[exp] = blue->data(); } }
Combo::Combo(Layer::Molecule* molecule, DataList const& frames, int const interpolationFrames, double const speed) : Base(1.0, speed, Ramp), m_molecule(molecule), m_frames(frames), m_bounce(false), m_loop(false), m_interpolationFrames(interpolationFrames), m_currentIndex(-1) { m_referenceFrames = 1 + (frames.size()-1)/(m_interpolationFrames+1); int nCycles(m_bounce ? 2*m_referenceFrames-1 : m_referenceFrames-1); setCycles(nCycles); DataList::iterator iter; for (iter = m_frames.begin(); iter != m_frames.end(); ++iter) { (*iter)->m_surface->setCheckState(Qt::Unchecked); } setCurrentIndex(0); }
void makeNode(DataList& in) { for(int i = 0; i< in.size(); i++) { Node* temp = new Node(i+1); stringstream left1,down1,top1,right1; int left2,down2,top2,right2; if(in[i][0][0] == '-') { string temp0 = in[i][0]; temp0.erase(temp0.begin()); left1<<temp0; left1>>left2; left2 = (-1)*left2; } else {
void ScrDB::Read(TARGETING::TargetHandle_t i_ptargetHandle, BitString & bs, uint64_t registerId) { //PRDF_DENTER( "ScrDB::Read() huid: 0x%X, addr: 0x%016X", // getHuid(i_ptargetHandle), registerId ); DataList data; unsigned int dataWordSize = bs.getBitLen()/32; dataWordSize += (bs.getBitLen() % 32) ? 1 : 0; // if the register has a predetermined value than get it if(pChipset.find(i_ptargetHandle) != pChipset.end()) { PreScrMap pscrmap = pChipset[i_ptargetHandle]; if(pscrmap.find(registerId) != pscrmap.end()) // we must have a predetermined value { SimScrDataSet pValues = pscrmap[registerId]; data = pValues.GetData(); // get next set of values // pValues has changed - copy it back pscrmap[registerId] = pValues; pChipset[i_ptargetHandle] = pscrmap; } } if(data.size() == 0) // use the last value written to this reg { // get a copy of the scrMap for this chip - if one does not exist it will be created ScrMap scrMap = chipset[i_ptargetHandle]; // get a copy of the data for this address from the scrMap for this chip // if data structure does not exist, it will be created, but will be empty data = scrMap[registerId]; if(data.size() == 0) // This is the first time this register has been accessed { while(data.size() < dataWordSize) data.push_back(0); // zero fill scrMap[registerId] = data; chipset[i_ptargetHandle] = scrMap; // update the persistent copy of the scrMap } } if(0 != data.size()) { for(unsigned int i = 0; i < data.size(); ++i) { bs.setFieldJustify((i*32), 32, data[i]); } PRDF_TRAC( "ScrDB::Read() huid: %X, addr: %016X, data: %08X %08X", getHuid(i_ptargetHandle), registerId, data[0], 2 == data.size() ? data[1] : 0 ); } //PRDF_DEXIT( "ScrDB::Read()" ); }
void DBDictionary::GetColData( int colNum, const DataList & dataList, std::vector<std::string> & outList ) { if( colNum < 0 ) { printf( "read error" ); return; } int size = dataList.size(); for( int num = 0; num < size; num++ ) { std::string data = dataList[num]._data[colNum]; if( IsSameData( data, outList ) == false ) { printf( "%s \n", data.c_str() ); outList.push_back( data ); } } }
void ScrDB::Write(TARGETING::TargetHandle_t i_ptargetHandle, BitString & bs, uint64_t registerId) { PRDF_TRAC( "ScrDB::Write() huid: %X, addr: %016X, data: %08X %08X", getHuid(i_ptargetHandle), registerId, bs.getFieldJustify(0,32), bs.getFieldJustify(32,32) ); unsigned int dataWordSize = bs.getBitLen()/32; // PRDF_TRAC("dataWordSize1: %d", dataWordSize); dataWordSize += (bs.getBitLen() % 32) ? 1 : 0; // PRDF_TRAC("dataWordSize2: %d", dataWordSize); DataList data; // parse all data given data.push_back(bs.getFieldJustify(0,32)); data.push_back(bs.getFieldJustify(32,32)); // PRDF_TRAC("parse all data given"); // look for expected data DataList expectedData; if(eChipset.find(i_ptargetHandle) != eChipset.end()) { PRDF_TRAC("found target"); PreScrMap escrmap = eChipset[i_ptargetHandle]; if(escrmap.find(registerId) != escrmap.end()) // we have expected data value { PRDF_TRAC("found scom reg"); SimScrDataSet eValues = escrmap[registerId]; expectedData = eValues.GetData(); // get next set of values escrmap[registerId] = eValues; eChipset[i_ptargetHandle] = escrmap; } } if(expectedData.size() > 0) { if((expectedData[0] != data[0]) || (expectedData[1] != data[1])) { PRDF_ERR("Verify SC register: %p", i_ptargetHandle); PRDF_ERR(" Address: 0x%016X", registerId); PRDF_ERR("SCR write Actual : %08X %08X", data[0], data[1]); PRDF_ERR("SCR write Expected: %08X %08X", expectedData[0], expectedData[1]); } else { PRDF_TRAC("Verify SC register: %p", i_ptargetHandle); PRDF_TRAC(" Address: 0x%016X", registerId); PRDF_TRAC("SCR write Actual: %08X %08X", data[0], data[1]); } } // PRDF_TRAC("get a copy"); // get a copy of the scrMap for this chip - if one does not exist it will be created ScrMap scrMap = chipset[i_ptargetHandle]; // PRDF_TRAC("update register value"); // update register value scrMap[registerId] = data; // copy the supplied value to the register // PRDF_TRAC("update the master"); chipset[i_ptargetHandle] = scrMap; // scrMap is only a copy so must update the master //PRDF_EXIT( "ScrDB::Write()" ); }
int main(int argc, char* argv[]) { int capacity; int NumOfFood; fstream fin(argv[1]); fstream fout; fout.open(argv[2],ios::out); fin>>capacity; fin>>NumOfFood; int x; int y; int weight; DataList FoodInfo; vector<int>aa(4,0); FoodInfo.push_back(aa); while(fin>>x>>y>>weight) { Data temp(3); temp[0] = x; temp[1] = y; temp[2] = weight; FoodInfo.push_back(temp); } //test cout<<capacity<<endl; cout<<NumOfFood<<endl; //cout<<x<<" "<<y<<" "<<weight<<endl; for(int i=0;i<FoodInfo.size();i++) { for(int j=0;j<3;j++) { cout<<FoodInfo[i][j]<<" "; } cout<<endl; } //cout<<"capacity="<<capacity<<endl; //cout<<"size:"<<FoodInfo.size()<<endl; int *minimalDist = new int[FoodInfo.size()]; //int* position = new int[FoodInfo.size()]; vector<int> position; ShortestPath(FoodInfo.size()-1,capacity,FoodInfo,minimalDist,position); for(int i=1;i<=NumOfFood;i++) { cout<<minimalDist[i]<<endl; } cout<<"postition"<<endl; for(int i=position.size()-1;i>=0;i--) { cout<<position[i]<<endl; } //cout<<FoodInfo.size()-1<<endl; cout<<"GREEDY!"<<endl; int distance = 0; Data position1; Greedy(FoodInfo,FoodInfo.size()-1,capacity,position1,distance); for(int i=0;i<position1.size();i++) { cout<<position1[i]<<endl; } cout<<"distance"<<distance<<endl; cout<<"end"<<endl; /* cout<<CapacityCheck(0 , 3 , capacity ,FoodInfo); cout<<CapacityCheck(1 , 3 , capacity ,FoodInfo); cout<<CapacityCheck(2 , 3 , capacity ,FoodInfo); cout<<CapacityCheck(3 , 3 , capacity ,FoodInfo); cout<<endl; cout<<dist2origin(0, FoodInfo)<<endl; cout<<dist2origin(1, FoodInfo)<<endl; cout<<dist2origin(2, FoodInfo)<<endl; cout<<dist2origin(3, FoodInfo)<<endl; cout<<endl; //cout<<dist(0, 0, FoodInfo)<<endl; //c//out<<dist(0, 1, FoodInfo)<<endl; //cout<<dist(1, 2, FoodInfo)<<endl; //cout<<"asd"<<dist(0, 1, FoodInfo)+dist(1, 2, FoodInfo)+dist(2, 3, FoodInfo)<<endl; */ //cout<<dist2origin(1, FoodInfo); }
bool FreezeScript::invokeMemberFunction(const string& name, const DataPtr& target, const DataList& args, DataPtr& result, const DataFactoryPtr& factory, const ErrorReporterPtr& errorReporter) { // // string // StringDataPtr targetStr = StringDataPtr::dynamicCast(target); if(targetStr) { if(name == "find") { StringDataPtr argData; IntegerDataPtr startData; if(args.size() > 0) { argData = StringDataPtr::dynamicCast(args[0]); } if(args.size() > 1) { startData = IntegerDataPtr::dynamicCast(args[1]); } if(args.size() == 0 || args.size() > 2 || !argData || (args.size() == 2 && !startData)) { errorReporter->error("invalid arguments to find(string str[, int len])"); } string targ = targetStr->stringValue(); string arg = argData->stringValue(); string::size_type pos; if(startData) { string::size_type start = static_cast<string::size_type>(startData->integerValue()); pos = targ.find(arg, start); } else { pos = targ.find(arg); } result = factory->createInteger(pos == string::npos ? -1 : static_cast<Ice::Long>(pos), false); return true; } else if(name == "substr") { IntegerDataPtr startData; IntegerDataPtr lenData; if(args.size() > 0) { startData = IntegerDataPtr::dynamicCast(args[0]); } if(args.size() > 1) { lenData = IntegerDataPtr::dynamicCast(args[1]); } if(args.size() == 0 || args.size() > 2 || !startData || (args.size() == 2 && !lenData)) { errorReporter->error("invalid arguments to substr(int start[, int len])"); } string targ = targetStr->stringValue(); string::size_type start = static_cast<string::size_type>(startData->integerValue()); string::size_type len = string::npos; if(lenData) { len = static_cast<string::size_type>(lenData->integerValue()); } if(start > targ.size()) { ostringstream ostr; ostr << "substr() starting position (" << start << ") is greater than string length (" << targ.size() << ")"; errorReporter->error(ostr.str()); } result = factory->createString(targ.substr(start, len), false); return true; } else if(name == "replace") { IntegerDataPtr startData; IntegerDataPtr lenData; StringDataPtr strData; if(args.size() == 3) { startData = IntegerDataPtr::dynamicCast(args[0]); lenData = IntegerDataPtr::dynamicCast(args[1]); strData = StringDataPtr::dynamicCast(args[2]); } if(args.size() != 3 || !startData || !lenData || !strData) { errorReporter->error("invalid arguments to replace(int start, int len, string val)"); } string targ = targetStr->stringValue(); string::size_type start = static_cast<string::size_type>(startData->integerValue()); string::size_type len = static_cast<string::size_type>(lenData->integerValue()); string str = strData->stringValue(); if(start > targ.size()) { ostringstream ostr; ostr << "replace() starting position (" << start << ") is greater than string length (" << targ.size() << ")"; errorReporter->error(ostr.str()); } result = factory->createString(targ.replace(start, len, str), false); return true; } return false; } // // Object // ObjectRefPtr targetObj = ObjectRefPtr::dynamicCast(target); if(targetObj) { if(name == "ice_isA") { ObjectDataPtr value = targetObj->getValue(); if(!value) { errorReporter->error("ice_isA() invoked on nil object"); } StringDataPtr str; if(args.size() > 0) { str = StringDataPtr::dynamicCast(args.front()); } if(args.size() != 1 || !str) { errorReporter->error("invalid arguments to ice_isA(string id)"); } string id = str->stringValue(); if(id == "::Ice::Object") { result = factory->createBoolean(true, false); return true; } Slice::ClassDeclPtr decl = Slice::ClassDeclPtr::dynamicCast(value->getType()); if(!decl) { // // Ice::Object // result = factory->createBoolean(false, false); return true; } Slice::ClassDefPtr def = decl->definition(); assert(def); result = factory->createBoolean(def->isA(id), false); return true; } return false; } return false; }
bool FreezeScript::invokeGlobalFunction(const Ice::CommunicatorPtr& communicator, const string& name, const DataList& args, DataPtr& result, const DataFactoryPtr& factory, const ErrorReporterPtr& errorReporter) { // // Global function. // if(name == "typeOf") { if(args.size() != 1) { errorReporter->error("typeOf() requires one argument"); } result = factory->createString(typeToString(args.front()->getType()), false); return true; } else if(name == "generateUUID") { if(args.size() != 0) { errorReporter->error("generateUUID() accepts no arguments"); } result = factory->createString(IceUtil::generateUUID(), false); return true; } else if(name == "stringToIdentity") { StringDataPtr str; if(args.size() > 0) { str = StringDataPtr::dynamicCast(args.front()); } if(args.size() != 1 || !str) { errorReporter->error("stringToIdentity() requires a string argument"); } // // Parse the identity string. // string idstr = str->stringValue(); Ice::Identity id; try { id = communicator->stringToIdentity(idstr); } catch(const Ice::IdentityParseException& ex) { errorReporter->error("error in stringToIdentity():\n" + ex.str); } // // Create a data representation of Ice::Identity. // Slice::UnitPtr unit = str->getType()->unit(); Slice::TypeList l = unit->lookupType("::Ice::Identity", false); assert(!l.empty()); DataPtr identity = factory->create(l.front(), false); StringDataPtr member; member = StringDataPtr::dynamicCast(identity->getMember("name")); assert(member); member->setValue(id.name); member = StringDataPtr::dynamicCast(identity->getMember("category")); assert(member); member->setValue(id.category); result = identity; return true; } else if(name == "identityToString") { StructDataPtr identity; if(args.size() > 0) { identity = StructDataPtr::dynamicCast(args.front()); } if(identity) { Slice::TypePtr argType = identity->getType(); Slice::StructPtr st = Slice::StructPtr::dynamicCast(argType); if(!st || st->scoped() != "::Ice::Identity") { identity = 0; } } if(args.size() != 1 || !identity) { errorReporter->error("identityToString() requires a argument of type ::Ice::Identity"); } // // Compose the identity. // Ice::Identity id; StringDataPtr member; member = StringDataPtr::dynamicCast(identity->getMember("name")); assert(member); id.name = member->stringValue(); member = StringDataPtr::dynamicCast(identity->getMember("category")); assert(member); id.category = member->stringValue(); result = factory->createString(communicator->identityToString(id), false); return true; } else if(name == "stringToProxy") { StringDataPtr str; if(args.size() > 0) { str = StringDataPtr::dynamicCast(args.front()); } if(args.size() != 1 || !str) { errorReporter->error("stringToProxy() requires a string argument"); } // // Parse the proxy; // string sprx = str->stringValue(); Ice::ObjectPrx prx; try { prx = factory->getCommunicator()->stringToProxy(sprx); } catch(const Ice::ProxyParseException& ex) { errorReporter->error("error in stringToProxy():\n" + ex.str); } Slice::UnitPtr unit = str->getType()->unit(); ProxyDataPtr p = ProxyDataPtr::dynamicCast(factory->create(unit->builtin(Slice::Builtin::KindObjectProxy), false)); p->setValue(prx); result = p; return true; } else if(name == "proxyToString") { ProxyDataPtr prx; if(args.size() > 0) { prx = ProxyDataPtr::dynamicCast(args.front()); } if(args.size() != 1 || !prx) { errorReporter->error("proxyToString() requires a proxy argument"); } result = factory->createString(prx->toString(), false); return true; } else if(name == "lowercase") { StringDataPtr str; if(args.size() > 0) { str = StringDataPtr::dynamicCast(args.front()); } if(args.size() != 1 || !str) { errorReporter->error("lowercase() requires a string argument"); } string val = IceUtilInternal::toLower(str->stringValue()); result = factory->createString(val, false); return true; } return false; }