当前位置: 首页>>代码示例>>C++>>正文


C++ vec类代码示例

本文整理汇总了C++中vec的典型用法代码示例。如果您正苦于以下问题:C++ vec类的具体用法?C++ vec怎么用?C++ vec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了vec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: mid

inline vec mid(const vec&v, int start, int num){
  return v.segment(start, std::min(num, (int)(v.size()-start)));
}
开发者ID:Prokopp,项目名称:graphchi-cpp,代码行数:3,代码来源:eigen_wrapper.hpp

示例2: sort

inline void sort(vec & a){
  std::sort(a.data(), a.data()+a.size());
}
开发者ID:Prokopp,项目名称:graphchi-cpp,代码行数:3,代码来源:eigen_wrapper.hpp

示例3: buildConstraint

static
void buildConstraint(vec<Formula>& ps, vec<Int>& Cs, vec<Formula>& carry, vec<int>& base, int digit_no, vec<vec<Formula> >& out_digits, int max_cost)
{
    assert(ps.size() == Cs.size());

    if (FEnv::topSize() > max_cost) throw Exception_TooBig();
    /**
    pf("buildConstraint(");
    for (int i = 0; i < ps.size(); i++)
        pf("%d*%s ", Cs[i], (*debug_names)[index(ps[i])]);
    pf("+ %d carry)\n", carry.size());
    **/

    if (digit_no == base.size()){
        // Final digit, build sorter for rest:
        // -- add carry bits:
        for (int i = 0; i < carry.size(); i++)
            ps.push(carry[i]),
            Cs.push(1);
        out_digits.push();
        buildSorter(ps, Cs, out_digits.last());

    }else{
        vec<Formula>    ps_rem;
        vec<int>        Cs_rem;
        vec<Formula>    ps_div;
        vec<Int>        Cs_div;

        // Split sum according to base:
        int B = base[digit_no];
        for (int i = 0; i < Cs.size(); i++){
            Int div = Cs[i] / Int(B);
            int rem = toint(Cs[i] % Int(B));
            if (div > 0){
                ps_div.push(ps[i]);
                Cs_div.push(div);
            }
            if (rem > 0){
                ps_rem.push(ps[i]);
                Cs_rem.push(rem);
            }
        }

        // Add carry bits:
        for (int i = 0; i < carry.size(); i++)
            ps_rem.push(carry[i]),
            Cs_rem.push(1);

        // Build sorting network:
        vec<Formula> result;
        buildSorter(ps_rem, Cs_rem, result);

        // Get carry bits:
        carry.clear();
        for (int i = B-1; i < result.size(); i += B)
            carry.push(result[i]);

        out_digits.push();
        for (int i = 0; i < B-1; i++){
            Formula out = _0_;
            for (int j = 0; j < result.size(); j += B){
                int n = j+B-1;
                if (j + i < result.size())
                    out |= result[j + i] & ((n >= result.size()) ? _1_ : ~result[n]);
            }
            out_digits.last().push(out);
        }

        buildConstraint(ps_div, Cs_div, carry, base, digit_no+1, out_digits, max_cost); // <<== change to normal loop
    }
}
开发者ID:bytekid,项目名称:mkbtt,代码行数:71,代码来源:PbSolver_convertSort.C

示例4: optimizeBase

static
void optimizeBase(vec<Int>& seq, int carry_ins, vec<Int>& rhs, int cost, vec<int>& base, int& cost_bestfound, vec<int>& base_bestfound)
{
    if (cost >= cost_bestfound)
        return;

    // "Base case" -- don't split further, build sorting network for current sequence:
    int final_cost = 0;
    for (int i = 0; i < seq.size(); i++){
        if (seq[i] > INT_MAX)
            goto TooBig;
      #ifdef ExpensiveBigConstants
        final_cost += toint(seq[i]);
      #else
        int c; for (c = 1; c*c < seq[i]; c++);
        final_cost += c;
      #endif
        if (final_cost < 0)
            goto TooBig;
    }
    if (cost + final_cost < cost_bestfound){
        base.copyTo(base_bestfound);
        cost_bestfound = cost + final_cost;
    }
  TooBig:;

    /**/static int depth = 0;

    // <<== could count 1:s here for efficiency

    vec<Int> new_seq;
    vec<Int> new_rhs;
#ifdef PickSmallest
    int p = -1;
    for (int i = 0; i < seq.size(); i++)
        if (seq[i] > 1){ p = seq[i]; break; }
    if (p != -1){
#else
    //int upper_lim = (seq.size() == 0) ? 1 : seq.last(); // <<== Check that sqRoot is an 'int' (no truncation of 'Int')
    //for (int i = 0; i < (int)elemsof(primes) && primes[i] <= upper_lim; i++){
    for (int i = 0; i < (int)elemsof(primes); i++){
        int p    = primes[i];
#endif
        int rest = carry_ins;   // Sum of all the remainders.
        Int div, rem;

        /**/for (int n = depth; n != 0; n--) pf("  "); pf("prime=%d   carry_ins=%d\n", p, carry_ins);
        /**/for (int n = depth; n != 0; n--) pf("  "); pf("New seq:");
        for (int j = 0; j < seq.size(); j++){
            rest += toint(seq[j] % Int(p));
            div = seq[j] / Int(p);
            if (div > 0)
                //**/pf(" %d", div),
                new_seq.push(div);
        }
        /**/pf("\n");
        /**/for (int n = depth; n != 0; n--) pf("  "); pf("rest=%d\n", rest);

        /**/for (int n = depth; n != 0; n--) pf("  "); pf("New rhs:");
#ifdef AllDigitsImportant
        bool    digit_important = true;
#else
        bool    digit_important = false;
#endif
        for (int j = 0; j < rhs.size(); j++){
            div = rhs[j] / p;
            if (new_rhs.size() == 0 || div > new_rhs.last()){
                rem = rhs[j] % p;
                /**/pf(" %d:%d", div, rem),
                new_rhs.push(div);
                if (!(rem == 0 && rest < p) && !(rem > rest))
                    digit_important = true;
            }
            /* <<==
            om 'rhs' slutar på 0:a och 'rest' inte kan overflowa, då behövs inte det sorterande nätverket för 'rest' ("always TRUE")
            samma sak om 'rhs' sista siffra är strikt större än 'rest' ("never TRUE")
            */
        }
        /**/pf("\n\n");

        base.push(p);
        /**/depth++;
        optimizeBase(new_seq, rest/p, new_rhs, cost+(digit_important ? rest : 0), base, cost_bestfound, base_bestfound);
        /**/depth--;
        base.pop();

        new_seq.clear();
        new_rhs.clear();
    }
}


static
void optimizeBase(vec<Int>& seq, vec<Int>& rhs, int& cost_bestfound, vec<int>& base_bestfound)
{
    vec<int>    base;
    cost_bestfound = INT_MAX;
    base_bestfound.clear();
    optimizeBase(seq, 0, rhs, 0, base, cost_bestfound, base_bestfound);
}
开发者ID:bytekid,项目名称:mkbtt,代码行数:100,代码来源:PbSolver_convertSort.C

示例5: ggc_register_root_tab

void
ggc_register_root_tab (const struct ggc_root_tab* rt)
{
  if (rt)
    extra_root_vec.safe_push (rt);
}
开发者ID:ajinkya93,项目名称:netbsd-src,代码行数:6,代码来源:ggc-common.c

示例6: addPb

void addPb(const vec<Formula>& ps, const vec<Int>& Cs_, vec<Formula>& out, int bits)
{
    assert(ps.size() == Cs_.size());
    vec<vec<Formula> >  pools;
    vec<Int>            Cs(Cs_.size());
    Int                 max_C = -1;
    for (int i = 0; i < Cs_.size(); i++){
        Cs[i] = Cs_[i];
        if (Cs[i] > max_C)
            max_C = Cs[i];
    }

    for (; max_C > 0; max_C >>= 1){
        pools.push();
        for (int i = 0; i < Cs.size(); i++){
            if ((Cs[i] & 1) != 0)
                pools.last().push(ps[i]);
            Cs[i] >>= 1;
        }
    }

    vec<Formula> carry;
    for (int p = 0; p < pools.size(); p++){
        vec<Formula>& pool = pools[p];
        carry.clear();

        if (p == bits){
            Formula overflow = _0_;
            for (; p < pools.size(); p++)
                for (int i = 0; i < pools[p].size(); i++)
                    overflow |= pools[p][i];
            out.push(overflow);
        }else if (pool.size() == 0)
            out.push(_0_);
        else{
            int head = 0;
            while (pool.size()-head >= 3){
                pool .push(FAs(pool[head], pool[head+1], pool[head+2]));
                carry.push(FAc(pool[head], pool[head+1], pool[head+2]));
                head += 3;
            }
            if (pool.size()-head == 2){
                pool .push(FAs(pool[head], pool[head+1], _0_));
                carry.push(FAc(pool[head], pool[head+1], _0_));
                head += 2;
            }
            assert(pool.size()-head == 1);
            out.push(pool[head]);
        }

        if (carry.size() > 0){
            if (p+1 == pools.size())
                pools.push();
            for (int i = 0; i < carry.size(); i++)
                pools[p+1].push(carry[i]);
        }
    }

    #if 0
    //DEBUG
    for (int p = 0; p < pools.size(); p++){
        printf("pool %d:", (1 << p));
        for (int i = 0; i < pools[p].size(); i++){
            printf(" ");
            dump(pools[p][i]);
        }
        printf("\n");
    }
    #endif
}
开发者ID:bakhansen,项目名称:service-technology.org,代码行数:70,代码来源:Hardware_adders.C

示例7: lexComp

static
Formula lexComp(vec<int>& num, vec<vec<Formula> >& digits) {
    assert(num.size() == digits.size());
    return lexComp(num.size(), num, digits); }
开发者ID:bytekid,项目名称:mkbtt,代码行数:4,代码来源:PbSolver_convertSort.C

示例8: clear

 void clear(void) {
   hs.clear();
 }
开发者ID:Amit-DU,项目名称:dht,代码行数:3,代码来源:filestore.C

示例9: generateIf

void generateIf(){
	int pl=tempCode.size();
	if(DEBUG)printf("Generuje if w linii %d\n", pl);
}
开发者ID:rybycy,项目名称:JfttCompiler,代码行数:4,代码来源:translate.c

示例10: generateWhile

void generateWhile(){
	int pl=tempCode.size();
	if(DEBUG)printf("Generuej while w linii %d\n", pl);	
	labeler();
}
开发者ID:rybycy,项目名称:JfttCompiler,代码行数:5,代码来源:translate.c

示例11: generateDivision

void generateDivision(){
	char temp[50];
		int mod=0;
		//c=0, d=1
		addCodeLine("LOAD " + op_temp_b);
		addCodeLine("STORE " + op_temp_c);
		//jezeli b=0 to skaczemy 
		//addCodeLine("JZ " + tempCode.size()+66);
		sprintf(temp, "JZ %d", tempCode.size()+mod+66);addCodeLine(temp);
		addCodeLine("ZERO");
		addCodeLine("STORE " + op_temp_c);
		addCodeLine("INC");
		addCodeLine("STORE " + op_temp_d);
		
		//jesli b parzyste -> skacz (czyt. jezeli b+1 nieparzyste -> skacz)
		// ********** 0 *********
		int label[7];
		label[0] = tempCode.size();
		addCodeLine("LOAD " + op_temp_b);
		//addCodeLine("INC");
		// dopokia b+1 jest nieparzyste (b jest parzyste)
		sprintf(temp, "JODD %d", tempCode.size()+mod+17);addCodeLine(temp);
		addCodeLine("LOAD " + op_temp_d);
		addCodeLine("SHL");
		addCodeLine("STORE " + op_temp_d);
		
		//jezeli a+1 nieparzyste -> 2
		addCodeLine("LOAD " + op_temp_a);
		addCodeLine("INC");
		sprintf(temp, "JODD %d", tempCode.size()+mod+4);addCodeLine(temp);
		addCodeLine("LOAD " + op_temp_d);
		addCodeLine("INC");
		addCodeLine("STORE " + op_temp_d);
		// ************ 2 **********
		
		addCodeLine("LOAD " + op_temp_a);
		addCodeLine("SHR");
		addCodeLine("STORE " + op_temp_a);
		addCodeLine("LOAD " + op_temp_b);
		addCodeLine("SHR");
		addCodeLine("STORE " + op_temp_b);
		sprintf(temp, "JUMP %d", label[0]);addCodeLine(temp);
		

		// **************** 1
		label[1]=tempCode.size();
		addCodeLine("LOAD " + op_temp_b);
		addCodeLine("SUB " + op_temp_a);
		sprintf(temp, "JG %d", tempCode.size()+mod+5);addCodeLine(temp); //3
		addCodeLine("LOAD " + op_temp_b);
		addCodeLine("SHL");
		addCodeLine("STORE " + op_temp_b);
		sprintf(temp, "JUMP %d", label[1]);addCodeLine(temp); //1
		
		// ************* 3
		label[3]=tempCode.size();
		addCodeLine("LOAD " + op_temp_b);
		sprintf(temp, "JODD %d", tempCode.size()+mod+16);addCodeLine(temp); //4
		addCodeLine("LOAD " + op_temp_c);
		addCodeLine("SHL");
		addCodeLine("STORE " + op_temp_c);
		addCodeLine("LOAD " + op_temp_b);
		addCodeLine("SHR");
		addCodeLine("STORE " + op_temp_b);
		addCodeLine("SUB " + op_temp_a);
		sprintf(temp, "JG %d", tempCode.size()+mod+7);addCodeLine(temp); // -> 5
		addCodeLine("LOAD " + op_temp_c);
		addCodeLine("INC");
		addCodeLine("STORE " + op_temp_c);
		addCodeLine("LOAD " + op_temp_a);
		addCodeLine("SUB " + op_temp_b);
		addCodeLine("STORE " + op_temp_a);
		// ****************** 5
		sprintf(temp, "JUMP %d", label[3]);addCodeLine(temp); // ->3
		// jezeli d>0 (r>0) to rob; jesli rowna- skacz
		// ***************** 4
		label[4]=tempCode.size();
		addCodeLine("LOAD " + op_temp_d);
		sprintf(temp, "JZ %d", tempCode.size()+mod+14);addCodeLine(temp); // -> 6
		addCodeLine("LOAD " + op_temp_a);
		addCodeLine("SHL");
		addCodeLine("STORE " + op_temp_a);
		addCodeLine("LOAD " + op_temp_d);
		addCodeLine("INC");
		sprintf(temp, "JODD %d", tempCode.size()+mod+4);addCodeLine(temp); // -> 7
		addCodeLine("LOAD " + op_temp_a);
		addCodeLine("INC");
		addCodeLine("STORE " + op_temp_a);
		// ************* 7
		addCodeLine("LOAD " + op_temp_d);
		addCodeLine("SHR");
		addCodeLine("STORE " + op_temp_d);
		sprintf(temp, "JUMP %d", label[4]);addCodeLine(temp); // -> 4
		// **************** 6
		addCodeLine("LOAD " + op_temp_a);
		addCodeLine("SHR");
		addCodeLine("STORE " + op_temp_a);
		addCodeLine("STORE " + op_temp_b); //reszta w b
		addCodeLine("LOAD " + op_temp_c); // przepisac wynik z c do a 
		addCodeLine("STORE " + op_temp_a);
//.........这里部分代码省略.........
开发者ID:rybycy,项目名称:JfttCompiler,代码行数:101,代码来源:translate.c

示例12: labeler

void labeler(){
	if(DEBUG)addCodeLine("---ETYKIETA---");
	int line=tempCode.size()-1;
	labelStack.push_back(line);
	if(DEBUG)printf("Tymczasowy label w linii %d\n", line);
}
开发者ID:rybycy,项目名称:JfttCompiler,代码行数:6,代码来源:translate.c

示例13:

	vco() { y0.set_length(2);  
			y0(0) = 0.0; y0(1)= 0.0;   
			acc = 0.0; } ;
开发者ID:maki63,项目名称:c_sci,代码行数:3,代码来源:csim_vco.hpp

示例14: maymove

 bool maymove() const { return timeinair || physstate < PHYS_FLOOR || vel.squaredlen() > 1e-4f || deltapos.squaredlen() > 1e-4f; } 
开发者ID:Croydon,项目名称:code,代码行数:1,代码来源:ents.hpp

示例15: for

 ~VSolver(void) { for (int i = 0; i < clauses.size(); i++) delete clauses[i]; }
开发者ID:Sealos,项目名称:AI,代码行数:1,代码来源:Main_debug.C


注:本文中的vec类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。