int main() { scanf("%d",&N); for (int i=1;i<=N;++i) { scanf("%d",&Val(i)); Sum(i)=Ms(i)=Lms(i)=Rms(i)=Val(i); Par(i)=i-1,Rch(i-1)=i,Size(i)=N-i+1; splay(root,i); } splay(root,1),Par(N+1)=1,Lch(1)=N+1,Size(N+1)=1,splay(root,N+1); splay(root,N),Par(N+2)=N,Rch(N)=N+2,Size(N+2)=1,splay(root,N+2); tot=N+2; for (scanf("%d",&Que);Que--;) { scanf("%s%d",cmd,&x); if (cmd[0]=='D') D(Findkth(root,x+1)); else { scanf("%d",&y); if (cmd[0]=='Q') Q(Findkth(root,x),Findkth(root,y+2)); else if (cmd[0]=='I') I(Findkth(root,x+1),y); else R(Findkth(root,x+1),y); } } print_r(root); printf("\n"); print_l(root); printf("\n"); return 0; }
TEST(TNEANet, AddEdgeAttributeError) { PNEANet Graph; Graph = TNEANet::New(); TStr StrAttr("name"); TStr FltAttr("weight"); TStr IntAttr("test"); Graph->AddStrAttrE(StrAttr); Graph->AddFltAttrE(FltAttr); Graph->AddIntAttrE(IntAttr); int NumEdges = 5; for (int i = 0; i < NumEdges + 1; i++) { Graph->AddNode(i); } for (int i = 0; i < NumEdges; i++) { Graph->AddEdge(i, i+1, i); Graph->AddIntAttrDatE(i, TInt(i), IntAttr); Graph->AddFltAttrDatE(i, TFlt(i), FltAttr); TInt Val(i); Graph->AddStrAttrDatE(i, Val.GetStr(), StrAttr); } Graph->DelNode(0); for (int j = 1; j < NumEdges; j++) { ASSERT_EQ(Graph->GetIntAttrDatE(j, IntAttr), TInt(j)); ASSERT_EQ(Graph->GetFltAttrDatE(j, FltAttr), TFlt(j)); TInt Val(j); ASSERT_EQ(Graph->GetStrAttrDatE(j, StrAttr), Val.GetStr()); } }
AST(Json::Value& expr, Table *t) { op = VAL; val = Val(); switch(expr.type()) { case Json::arrayValue: { string call = expr[0].asString(); if (call == "get") { path p; for(u32 i=1; i<expr.size(); ++i) p.push_back( expr[i].asString() ); forn = t->findColumn(p); if (forn.size() == 1) { op = GET; get = forn.front(); } else if (forn.size() != 0) { op = FORN; for(auto &c: forn) if(c->type == Type::MFORN) op = MFORN; } } else { if (!determineFunc(call)) throw UnknownOperationE(call); for(u32 i=1; i<expr.size(); ++i) params.push_back(AST(expr[i], t)); } } break; case Json::objectValue: throw HashExpressionE(); break; default: val = Val(expr); } }
void CJSONWriter::Val(const CFSVar &Var) { switch (Var.GetType()) { case CFSVar::VAR_EMPTY: NullVal(); break; case CFSVar::VAR_INT: IntVal(Var.GetInt()); break; case CFSVar::VAR_FLOAT: FloatVal(Var.GetFloat()); break; case CFSVar::VAR_BOOL: BoolVal(Var.GetBool()); break; case CFSVar::VAR_STRING: StringVal(Var.GetAString()); break; case CFSVar::VAR_MAP: ObjectStart(); for (INTPTR ip=0; ip<Var.GetSize(); ip++) { CFSAString szKey=Var.GetKey(ip); Key(szKey); Val(Var[szKey]); } ObjectEnd(); break; case CFSVar::VAR_ARRAY: ArrayStart(); for (INTPTR ip=0; ip<Var.GetSize(); ip++) { Val(Var[ip]); } ArrayEnd(); break; } }
//13.<分支语句>—> if <布尔表达式> then <语句> //| if <布尔表达式> then <语句> else <语句> void switchStatement(){ if (lookahead == IF){ match(IF); TFexit tf = booleaexpression();//真假出口 match(THEN); //填真出口 BackPatch(tf.TC, sno); statementlists(); if (lookahead == ELSE){ // 1 无条件跳转 int j = sno; quadruples.push_back(Quadruple(sno++, 0,Val(),Val())); match(ELSE); //回填假出口 BackPatch(tf.FC, sno); statementlists(); //回填 1 无条件跳转 BackPatch(j, sno); } else { // 回填假出口 BackPatch(tf.FC, sno); } } else{ error(24); } }
//19. <关系表达式>—> <表达式> <关系> <表达式> TFexit relationexpression(){ Val v1 = expression(); int re = relation(); Val v2 = expression(); quadruples.push_back(Quadruple(sno++, re, v1, v2)); quadruples.push_back(Quadruple(sno++,0,Val(),Val()));//无条件跳转op=0 return TFexit(sno - 2, sno - 1); }
inline void Tupdate(int x) { Size(x)=Size(Lch(x))+1+Size(Rch(x)); Sum(x)=Sum(Lch(x))+Val(x)+Sum(Rch(x)); Lms(x)=max(Lms(Lch(x)),Sum(Lch(x))+Val(x)+Lms(Rch(x))); Rms(x)=max(Rms(Rch(x)),Rms(Lch(x))+Val(x)+Sum(Rch(x))); Ms(x)=Rms(Lch(x))+Val(x)+Lms(Rch(x)); if (Lch(x)) Ms(x)=max(Ms(x),Ms(Lch(x))); if (Rch(x)) Ms(x)=max(Ms(x),Ms(Rch(x))); }
//14.<循环语句>—> while <布尔表达式> do <语句> void loopStatement(){ match(WHILE); //int boolId = 序号全局变量 int boolId = sno; TFexit tf = booleaexpression();//真假出口 match(DO); //回填真出口 BackPatch(tf.TC, sno); statementlists(); //(j boolId) quadruples.push_back(Quadruple(sno++, 0, Val(), Val(), boolId)); //回填假出口 BackPatch(tf.FC, sno); }
int Foo (Packed &p, int i, int ui) { int r; if ((r = Val (p.i, i))) return r; if ((r = Val (p.u.i, ui))) return r + 2; if ((r = Val (p.u, ui))) return r + 4; if ((r = ConstRef (p.i, &p.i, i))) return r + 6; return 0; }
TEST(TNEANet, AddSAttrDatN_str) { PNEANet Graph; Graph = TNEANet::New(); Graph->AddNode(0); TStr Val("5"); TInt Id(0); int status = Graph->AddSAttrDatN(Id, 1, Val); EXPECT_EQ(-1, status); TInt AttrId; TStr AttrName("TestFlt"); Graph->AddSAttrN(AttrName, atStr, AttrId); TInt ErrorVal(1); status = Graph->AddSAttrDatN(Id, AttrId, ErrorVal); EXPECT_EQ(-2, status); status = Graph->AddSAttrDatN(Id, AttrId, Val); EXPECT_EQ(0, status); status = Graph->AddSAttrDatN(Id, AttrName, Val); EXPECT_EQ(0, status); TStr NewName("TestStr2"); status = Graph->AddSAttrDatN(Id, NewName, Val); EXPECT_EQ(0, status); TInt ErrorId(1); status = Graph->AddSAttrDatN(ErrorId, AttrId, Val); EXPECT_EQ(-1, status); }
//10.<赋值语句>—> id = <表达式> ; void assignment(){ char varname[MAXIDLEN]; strcpy(varname, token); Val v2 = Val(1, GetIdByName(varname)); match(id); if (!isexist(varname)){ strcpy(token, varname); error(46); } match(equl); Val v = expression(); match(semicolon); quadruples.push_back(Quadruple(sno++, equl, v, v2)); //生成四元式 /*printf("%3d (=,", sno++); if (v.type == 1) printf("%s", GetNameByID(v.value1)); else if (v.type == 0) printf("%d", v.value1); else if (v.type == 2) printf("%lf", v.value2); else printf("t%d", v.value1); printf(",%s)\n", varname);*/ }
TEST(TNEANet, AddSAttrDatE_flt) { PNEANet Graph; Graph = TNEANet::New(); Graph->AddNode(0); Graph->AddNode(1); Graph->AddEdge(0, 1, 0); TFlt Val(5.0); TInt Id(0); int status = Graph->AddSAttrDatE(Id, 1, Val); EXPECT_EQ(-1, status); TInt AttrId; TStr AttrName("TestFlt"); Graph->AddSAttrE(AttrName, atFlt, AttrId); TInt ErrorVal(1); status = Graph->AddSAttrDatE(Id, AttrId, ErrorVal); EXPECT_EQ(-2, status); status = Graph->AddSAttrDatE(Id, AttrId, Val); EXPECT_EQ(0, status); status = Graph->AddSAttrDatE(Id, AttrName, Val); EXPECT_EQ(0, status); TStr NewName("TestFlt2"); status = Graph->AddSAttrDatE(Id, NewName, Val); EXPECT_EQ(0, status); TInt ErrorId(1); status = Graph->AddSAttrDatE(ErrorId, AttrId, Val); EXPECT_EQ(-1, status); }
va_dcl #else Symbol_t* Symbol(Msg_t msg, ...) #endif { char blank[64]; String_t* image; size_t indent; Symbol_t* obj; va_init(ap, msg, obj); if (!obj) return NULL; switch (msg) { case _Init: return (Symbol_t*) Obj(_Init, obj, Symbol); case _Image: image = va_arg(ap, String_t*); if ((indent = va_arg(ap, size_t)) >= sizeof(blank)) return NULL; if (indent > 0) memset(blank, ' ', indent); blank[indent] = 0; return (Symbol_t*) String(_Cat, image, blank, "'", Val(obj), "'", 0); default: return (Symbol_t*) String(_Relay, msg, obj, ap); } }
typename LRUCacheH4<K, V>::Val * LRUCacheH4<K, V>::_insert(const K & key) { // if we have grown too large, remove LRU if (_map.size() >= _maxsize) { Val * old_lru = _lru; if (_lru->second._newer) { _lru = _lru->second._newer; _lru->second._older = NULL; } // erase takes a 'const K &', if we don't make a copy of the key, // it'll be destroied in erase, but the reference may be used // later in erase //const K k = old_lru->first; //cerr << "_map.erase, key=" << k << endl; //_map.erase(k); _map.erase(old_lru->first); } // insert key to MRU position std::pair<typename MAP_TYPE::iterator, bool> ret = _map.insert(Val(key, LRUCacheH4Value<K, V>(V(), _mru, NULL))); Val * inserted = &*ret.first; if (_mru) _mru->second._newer = inserted; _mru = inserted; // possibly update the LRU if (!_lru) _lru = _mru; else if (!_lru->second._newer) _lru->second._newer = _mru; return inserted; }
//****************************************************************************** //Name: array print * // * //Purpose: prints out the value of the array given the indices * // * //Takes: a message string and variable list of indices * //****************************************************************************** void array::print(const char *msg, int range1, ...) const { int *range, i; //Allocate space for the range array range = new int[p->num_indices]; //Initialize the variable argument list va_list arg_list; va_start(arg_list,range1); //Pack the range array range[0] = range1; for(i = 1; i < p->num_indices; i++) range[i] = va_arg(arg_list,int); double value; value = Val(range); if(*msg) cout << msg; cout << setw(6) << setprecision(3) << value; //Clean up va_end(arg_list); delete [] range; }
void init(const Key &null_value=Key(),std::size_t cache_size=10000) { cachesize=next_doubled_prime(cache_size); cache.clear(); cache.resize(cachesize,entry(null_value,Val())); assert(cache.size()==cachesize); n_miss=n_hit=0; }
void JFrame::push(jtype jt) { assert(m_top<(int)max_size()); if (jt < i32) { jt = i32; } switch (jt) { case i8: case i16: case u16: case i32: case jobj: m_stack[++m_top] = Val(jt); break; case i64: m_stack[++m_top] = Val(jt); m_stack[++m_top] = Val(jt); break; case flt32: m_stack[++m_top] = Val(jt); break; case dbl64: m_stack[++m_top] = Val(jt); m_stack[++m_top] = Val(jt); break; default: assert( jt == jretAddr ); m_stack[++m_top] = Val(jt); break; } }
inline void I(int x,int y) { splay(root,x); int v=Lch(x); for (;Rch(v);v=Rch(v)); Rch(v)=++tot,Par(tot)=v,Size(tot)=1; Sum(tot)=Ms(tot)=Lms(tot)=Rms(tot)=Val(tot)=y; splay(root,tot); }
typename DomainEnumerate<Val>::ValueId DomainEnumerate<Val>::insert(const typename Val::Value& value) { Val attr(value, this); const_iterator found = std::find( values_.begin(), values_.end(), attr ); if( found != values_.end() ) return getValueId(found); //inserts element on the end (if not found) return getValueId( values_.insert( values_.end(), Val(value, this) ) ); }
void print_r(int node) { if(!node) { printf("()"); return; } printf("("); print_r( Lch(node) ); printf(" %d ",Val(node)); print_r( Rch(node) ); printf(")"); }
void Compiler::gen_jsr(unsigned target) { AR gr = valloc(jobj); const JInst& jinst = *m_curr_inst; movp(gr, jinst.next, m_bbinfo->start); vpush(Val(jretAddr, gr)); gen_bb_leave(target); br(cond_none, target, m_bbinfo->start); }
ResolvedToken operator()(long long val)const { if( !m_EC.This.IsNull() ) { //accessing table element. E.g.: table[0] Member Val((*m_EC.This)[val]); m_EC.This = NullReference(); return boost::apply_visitor(*this,Val); } return val; }
TBool TfrLex::Eat( TLex& aLex, const TDesC& aTerm ) { aLex.SkipSpace(); TLexMark unget; aLex.Mark(unget); if ( Val(aLex,aTerm) == KErrNone ) return ETrue; aLex.UnGetToMark(unget); return EFalse; }
std::string operator()(long long val)const { if( !m_EC.This.IsNull() ) { //accessing table element. E.g.: table[0] Member Val((*m_EC.This)[val]); m_EC.This = NullReference(); return boost::apply_visitor(*this,Val); } return boost::lexical_cast<std::string>(val); }
void print_l(int node) { if(!node) { printf("XX"); return; } printf(" %d ",Val(node)); printf("("); print_l( Lch(node) ); printf(","); print_l( Rch(node) ); printf(")"); }
// Return (true, value) if key exists and (false, Val()) otherwise. std::pair<bool, Val> Find(Key key) const{ Node<Key, Val>* node = root_; while (node != NULL){ if (key == node->key){ return std::make_pair(true, node->val); } else if (Comp()(key, node->key)){ node = node->left; } else { node = node->right; } } return std::make_pair(false, Val()); }
//****************************************************************************** //Name: GetTensor * // * //Purpose: get the tensor portion of the field given the position * // * //Takes: position stored as a tensor * //****************************************************************************** tensor field::GetTensor(int *indices) { tensor temp; int n, *r, new_n, *new_r; int i, j, dummy; //Get the total number of indices and ranges of the field n = NumIndices(); r = Ranges(); //Determine the number of indices on the temp tensor new_n = n - 3; //Make a new array for resizing temp new_r = new int[new_n]; //Pack the new_r array with the for( i = 0; i < new_n; i++ ) { new_r[i] = r[i + 3]; } //Resize the temp tensor temp.Resize(new_n, new_r); //Let the r array do double duty and pack the first three elements with the //values in the indices array for( i = 0; i < 3; i++) r[i] = indices[i]; //now pack temp with the components of the tensor portion of the field for( i = 0; i < temp.p->product; i++) { //Let the last indices of the r array hold the //index structure for the temp tensor dummy = 0; for( j = 0; j < new_n; j++) { r[j + 3] = (i - i%temp.p->scales[j] - dummy)/temp.p->scales[j]; dummy += r[j + 3] * temp.p->scales[j]; } temp.p->m[i] = Val(r); } //Clean up delete [] r; delete [] new_r; //Return the tensor return temp; }
//****************************************************************************** //Name: array print * // * //Purpose: prints out the values in the whole array without indices * // * //Takes: * //****************************************************************************** void array::print(char **buffer) const { int *index, i, j, temp, num_indices, counter; //test for range = 1 indices num_indices = p->num_indices; for(i = 0; i < p->num_indices; i++) { if(p->range[i] == 1) num_indices--; } index = new int[p->num_indices]; if( *buffer != NULL ) delete [] *buffer; *buffer = new char[p->product*41 + 1]; (*buffer)[0] = '\0'; for(i = 0; i < p->product; i++) { //pack the index array testing for range = 1 cases temp = 0; for(j = 0; j < num_indices - 1; j++) { index[j] = (i - i%p->scales[j] - temp)/p->scales[j]; temp += index[j] * p->scales[j]; } //range = 1 testing starts here if( num_indices < p->num_indices) { index[num_indices - 1] = (i - temp)/p->scales[num_indices - 1]; for(j = num_indices; j < p->num_indices; j++) index[j] = 0; } else { index[j] = (i - temp)/p->scales[j]; } //fill the buffer line counter = strlen(*buffer); sprintf((*buffer)+counter,"%g\n",Val(index)); } //terminate the string properly counter = strlen(*buffer); (*buffer)[counter+1] = '\0'; //clean-up delete [] index; }
void CompilationEnvironment::load_env_var() { if ( String str = get_env( "METIL_INC_PATHS" ) ) { BasicVec<String> lst = tokenize( str, ';' ); for( int i = 0; i < lst.size(); ++i ) add_inc_path( lst[ i ] ); } if ( String str = get_env( "METIL_LIB_PATHS" ) ) { BasicVec<String> lst = tokenize( str, ';' ); for( int i = 0; i < lst.size(); ++i ) add_lib_path( lst[ i ] ); } if ( String str = get_env( "METIL_LIB_NAMES" ) ) { BasicVec<String> lst = tokenize( str, ';' ); for( int i = 0; i < lst.size(); ++i ) add_lib_name( lst[ i ] ); } if ( String str = get_env( "METIL_PARSED" ) ) { BasicVec<String> lst = tokenize( str, ';' ); for( int i = 0; i < lst.size(); ++i ) parsed << lst[ i ]; } if ( String str = get_env( "METIL_COMP_DIR" ) ) _comp_dir = str; if ( String str = get_env( "METIL_CXX" ) ) CXX = str; if ( String str = get_env( "METIL_LD" ) ) LD = str; if ( String str = get_env( "METIL_NVCC" ) ) NVCC = str; if ( String str = get_env( "METIL_CPPFLAGS" ) ) CPPFLAGS = str; if ( String str = get_env( "METIL_LDFLAGS" ) ) LDFLAGS = str; if ( String str = get_env( "METIL_DEV_EMU" ) ) device_emulation = Val( str ); if ( String str = get_env( "METIL_REG_CNT" ) ) maxrregcount = Val( str ); if ( String str = get_env( "METIL_DBG_LEVEL" ) ) dbg_level = Val( str ); if ( String str = get_env( "METIL_OPT_LEVEL" ) ) opt_level = Val( str ); if ( String str = get_env( "METIL_CXX_NAME" ) ) cxx_name = str; }
void generate_f2i_tests(std::ostream &ofs , const std::vector<llvm::APFloat> &x , bool is_signed , unsigned width) { for (unsigned i = 0, e = x.size(); i != e; ++i) { const llvm::APFloat &apf = x[i]; bool ignored; uint64_t x[2]; apf.convertToInteger(x, width, is_signed, llvm::APFloat::rmTowardZero, &ignored); llvm::APInt Val(width, 2, x); ofs << get_padded_string(apf) << " " << get_padded_string(Val) << "\n"; } }