Ejemplo n.º 1
0
  //
  // HaveMember::Test
  //
  Bool HaveMember::Test(Team *team)
  {
    // Has a relation been specified
    if (relation)
    {
      if (combine)
      {
        U32 count = 0;

        for (List<Team>::Iterator t(&team->RelatedTeams(relation->relation)); *t; t++)
        {
          count += (*t)->GetTotalUnitMembers();
        }
        return (oper(count, amount));
      }
      else
      {
        for (List<Team>::Iterator t(&team->RelatedTeams(relation->relation)); *t; t++)
        {
          if (oper((*t)->GetTotalUnitMembers(), amount))
          {
            return (TRUE);
          }
        }
      }  
      return (FALSE);
    }
    else
    {
      return (oper(team->GetTotalUnitMembers(), amount));
    }
  }
Ejemplo n.º 2
0
 virtual bool isAbelian() const {
  const std::vector<T>& elems = elements();
  typename std::vector<T>::const_iterator xiter;
  for (xiter = elems.begin(); xiter != elems.end(); xiter++) {
   typename std::vector<T>::const_iterator yiter = xiter;
   for (yiter++; yiter != elems.end(); yiter++) {
    if (oper(*xiter, *yiter) != oper(*yiter, *xiter)) return false;
   }
  }
  return true;
 }
Ejemplo n.º 3
0
 std::set<T> centralizer(Iter first, Iter last) const {
  std::set<T> elems = elementSet();
  for (; first != last; first++) {
   typename std::set<T>::iterator iter;
   for (iter = elems.begin(); iter != elems.end(); ) {
    if (oper(*first, *iter) != oper(*iter, *first)) elems.erase(iter++);
    else iter++;
   }
  }
  return elems;
 }
Ejemplo n.º 4
0
 T pow(const T& x0, int n) const {
  T x = n > 0 ? x0 : invert(x0);
  if (n < 0) n *= -1;
  n %= order(x);
  if (n == 0) return identity();
  int i;
  for (i=1; !(n & i); i <<= 1) x = oper(x,x);
  T agg = x;
  for (i <<= 1, x = oper(x,x); i <= n; i <<= 1, x = oper(x,x))
   if (n & i) agg = oper(agg, x);
  return agg;
 }
    int shoppingOffersHelper(vector<int>& price, vector<vector<int>>& special, vector<int>& needs, int payment) {
        if (oper(needs, price, CMP))
            return INT_MAX;
        
        int p = payment + oper(needs, price, MUL);

        for (auto &offer : special) {
            if (payment + offer.back() >= p) // pruning
                continue;
            oper(needs, offer, SUB);
            p = min(p, shoppingOffersHelper(price, special, needs, payment + offer.back()));
            oper(needs, offer, ADD);
        }
        return p;
    }
Ejemplo n.º 6
0
long device_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
{
	int result = 0;

	switch (cmd) {
	case MYCALC_IOC_SET_NUM1:
		get_user(number1, (int *)arg);
		printk(KERN_INFO "About to set the number 1 %i\n", number1);
		break;
	case MYCALC_IOC_SET_NUM2:
		get_user(number2, (int *)arg);
		printk(KERN_INFO "About to set the number 2 %i\n", number2);
		break;
	case MYCALC_IOC_SET_OPERATION:
		get_user(operator, (char *)arg);
		printk(KERN_INFO "About to set the operation %c\n", operator);
		break;
	case MYCALC_IOC_GET_RESULT:
		/* Handle a division by 0 error */
		if (operator == '/' && number2 == 0)
			goto out;

			/* Calculate result */
			result = oper(number1, number2, operator);
			printk(KERN_INFO "Result: %i\n", result);
			put_user(result, (int *)arg);
			break;
	case MYCALC_IOC_DO_OPERATION:
		my_func = arg;
		copy_from_user(&number1, &my_func->number1, 4);
		copy_from_user(&number2, &my_func->number2, 4);
		copy_from_user(&operator, &my_func->operator, 1);

		/* Handle a division by 0 error */
		if (operator == '/' && number2 == 0)
			goto out;

			/* Calculate result */
		result = oper(number1, number2, operator);
		copy_to_user(&my_func->result, &result, 4);
		break;
	default:
		return -ENOTTY;
	}

out:
	return result;
}
Ejemplo n.º 7
0
/* compatible_oper()
 *	given an opname and input datatypes, find a compatible binary operator
 *
 *	This is tighter than oper() because it will not return an operator that
 *	requires coercion of the input datatypes (but binary-compatible operators
 *	are accepted).	Otherwise, the semantics are the same.
 */
Operator
compatible_oper(ParseState *pstate, List *op, Oid arg1, Oid arg2,
				bool noError, int location)
{
	Operator	optup;
	Form_pg_operator opform;

	/* oper() will find the best available match */
	optup = oper(pstate, op, arg1, arg2, noError, location);
	if (optup == (Operator) NULL)
		return (Operator) NULL; /* must be noError case */

	/* but is it good enough? */
	opform = (Form_pg_operator) GETSTRUCT(optup);
	if (IsBinaryCoercible(arg1, opform->oprleft) &&
		IsBinaryCoercible(arg2, opform->oprright))
		return optup;

	/* nope... */
	ReleaseSysCache(optup);

	if (!noError)
		ereport(ERROR,
				(errcode(ERRCODE_UNDEFINED_FUNCTION),
				 errmsg("operator requires run-time type coercion: %s",
						op_signature_string(op, 'b', arg1, arg2)),
				 parser_errposition(pstate, location)));

	return (Operator) NULL;
}
Ejemplo n.º 8
0
void BinTree_Level(LinkedBinTree *bt, void (*oper)(LinkedBinTree *p)) {
	LinkedBinTree *p;
	LinkedBinTree *q[QUEUE_MAXSIZE];
	int head = 0, tail = 0;
	if (bt) {
		tail = (tail+1)%QUEUE_MAXSIZE;
		q[tail] = bt;
	}

	while (head != tail) {
		head = (head+1)%QUEUE_MAXSIZE;
		p = q[head];
		oper(p);
		if (p->left != NULL) {
			tail = (tail+1)%QUEUE_MAXSIZE;
			q[tail] = p->left;
		}

		if (p->right != NULL) {
			tail = (tail+1)%QUEUE_MAXSIZE;
			q[tail] = p->right;
		}
	}

	return;
}
Ejemplo n.º 9
0
int main()
{
	int a;
	int operand1,operand2,value;
	stack s;
	s.top= -1;
	char exp[MAX];
	int symbol;
	gets(exp);
	for(a=0;a<strlen(exp);a++)
	{
		printf("%c", exp[a]);
	}
	for(a=0;a<strlen(exp);a++)
	{
		symbol=exp[a];
		if ((symbol>='0')&&(symbol<='9'))

			push(&s, (symbol-'0'));
		else if(symbol=='+'||symbol=='-'||symbol=='*'||symbol=='/'||symbol=='$')
			{
				operand2= pop(&s);
				operand1= pop(&s);
				value = oper(symbol,operand1,operand2);
				push(&s,value);
			}



	}

	printf("\n%d", pop(&s));
}
Ejemplo n.º 10
0
void pref(char prefi[78],char exp[78])
{
    struct stack st1;
    struct stack st2;
    struct stack st3;
    int cn=0;
    int i, apil=0;
    st1.top=0;
    st2.top=0;
    st3.top=0;
    lim(&st1);
    exp[0]='\0';
    for(i=strlen(prefi)-1;i>=0;i--)
    {
	if( oper(prefi[i]))
	    ins(&st2,prefi[i]);
	else
	{
	    ins(&st1,prefi[i]);
	    cn++;
	}
	if (cn==2)
	{
	    vaciar(&st1,&st3);
	    ins(&st3,elim(&st2,st2.pila[st2.top]));
	    cn=0;
	}
    }
    //mostrarmul(&st1,&st2,&st3);
    copytexp(&st2,exp);
    copytexp(&st1,exp);
    copytexp(&st3,exp);
    
}
Ejemplo n.º 11
0
Archivo: tok.c Proyecto: 8l/myrddin
static Tok *toknext()
{
    Tok *t;
    int c;

    eatspace();
    c = peek();
    if (c == End) {
        t =  mktok(0);
    } else if (c == '\n') {
        curloc.line++;
        next();
        t =  mktok(Tendln);
    } else if (isalpha(c) || c == '_' || c == '$') {
        t =  kwident();
    } else if (c == '"') {
        t =  strlit();
    } else if (c == '\'') {
        t = charlit();
    } else if (isdigit(c)) {
        t =  numlit();
    } else if (c == '@') {
        t = typaram();
    } else {
        t = oper();
    }

    if (!t || t->type == Terror)
        lfatal(curloc, "Unable to parse token starting with %c", c);
    return t;
}
Ejemplo n.º 12
0
void BinTree_LRD(LinkedBinTree *bt, void (*oper)(LinkedBinTree *p)) {
	 if(bt) {
		 BinTree_LRD(bt->left,oper);
		 BinTree_LRD(bt->right,oper);
		 oper(bt);
	 }
	 return;
}
Ejemplo n.º 13
0
 std::set<T> oper(const std::set<T>& xs, const std::set<T>& ys) const {
  std::set<T> result;
  for (const T& x: xs) {
   for (const T& y: ys) {
    result.insert(oper(x,y));
   }
  }
  return result;
 }
Ejemplo n.º 14
0
 bool isSubgroup(const std::set<T>& elems) const {
  if (elems.empty() || !isSubset(elems)) return false;
  for (const T& x: elems) {
   for (const T& y: elems) {
    if (elems.count(oper(x,y)) == 0) return false;
   }
  }
  return true;
 }
Ejemplo n.º 15
0
int main()
{
	stack *st = NULL;
	char a[20];//вход, счётчик i
	char b[20];//вывод, счётчик j
	printf("infix: ");
	scanf("%s", a);
	int i = 0;
	int j = 0;
	while(a[i] != '\0')           
	{
		st = clbr(st, a[i], b, j);
		operand(a[i], b, j);
		st = opbr(st, a[i]);
		st = oper(st, a[i], b, j);
		i++;                                    
	}
	st = end(st, b, j);
	printf("postfix: %s\n", b);
	
	i = 0;
	while (b[i] != '\0')
	{
		if (numb(b[i]))//число - в стек
			st = push (st, b[i]);
		else//операция - вытащить два числа и прооперировать
		{
			int a1 = (int(pop(&st)) - int('0'));
			int b1 = (int(pop(&st)) - int('0'));
			int c = 0;
			switch (b[i])
			{
			case '+':
				c = a1 + b1;
				break;
			case '-':
				c = b1 - a1;
				break;
			case '*':
				c = b1 * a1;
				break;
			case '/':
				c = b1 / a1;
				break;
			}
			st = push (st, (c + int('0')));
		}
		i++;
	}
	int res = (int(pop(&st)) - int('0'));
	printf("result: %d\ninput something to close\n", res);

	scanf("%*s");
	return 0;
}
    int shoppingOffersHelper(vector<int>& price, vector<vector<int>>& special, vector<int>& needs, int payment, unordered_map<int, int> &dp) {
        if (oper(needs, price, CMP))
            return INT_MAX;

        int k = oper(needs, price, KEY);
        if (dp.find(k) != dp.end())
            return dp[k];
        
        int p = payment + oper(needs, price, MUL);

        for (auto &offer : special) {
            if (payment + offer.back() >= p) // pruning
                continue;
            oper(needs, offer, SUB);
            p = min(p, shoppingOffersHelper(price, special, needs, payment + offer.back(), dp));
            oper(needs, offer, ADD);
        }
        dp[k] = p;
        return p;
    }
Ejemplo n.º 17
0
void main()
{
	char str[100];
	int n;
	printf("enter string\t");
	gets(str);
	printf("enter a number\t");
	scanf("%d",&n);
	oper(str,n);
	getch();
}
 int evalRPN(vector<string> &tokens) {
     stack<int> s;
     for(auto str: tokens)
     {
         if(str == "+" || str == "-" || str == "*" || str == "/")
             oper(s, str);
         else
             s.push(atoi(str.c_str()));
     }
     return s.top();
 }
Ejemplo n.º 19
0
Archivo: main.c Proyecto: qioqio/ACM
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        int m;
        scanf("%d",&m);
        oper(m);
    }
    return 0;
}
Ejemplo n.º 20
0
string SMSClient::name()
{
    string res = "SMS.";
    if (getState() == Connected){
        res += model();
        res += " ";
        res += oper();
    }else{
        res += getDevice();
    }
    return res;
}
Ejemplo n.º 21
0
 std::set<T> cycle(const T& x) const {
  // TODO: Rename this to `cycleSet` in order to keep its return type from
  // being confused with that of `Element::cycle`?
  const T& id = identity();
  std::set<T> cyke;
  cyke.insert(id);
  T y = x;
  while (y != id) {
   cyke.insert(y);
   y = oper(y,x);
  }
  return cyke;
 }
Ejemplo n.º 22
0
RCatalogsArray<MNcdOperation> CNcdNodeProxy::OperationsL() const
    {
    DLTRACEIN(("this: %x, iMetadata: %x", this, iMetadata ));
    RCatalogsArray<MNcdOperation> operations;
    CleanupClosePushL( operations );

    if ( iMetadata ) 
        {
        // Get the original array and insert its content to catalogs array.
        // Also, increase the reference counter for the items.
        const RPointerArray<MNcdOperation>& origArray = iOperationManager.Operations();
        MNcdOperation* oper( NULL );
        MNcdNode* node( NULL );
        
        CNcdNodeMetadataProxy* metadata( NULL );
        DLTRACE(("Getting metaidentifier"));
        const CNcdNodeIdentifier& metadataId( iMetadata->Identifier() );
        
        DLTRACE(("Origarray.count: %d", origArray.Count() ));
        for ( TInt i = 0; i < origArray.Count(); ++i )
            {            
            oper = origArray[ i ];
            DLTRACE(("oper: %x", oper));
            // Notice that node ref count is increased. So, release it when done.
            node = oper->Node();
            if ( node ) 
                {
                CleanupReleasePushL( *node );
    
                // Compare metadatas
                metadata = static_cast<CNcdNodeProxy*>( node )->Metadata();
                DLTRACE(("Metadata: %x", metadata));
                if ( metadata && metadata->Identifier().Equals( metadataId ) )
                    {
                    DLTRACE(("Appending to ops array"));
                    operations.AppendL( oper );
                    oper->AddRef();
                    }
    
                CleanupStack::PopAndDestroy( node );
                }
            }
        }

    CleanupStack::Pop( &operations );
    
    DLTRACEOUT(( "" ));
    return operations;
    }
Ejemplo n.º 23
0
	void AlgorithmDummy::openShort(CppUtils::String const& provider,CppUtils::String const& symbol)
	{
		BrkLib::Order order;

		//order.ID_m.generate();
		order.provider_m = provider;
		order.symbol_m = symbol;
		order.orderType_m = BrkLib::OP_SELL;
		order.orderValidity_m = BrkLib::OV_DAY;
		order.orVolume_m = 1;

		
		BrkLib::BrokerOperation oper(*brokerConnect_m);
		oper.unblockingIssueOrder(order);
	}
Ejemplo n.º 24
0
	void AlgorithmDummy::closeShort(CppUtils::String const& provider,CppUtils::String const& symbol, CppUtils::String const& brokerPositionId)
	{
		BrkLib::Order order;

		//order.ID_m.generate();
		order.provider_m = provider;
		order.brokerPositionID_m = brokerPositionId; 
		order.symbol_m = symbol;
		order.orderType_m = BrkLib::OP_CLOSE_SHORT;
		order.orderValidity_m = BrkLib::OV_DAY;
		order.orVolume_m = 1;

		
		BrkLib::BrokerOperation oper(*brokerConnect_m);
		oper.unblockingIssueOrder(order);
	}
static bool py_add_object_to_trans( cps_api_transaction_params_t *tr, PyObject *dict) {
    PyObject *_req = PyDict_GetItemString(dict,"change");
    PyObject *_op = PyDict_GetItemString(dict,"operation");

    if (_op==NULL || _req==NULL) {
        return false;
    }
    PyObject *_prev = PyDict_GetItemString(dict,"previous");
    if (_prev!=NULL) {
        if (cps_api_object_list_size(tr->change_list)!=
                cps_api_object_list_size(tr->prev)) {
            return false;
        }
        cps_api_object_guard og(dict_to_cps_obj(_req));
        if (!og.valid()) return false;
        if (!cps_api_object_list_append(tr->prev,og.get())) {
            return false;
        }
        og.release();
    }

    using cps_oper = cps_api_return_code_t (*)(cps_api_transaction_params_t * trans,
            cps_api_object_t object);

    static std::map<std::string,cps_oper> trans = {
            {"delete",cps_api_delete },
            {"create",cps_api_create},
            {"set",cps_api_set},
            {"rpc",cps_api_action}
    };

    if (trans.find(PyString_AsString(_op))==trans.end()) {
        return false;
    }

    cps_oper oper = trans[PyString_AsString(_op)];

    cps_api_object_t obj = dict_to_cps_obj(_req);
    cps_api_object_guard og(obj);
    if (!og.valid()) return false;

    if (oper(tr,obj)!=cps_api_ret_code_OK) {
        return false;
    }
    og.release();
    return true;
}
Ejemplo n.º 26
0
/** this is a very limited - and much bugged - approach to
  * highlighting Prolog syntax.
  * Just a quick alternative to properly interfacing SWI-Prolog goodies,
  * that proved much more difficult to do rightly than I foreseen
  */
void plMiniSyntax::setup() {
    QString number("\\d+(?:\\.\\d+)?");
    QString symbol("[a-z][A-Za-z0-9_]*");
    QString var("[A-Z_][A-Za-z0-9_]*");
    QString quoted("\"[^\"]*\"");
    QString oper("[\\+\\-\\*\\/\\=\\^<>~:\\.,;\\?@#$\\\\&{}`]+");

    tokens = QRegExp(QString("(%1)|(%2)|(%3)|(%4)|(%5)|%").arg(number, symbol, var, quoted, oper));

    fmt[Comment].setForeground(Qt::darkGreen);
    fmt[Number].setForeground(QColor("blueviolet"));
    fmt[Atom].setForeground(Qt::blue);
    fmt[String].setForeground(Qt::magenta);
    fmt[Variable].setForeground(QColor("brown"));
    fmt[Operator].setFontWeight(QFont::Bold);
    fmt[Unknown].setForeground(Qt::darkRed);
}
Ejemplo n.º 27
0
//Evaluate POSFIX expression
double evalPostfix(char expression[]) {
    int position = 0;;
    int token = 0;
    double operand1 = 0.0, operand2 = 0.0;
    double value = 0;;
    EVALSTACK operandStack;
    //initilize stack
    for (int i = 0; i < MAXCOLS; i++) {
        operandStack.stackelement[i] = 0.0;
    }
    operandStack.top = -1;
    token = expression[position];
    for (position = 0; token != '\0'; ) {
        /*
         *   ASCII == 42
         +   ASCII == 43
         -   ASCII == 45
         /   ASCII == 47
         ^   ASCII == 94
         %   ASCII == 37
         0   ASCII == 48
         9   ASCII == 57
         */
        // If digit from 0 to 9
        if (token >= 48 && token <= 57) {
            pushopd(&operandStack, token - '0');
        // any other digit
        } else if ((token != 42) && (token != 43) && (token != 45) &&
                   (token != 47) && (token != 94) && (token != 37)) {
            token = token - 48;
            pushopd(&operandStack, token);
        } else {
            operand2 = popopd(&operandStack);
            operand1 = popopd(&operandStack);
            //note the order of operand2 and operand1
            value = oper(token, operand1, operand2);
            pushopd(&operandStack, value);
        }
        position++;
        token = expression[position];
    }
    return popopd(&operandStack);
}
Ejemplo n.º 28
0
//Evaluation of prefix expression
double PREFIX_Eval(char expression[]) {
    double operand1 = 0.0, operand2 = 0.0, tempResult, result;
    size_t length, i;
    length = strlen(expression);
    EVALSTACK evalStack;
    resetStackEval(&evalStack);
    int token;
    char operator;
    for (i = length - 1; length >= i; i--)
    {
        token = expression[i];
        /*
         *   ASCII == 42
         +   ASCII == 43
         -   ASCII == 45
         /   ASCII == 47
         ^   ASCII == 94
         %   ASCII == 37
         0   ASCII == 48
         9   ASCII == 57 */
        // If digit from 0 to 9
        if (token >= 48 && token <= 57) {
            pushopd(&evalStack, token - '0');
        // any other digit
        } else if ((token != 42) && (token != 43) && (token != 45) &&
                   (token != 47) && (token != 94) && (token != 37)) {
            token = token - 48;
            pushopd(&evalStack, token);
        // if it is one of the operators
        } else {
            operand1 = popopd(&evalStack);
            operand2 = popopd(&evalStack);
            operator = token;
            // note the order of operand1 and operand2
            tempResult = oper(operator, operand1, operand2);
            pushopd(&evalStack, tempResult);
        }
    }
    result=popopd(&evalStack);
    return result;
}
Ejemplo n.º 29
0
double eval(char expr[]){

int c,position;
double opnd1,opnd2,value;
struct stack opndstck;

opndstck.top=-1;
for(position=0;(c=expr[position])!='\0';position++)
    if(isdigit(c))                        //If it is number
        push(&opndstck,(double)(c-'0'));

      else   {             //If it is a operator
      opnd2=pop(&opndstck);
      opnd1=pop(&opndstck);
      value= oper(c,opnd1,opnd2);
      push(&opndstck,value);

      }

 return(pop(&opndstck));
}
Ejemplo n.º 30
0
	// @override
	void run(void)
	{
		redis_oper oper(cluster_, sem_);

		int n = oper.set(__oper_count);
		(void) oper.get(n);
		(void) oper.del(n);

		static long long __total = 0;
		__total += oper.nset() + oper.nget() + oper.ndel();

		if (--__fibers_count == 0) {
			gettimeofday(&__end, NULL);
			double spent = stamp_sub(&__end, &__begin);
			printf("-------- All fibers over now --------\r\n");
			printf("fibers: %d, count: %lld, spent: %.2f, speed: %.2f\r\n",
				__fibers_max, __total, spent,
				(__total * 1000) / (spent > 0 ? spent : 1));

			acl::fiber::schedule_stop();
		}
	}