int main() { std::vector<double> arr(257, 0.0); std::mutex named_section; std::size_t total = 0; omp::parallel_for(omp::static_schedule(), arr.begin(), arr.end(), [&total, &named_section](double& element, const omp::iteration_context& ctx) { element = (ctx.index + 1); omp::critical(named_section, [&total, element, &ctx]() { ++total; }); { std::lock_guard<std::mutex> critical(named_section); // lock_guard is usually a better alternative to omp::critical. } omp::critical([]() { }); }, 8); omp::parallel_for(omp::dynamic_schedule(), omp::sequence_iterator(-2), omp::sequence_iterator(5), [&total, &named_section](int& element, const omp::iteration_context& ctx) { std::lock_guard<std::mutex> critical(named_section); ++total; }, 3); std::cout << total << std::endl; assert(total == 264); unsigned num_threads = 8; omp::parallel([](std::size_t thread_idx) { }, num_threads); return 0; }
void MeshSaverImplv1_0::WriteVertexBufferData(MeshBuffer* buffer, uint32 numVB, ChunkOutputStream& outStream) { ByteStream bytes; for (uint32 i = 0; i < numVB; ++i) { OutputSerializer& ser = outStream.BeginChunk(MCID_VERTEX_BUFFER_DATA); uint32 vertexCount = buffer->GetVertexCount(); uint32 vertexStride = buffer->GetVertexStride(i); uint32 bufferSize = vertexCount * vertexStride; uint16 streamIndex = (uint16)i; ser << bufferSize << vertexCount << streamIndex << vertexStride; buffer->GetVertices(i, bytes); OutputSerializer::UByteArray arr(bytes.data(), (uint32)bytes.size()); NEX_ASSERT(arr.second == bufferSize); ser << arr; outStream.EndChunk(); } }
thread_safe_page *complete_cached_req(io_request *req, thread_safe_page *p, io_interface *io, join_compute_allocator *compute_alloc, std::vector<io_request> &requests) { if (req->get_req_type() == io_request::BASIC_REQ) { int page_off; thread_safe_page *ret = NULL; char *req_buf; int req_size; page_off = req->get_offset() - ROUND_PAGE(req->get_offset()); req_buf = req->get_buf(); req_size = req->get_size(); p->lock(); if (req->get_access_method() == WRITE) { memcpy((char *) p->get_data() + page_off, req_buf, req_size); if (!p->set_dirty(true)) ret = p; } else /* I assume the data I read never crosses the page boundary */ memcpy(req_buf, (char *) p->get_data() + page_off, req_size); p->unlock(); return ret; } else { simple_page_byte_array arr(req, p); user_compute *compute = req->get_compute(); compute->run(arr); compute_alloc->set_compute(compute); compute->fetch_requests(io, compute_alloc, requests); compute_alloc->set_compute(NULL); // If no one else is referencing the user compute, it means the computation // is complete now. if (compute->get_ref() == 0) { compute_allocator *alloc = compute->get_allocator(); alloc->free(compute); } return NULL; } }
int main() { Geom_traits_2 traits; Arrangement_2 arr(&traits); Geom_traits_2::Construct_curve_2 polyline_construct = traits.construct_curve_2_object(); Point_2 points1[5]; points1[0] = Point_2(0, 0); points1[1] = Point_2(2, 4); points1[2] = Point_2(3, 0); points1[3] = Point_2(4, 4); points1[4] = Point_2(6, 0); Polyline_2 pi1 = polyline_construct(&points1[0], &points1[5]); std::list<Point_2> points2; points2.push_back(Point_2(1, 3)); points2.push_back(Point_2(0, 2)); points2.push_back(Point_2(1, 0)); points2.push_back(Point_2(2, 1)); points2.push_back(Point_2(3, 0)); points2.push_back(Point_2(4, 1)); points2.push_back(Point_2(5, 0)); points2.push_back(Point_2(6, 2)); points2.push_back(Point_2(5, 3)); points2.push_back(Point_2(4, 2)); Polyline_2 pi2 = polyline_construct(points2.begin(), points2.end()); std::vector<Segment_2> segs; segs.push_back(Segment_2(Point_2(0, 2), Point_2(1, 2))); segs.push_back(Segment_2(Point_2(1, 2), Point_2(3, 6))); segs.push_back(Segment_2(Point_2(3, 6), Point_2(5, 2))); Polyline_2 pi3 = polyline_construct(segs.begin(), segs.end()); insert(arr, pi1); insert(arr, pi2); insert(arr, pi3); print_arrangement(arr); return 0; }
void VJSLanguageSyntaxTester::_GetSyntaxColoring( XBOX::VJSParms_callStaticFunction &ioParams, void * ) { // We expect two parameters -- the extension for the type of information we have (js, html, etc) and // a line of text to be colored. We will perform the coloring, and return back to the user a list // of objects that contain the style information. if (ioParams.CountParams() < 2) return; VString extension, data; if (!ioParams.GetStringParam( 1, extension )) return; if (!ioParams.GetStringParam( 2, data )) return; CLanguageSyntaxComponent *languageSyntax = (CLanguageSyntaxComponent *)VComponentManager::RetainComponent( (CType)CLanguageSyntaxComponent::Component_Type ); if (!languageSyntax) return; ISyntaxInterface *syntaxEngine = languageSyntax->GetSyntaxByExtension( extension ); if (syntaxEngine) { // Now that we've got the syntax engine, we can ask it for the coloring information std::vector< size_t > offsets; std::vector< size_t > lengths; std::vector< sLONG > styles; syntaxEngine->GetColoringForTesting( data, offsets, lengths, styles ); // Loop over the returned results, turning them into a vector of VJSValue objects std::vector< VJSValue > results; std::vector< JSColorResult * > releaseList; for (size_t i = 0; i < offsets.size(); i++) { JSColorResult *result = new JSColorResult( offsets[ i ], lengths[ i ], styles[ i ] ); releaseList.push_back( result ); results.push_back( VJSLanguageSyntaxTesterColorResults::CreateInstance( ioParams.GetContextRef(), result ) ); } // Return an array of our results VJSArray arr( ioParams.GetContextRef() ); arr.PushValues( results ); ioParams.ReturnValue( arr ); for (std::vector< JSColorResult * >::iterator iter = releaseList.begin(); iter != releaseList.end(); ++iter) { (*iter)->Release(); } } languageSyntax->Release(); }
void DetermineBestThreadsNum() { for (unsigned i = 0; i < 3; ++i) { std::ofstream fquick, fmerge; openFiles(fquick, fmerge, i); unsigned arrSize = sizes[i]; unsigned repeatCnt = runs[i]; std::cerr << "Array size: " << arrSize; for (int tnum = 1; tnum < 30; ++ tnum) { CSimpleArray arr(arrSize); omp_set_num_threads(tnum); std::cerr << "*"; fmerge << tnum << " " << RunManyTimes(arr, repeatCnt, EMerge) << "\n"; fquick << tnum << " " << RunManyTimes(arr, repeatCnt, EQuick) << "\n"; } std::cerr << "\n"; fquick.close(); fmerge.close(); } }
vector<int> Solution::lszero(vector<int> &A) { vector<int> ans; if(A.size()==0 ) return ans; int sum=0,n=A.size(); vector<int> arr(n); map<int,int> m; map<int,int>:: iterator it; int maxlen=INT_MIN; for(int i=0;i<n;i++) { sum+=A[i]; if(sum==0) { if(i+1 >maxlen) maxlen=i+1; ans.clear(); for(int k=0;k<=i;k++) ans.push_back(A[k]); } arr[i]=sum; } for(int i=0;i<n;i++) { it=m.find(arr[i]); if(it==m.end()) m.insert(pair<int,int>(arr[i],i)); else { if(i!=it->second && (i-(it->second))>maxlen) { maxlen=i-(it->second); ans.clear(); for(int k=it->second+1;k<=i;k++) ans.push_back(A[k]); } } } return ans; }
int lengthOfLongestSubstring(string s) { // Start typing your C/C++ solution below // DO NOT write int main() function int res=1; int n=s.length(); if(n==0) return 0; vector<int> arr(26,0); int cross=0; int i=0, j=0; while(i<=j && j<n) { if(cross==0) { if(arr[s[j]-'a']==0) { arr[s[j]-'a']=1; int tmp=j-i+1; if(tmp>res) res=tmp; j++; } else { arr[s[j]-'a']++; cross++; j++; } } else { arr[s[i]-'a']--; if(arr[s[i]-'a']==1) cross--; i++; } } return res; }
void Plasm::convertOldXml(char* infilename,char* outfilename,char* prefix) { ::prefix=std::string(prefix); TiXmlDocument doc; unsigned long filesize; unsigned char* buff=FileSystem::ReadFile(infilename,filesize,true); if (!doc.Parse((const char*)buff)) { MemPool::getSingleton()->free(filesize,buff); Utils::Error(HERE,"Failed to open XML fle %s [%d] %s",infilename,doc.ErrorRow(),doc.ErrorDesc()); } MemPool::getSingleton()->free(filesize,buff); TiXmlNode* xnode=doc.FirstChild(); const char* xname=xnode->Value(); XgeReleaseAssert(!strcmpi(xname,"mesh")); //geometry std::map<int, SmartPointer<Vector > > arrays; TiXmlNode* xgeometry=getChild(xnode,"arrays"); for (TiXmlNode* xchild= xgeometry->FirstChild(); xchild != 0; xchild = xchild->NextSibling()) { XgeReleaseAssert(!strcmpi(xchild->Value(),"array")); int id =atoi(getAttribute(xchild,"id" )->Value()); int size =atoi(getAttribute(xchild,"size")->Value()); SmartPointer<Vector> arr(new Vector(size)); Vector::parse(size,arr->mem(),xchild->FirstChild()->Value(),(char*)"%e"); arrays[id]=arr; } SmartPointer<Hpc> hpc=openXmlNode(getChild(xnode,"node"),arrays); Log::printf("Opened XML file %s\n",infilename); Plasm::save(hpc,outfilename); }
void VJSGroup::_removeFrom(VJSParms_callStaticFunction& ioParms, CUAGGroup* inGroup) { VError err = VE_OK; sLONG nbparam = ioParms.CountParams(); for (sLONG i = 1; i <= nbparam /*&& err == VE_OK*/; i++) { if (ioParms.IsArrayParam(i)) { VJSArray arr(ioParms.GetContext(), nil, false); ioParms.GetParamArray(i, arr); sLONG nbelem = arr.GetLength(); for (sLONG j = 0; j < nbelem; ++j) { VJSValue val(arr.GetValueAt(j)); if (val.IsString()) { VString s; val.GetString(s); err = removeGroupFromGroup(ioParms, inGroup, s); } else /*if (val.IsInstanceOf("Group"))*/ { CUAGGroup* group = val.GetObjectPrivateData<VJSGroup>(); if (group != nil) err = inGroup->RemoveFromGroup(group); } } } else if (ioParms.IsStringParam(i)) { VString s; ioParms.GetStringParam(i, s); err = removeGroupFromGroup(ioParms, inGroup, s); } else { CUAGGroup* group = ioParms.GetParamObjectPrivateData<VJSGroup>(i); err = inGroup->RemoveFromGroup(group); } } }
// First Solution: Time Complexity: O(M+N) double findMedianSortedArrays(vector<int>& nums1, vector<int>& nums2) { const int M = nums1.size(); const int N = nums2.size(); if (nums1.empty()) return N % 2 == 1 ? nums2[(N - 1) / 2] : (double)(nums2[N / 2] + nums2[(N - 1) / 2]) / 2; if (nums2.empty()) return M % 2 == 1 ? nums1[(M - 1) / 2] : (double)(nums1[M / 2] + nums1[(M - 1) / 2]) / 2; vector<int> arr(M + N); int i, j, k; i = j = k = 0; for (; i < M && j < N;) arr[k++] = nums1[i] < nums2[j] ? nums1[i++] : nums2[j++]; while (i < M) arr[k++] = nums1[i++]; while (j < N) arr[k++] = nums2[j++]; return (M + N) % 2 == 1 ? arr[(M + N - 1) / 2] : (double)(arr[(M + N - 1) / 2] + arr[(M + N) / 2]) / 2; }
python::object TailGF::__factory_from_dict__(const python::object & dic){ python::dict d(dic); int omin= python::extract<int>(d["OrderMinMIN"]); int omax= python::extract<int>(d["OrderMaxMAX"]); int omax2= python::extract<int>(d["OrderMax"]); python::list indL, indR; if (d.has_key("Indices")) { indL = obj_or_string_to_list( d["Indices"]); //indL = python::list(d["Indices"]); indR = indL; } else { indL = obj_or_string_to_list(d["IndicesL"]); indR = obj_or_string_to_list(d["IndicesR"]); //indL = python::list(d["IndicesL"]); //indR = python::list(d["IndicesR"]); } python::object arr(d["array"]); PyArray<COMPLEX,3> ARR(arr); if (ARR.extent(0) !=( omax - omin +1)) TRIQS_RUNTIME_ERROR<<"Reconstruction : Inconsistent data for TailGF"; return python::object(TailGF(omin,omax,arr,omax2,indL,indR)); }
/** Create an AFileDialog */ AFileDialog::AFileDialog( const QString &caption, const QString &directory, const QString &filter ) : QFileDialog( 0, caption, directory, filter ) { QSettings settings; QByteArray arr( settings.value( "fileDialog" ).toByteArray() ); QRect oldRct( geometry() ); QRect lgRct( oldRct ); if( QApplication::activeWindow() ) { lgRct = QApplication::activeWindow()->normalGeometry(); } oldRct.moveCenter( lgRct.center() ); QRect rect( settings.value( "fileDialogRect", oldRct ).toRect() ); if( !arr.isEmpty() ) { restoreState( arr ); } setGeometry( rect ); }
GlobalNameValueTableWrapper::GlobalNameValueTableWrapper( NameValueTable* tab) : NameValueTableWrapper(tab) { Variant arr(staticEmptyArray()); #define X(s,v) tab->set(makeStaticString(#s), v.asTypedValue()); X(argc, init_null_variant); X(argv, init_null_variant); X(_SERVER, arr); X(_GET, arr); X(_POST, arr); X(_COOKIE, arr); X(_FILES, arr); X(_ENV, arr); X(_REQUEST, arr); X(HTTP_RAW_POST_DATA, init_null_variant); X(http_response_header, init_null_variant); #undef X g_variables = this; }
cnpy::NpyArray load_the_npy_file(FILE* fp) { std::vector<size_t> shape; size_t word_size; char arrayType; bool fortran_order; cnpy::parse_npy_header(fp,word_size, arrayType, shape,fortran_order); cnpy::NpyArray arr(shape, word_size, arrayType, fortran_order); size_t nread = fread(arr.data<char>(),1,arr.num_bytes(),fp); if(nread != arr.num_bytes()) throw std::runtime_error("load_the_npy_file: failed fread"); if ( fortran_order ){ arr.convert_to_c_order(); arr.fortran_order=false; } return arr; }
PBWT *pbwtSubSites (PBWT *pOld, double fmin, double frac) { int M = pOld->M ; PBWT *pNew = pbwtCreate (M, 0) ; int i, j, k, thresh = M*(1-fmin) ; double bit = 0.0 ; uchar *x ; PbwtCursor *uOld = pbwtCursorCreate (pOld, TRUE, TRUE) ; PbwtCursor *uNew = pbwtCursorCreate (pNew, TRUE, TRUE) ; if (!pOld || !pOld->yz) die ("subsites without an existing pbwt") ; if (fmin < 0 || fmin >= 1 || frac <= 0 || frac > 1) die ("fmin %f, frac %f for subsites out of range\n", fmin, frac) ; x = myalloc (M, uchar) ; if (pOld->sites) pNew->sites = arrayCreate (4096, Site) ; for (i = 0 ; i < pOld->N ; ++i) { if ((uOld->c < thresh) && ((bit += frac) > 1.0)) { for (j = 0 ; j < M ; ++j) x[uOld->a[j]] = uOld->y[j] ; for (j = 0 ; j < M ; ++j) uNew->y[j] = x[uNew->a[j]] ; pbwtCursorWriteForwards (uNew) ; if (pOld->sites) array(pNew->sites, pNew->N, Site) = arr(pOld->sites, i, Site) ; ++pNew->N ; bit -= 1.0 ; } pbwtCursorForwardsRead (uOld) ; } pbwtCursorToAFend (uNew, pNew) ; fprintf (logFile, "subsites with fmin %f, frac %f leaves %d sites\n", fmin, frac, pNew->N) ; pNew->chrom = pOld->chrom ; pOld->chrom = 0 ; pNew->samples = pOld->samples ; pOld->samples = 0 ; pNew->missingOffset = pOld->missingOffset ; pOld->missingOffset = 0 ; pNew->zMissing = pOld->zMissing ; pOld->zMissing = 0 ; pbwtDestroy (pOld) ; pbwtCursorDestroy (uOld) ; pbwtCursorDestroy (uNew) ; free(x) ; return pNew ; }
void VJSUser::_putInto(VJSParms_callStaticFunction& ioParms, CUAGUser* inUser) { VError err = VE_OK; sLONG nbparam = ioParms.CountParams(); for (sLONG i = 1; i <= nbparam /*&& err == VE_OK*/; i++) { if (ioParms.IsArrayParam(i)) { VJSArray arr(ioParms.GetContextRef(), nil, false); ioParms.GetParamArray(i, arr); sLONG nbelem = arr.GetLength(); for (sLONG j = 0; j < nbelem; ++j) { VJSValue val(arr.GetValueAt(j)); if (val.IsString()) { VString s; val.GetString(s); err = putUserIntoGroup(ioParms, inUser, s); } else if (val.IsInstanceOf("Group")) { CUAGGroup* group = val.GetObjectPrivateData<VJSGroup>(); err = inUser->PutIntoGroup(group); } } } else if (ioParms.IsStringParam(i)) { VString s; ioParms.GetStringParam(i, s); err = putUserIntoGroup(ioParms, inUser, s); } else { CUAGGroup* group = ioParms.GetParamObjectPrivateData<VJSGroup>(i); err = inUser->PutIntoGroup(group); } } }
bool AGActivities::generateRandomTraffic() { //total number of trips during the whole simulation int totalTrips = 0, ttOneDayTrips = 0, ttDailyTrips = 0; std::list<AGTrip>::iterator it; for (it = trips.begin(); it != trips.end(); ++it) { if (it->isDaily()) { ++ttDailyTrips; } else { ++ttOneDayTrips; } } totalTrips = ttOneDayTrips + ttDailyTrips * nbrDays; //TESTS std::cout << "Before Random traffic generation (days are still entire):" << std::endl; std::cout << "- Total number of trips: " << totalTrips << std::endl; std::cout << "- Total daily trips: " << ttDailyTrips << std::endl; std::cout << "- Total one-day trips: " << ttOneDayTrips << std::endl; //END OF TESTS //random uniform distribution: int nbrRandUni = (int)((float)totalTrips * myCity->statData.uniformRandomTrafficRate / (1.0f - myCity->statData.uniformRandomTrafficRate)); //TESTS std::cout << "added uniform random trips: " << nbrRandUni << std::endl; //END OF TESTS for (int i = 0; i < nbrRandUni; ++i) { AGPosition dep(myCity->getRandomStreet()); AGPosition arr(myCity->getRandomStreet()); AGTime depTime(RandHelper::rand(nbrDays * 86400)); AGTrip rdtr(dep, arr, generateName(i, "randUni"), depTime.getTime() % 86400, depTime.getDay() + 1); rdtr.setType("random"); trips.push_back(rdtr); } //random proportional distribution: //float proportionalPercentage = 0.05f; //TODO generate a proportionally distributed random traffic return true; }
static int nidium_timerng_wrapper(void *arg) { struct nidium_sm_timer *params = static_cast<struct nidium_sm_timer *>(arg); JSAutoRequest ar(params->cx); JS::RootedValue rval(params->cx); JS::AutoValueVector arr(params->cx); JS::RootedValue func(params->cx, params->func); JS::RootedObject global(params->cx, params->global); arr.resize(params->argc); for (int i = 0; i < params->argc; i++) { arr[i].set(params->argv[i]->get()); } JS_CallFunctionValue(params->cx, global, func, arr, &rval); // timers_stats_print(&((ape_global // *)JS_GetContextPrivate(params->cx))->timersng); return params->ms; }
GlobalNameValueTableWrapper::GlobalNameValueTableWrapper( NameValueTable* tab) : NameValueTableWrapper(tab) { Variant arr(HphpArray::GetStaticEmptyArray()); #define X(s,v) tab->set(StringData::GetStaticString(#s), v.asTypedValue()); X(argc, init_null_variant); X(argv, init_null_variant); X(_SERVER, arr); X(_GET, arr); X(_POST, arr); X(_COOKIE, arr); X(_FILES, arr); X(_ENV, arr); X(_REQUEST, arr); X(_SESSION, arr); X(HTTP_RAW_POST_DATA, init_null_variant); X(http_response_header, init_null_variant); #undef X ThreadInfo::s_threadInfo->m_globals = g_variables = this; }
// --------------------------------------------------------------------------- // // ------------ bGenericXMLBaseElement* bXMapTopoCheck::make_p(){ bArray arr(sizeof(xmlelt)); add_cdesc(arr,0,"param",""); add_cdesc(arr,1,"version","3.0.0"); bGenericType* tp; char nm[256]; for(long i=1;i<=_types.count();i++){ tp=NULL; _types.get(i,&tp); if(tp){ tp->name(nm); add_cdesc(arr,1,"name",nm); } } add_idesc(arr,1,"bool",_prm.activated); bGenericXMLBaseElement* root=_gapp->classMgr()->ParseXMLDescriptors(&arr); free_descs(arr); return(root); }
// --------------------------------------------------------------------------- // Destructeur // ----------- bMacMapType::~bMacMapType(){ _bTrace_("bMacMapType::~bMacMapType",true); _tm_("deleting "+_idx+" "+_name); if(_iter){ bMacMapGeoElement* geo; bArray arr(sizeof(bMacMapGeoElement*)); char cftitle[__MESSAGE_STRING_LENGTH_MAX__]; char cfprompt[__MESSAGE_STRING_LENGTH_MAX__]; message_string(kMsgClose,cftitle,true); strcpy(cfprompt,_name); _tm_("iterate"); _iter->iterate(&arr,add_to_array); _tm_("flush iterator"); _iter->flush(); _tm_((int)arr.count()+" objects to delete"); bProgressWait wait(cftitle,cfprompt,true,false,arr.count()); for(long i=1;i<=arr.count();i++){ //_tm_(i); wait.set_progress(i); if(arr.get(i,&geo)){ delete geo; } } arr.reset(); _tm_("deleting _iter"); extmgr->get_component(kComponentGeoIterator)->i_free(_iter); } if(_styles){ _tm_("deleting _styles"); _styles->unload(); delete _styles; } }
void sqlite3::exec(call_context & x) { local_root_scope scope; if (x.arg.size() != 1 && x.arg.size() != 2) { throw exception ("SQLite3.exec() requires at least 1 argument"); } if ( x.arg[0].is_string() ) { object data = create<object>(); data.set_property("sql", x.arg[0].get_string() ); if ( x.arg.size() > 1 ) { data.set_property( "bind", x.arg[1].to_object() ); } array arr(create<array>(list_of(data))); x.result = exec_internal( arr ); } else { throw exception("The first parameter of SQLite3.exec() requires to be" " a string containing an SQL statement"); } }
// --------------------------------------------------------------------------- // // ----------- bool bPrintMgr::write(){ _bTrace_("bPrintMgr::write",false); bArray arr(sizeof(xmlelt)); add_cdesc(arr,0,"param",""); add_cdesc(arr,1,"version","3.0"); add_idesc(arr,1,"int",_area.left); add_idesc(arr,1,"int",_area.top); add_idesc(arr,1,"int",_area.right); add_idesc(arr,1,"int",_area.bottom); bGenericXMLBaseElement* root=clssmgr->ParseXMLDescriptors(&arr); free_descs(arr); if(!root){ _te_("root == NULL"); return(false); } if(!map_doc->writeTree(root,kPrintSignature,kPrintConfigName)){ _te_("writeTree failed"); clssmgr->ReleaseXMLInstance(root); return(false); } clssmgr->ReleaseXMLInstance(root); return(true); }
//----------------------------------------------------------- void OprtColon::Eval(ptr_val_type& ret, const ptr_val_type *a_pArg, int num) { assert(num==2); const IValue *argMin = a_pArg[0].Get(); const IValue *argMax = a_pArg[1].Get(); if (!argMin->IsNonComplexScalar()) throw ParserError( ErrorContext(ecTYPE_CONFLICT_FUN, -1, GetIdent(), argMin->GetType(), 'i', 1)); if (!argMax->IsNonComplexScalar()) throw ParserError( ErrorContext(ecTYPE_CONFLICT_FUN, -1, GetIdent(), argMax->GetType(), 'i', 1)); if (*argMax < *argMin) throw ParserError(_T("Colon operator: Maximum value smaller than Minimum!")); int n = (argMax->GetFloat() - argMin->GetFloat()) + 1; matrix_type arr(n); for (int i=0; i<n; ++i) arr.At(i) = argMin->GetFloat() + i; *ret = arr; }
void GSTM::selection(GAIndividual<CodeVInt> &indivl1, GAIndividual<CodeVInt> &indivl2) { vector<int> arr(m_popsize); int i, j, local = -1; for (i = 0; i<m_popsize; i++) arr[i] = i; for (i = 0; i<2; i++) { double min = DBL_MAX; for (j = 0; j<m_selectK; j++) { int pos = Global::msp_global->getRandInt(0, m_popsize - 1 - j); if (min> m_pop[arr[pos]]->data().m_obj[0]) { min = m_pop[arr[pos]]->data().m_obj[0]; local = arr[pos]; } arr[pos] = arr[m_popsize - 1 - j]; } if (i == 0) indivl1 = *m_pop[local]; if (i == 1) indivl2 = *m_pop[local]; } }
GlobalsArray::GlobalsArray(NameValueTable* tab) : ArrayData(kGlobalsKind) , m_tab(tab) { Variant arr(staticEmptyArray()); #define X(s,v) tab->set(makeStaticString(#s), v.asTypedValue()); X(argc, init_null_variant); X(argv, init_null_variant); X(_SERVER, arr); X(_GET, arr); X(_POST, arr); X(_COOKIE, arr); X(_FILES, arr); X(_ENV, arr); X(_REQUEST, arr); X(_SESSION, arr); X(HTTP_RAW_POST_DATA, init_null_variant); #undef X g_variables.set(this); assertx(hasExactlyOneRef()); }
void ServerThread::handleArchive(const Packet &headerPacket) { quint64 start = msystime(); Command::FileHeaderData header; headerPacket.as(header); const bool good = QString(header.metadata) == "kar"; std::ostringstream file(std::ios::binary); if(!m_proto->confirmFile(good)) return; if(!good) return; emit stateChanged(tr("Receiving Program...")); if(!m_proto->recvFile(header.size, &file, 1000)) { qWarning() << "recvFile failed"; return; } quint64 end = msystime(); qDebug() << "Took" << (end - start) << "milliseconds to recv"; std::string data = file.str(); QByteArray arr(data.c_str(), data.size()); QDataStream stream(arr); Kiss::Kar *archive = new Kiss::Kar(); stream >> *archive; m_archive = Kiss::KarPtr(archive); m_archiveLocation = header.dest; qDebug() << "archiveLocation" << m_archiveLocation; m_executable = QString(); emit stateChanged(tr("Received Program.")); }
//----------------------------------------------------------------------------- // Replace references //----------------------------------------------------------------------------- static void BuildStartingDefList( CDmElement *pElement, CDmElement *pOldVersion, CDmElement *pNewVersion ) { for ( CDmAttribute *pAtt = pElement->FirstAttribute(); pAtt; pAtt = pAtt->NextAttribute() ) { if ( pAtt->GetType() == AT_ELEMENT ) { CDmElement *pCurrent = pAtt->GetValueElement<CDmElement>(); if ( pCurrent == pOldVersion ) { pAtt->SetValue( pNewVersion ); } else { ReplaceChildReferences( pCurrent, pOldVersion, pNewVersion ); } continue; } if ( pAtt->GetType() == AT_ELEMENT_ARRAY ) { CDmrElementArray<> arr( pAtt ); int nCount = arr.Count(); for ( int i = 0; i < nCount; ++i ) { if ( arr[i] == pOldVersion ) { arr.Set( i, pNewVersion ); } else { ReplaceChildReferences( arr[i], pOldVersion, pNewVersion ); } } continue; } } }
void MigrationChunkClonerSourceLegacy::_xfer(OperationContext* txn, Database* db, std::list<BSONObj>* docIdList, BSONObjBuilder* builder, const char* fieldName, long long* sizeAccumulator, bool explode) { const long long maxSize = 1024 * 1024; if (docIdList->size() == 0 || *sizeAccumulator > maxSize) { return; } const std::string& ns = _args.getNss().ns(); BSONArrayBuilder arr(builder->subarrayStart(fieldName)); std::list<BSONObj>::iterator docIdIter = docIdList->begin(); while (docIdIter != docIdList->end() && *sizeAccumulator < maxSize) { BSONObj idDoc = *docIdIter; if (explode) { BSONObj fullDoc; if (Helpers::findById(txn, db, ns.c_str(), idDoc, fullDoc)) { arr.append(fullDoc); *sizeAccumulator += fullDoc.objsize(); } } else { arr.append(idDoc); *sizeAccumulator += idDoc.objsize(); } docIdIter = docIdList->erase(docIdIter); } arr.done(); }